VTK
vtkTextureObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTextureObject.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
26 #ifndef vtkTextureObject_h
27 #define vtkTextureObject_h
28 
29 #include "vtkRenderingOpenGLModule.h" // For export macro
30 #include "vtkObject.h"
31 #include "vtkWeakPointer.h" // for render context
32 
33 class vtkFloatArray;
34 class vtkTextureObject;
35 class vtkRenderWindow;
39 
40 class VTKRENDERINGOPENGL_EXPORT vtkTextureObject : public vtkObject
41 {
42 public:
43 
44  // DepthTextureCompareFunction values.
45  enum
46  {
47  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
48  Gequal, // r=R>=Dt ? 1.0 : 0.0
49  Less, // r=R<D_t ? 1.0 : 0.0
50  Greater, // r=R>Dt ? 1.0 : 0.0
51  Equal, // r=R==Dt ? 1.0 : 0.0
52  NotEqual, // r=R!=Dt ? 1.0 : 0.0
53  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
54  Never, // r=0.0
55  NumberOfDepthTextureCompareFunctions
56  };
57 
58  // DepthTextureMode values.
59  enum
60  {
61  Luminance=0, // (R,G,B,A)=(r,r,r,1)
62  Intensity, // (R,G,B,A)=(r,r,r,r)
63  Alpha, // (R,G,B,A)=(0,0,0,r)
64  NumberOfDepthTextureModes
65  };
66 
67  // Wrap values.
68  enum
69  {
70  Clamp=0,
75  NumberOfWrapModes
76  };
77 
78  // MinificationFilter values.
79  enum
80  {
81  Nearest=0,
87  NumberOfMinificationModes
88  };
89 
90  // Internal depth format
91  enum
92  {
93  Native=0, // will try to match with the depth buffer format.
98  NumberOfDepthFormats
99  };
100 
101  static vtkTextureObject* New();
102  vtkTypeMacro(vtkTextureObject, vtkObject);
103  void PrintSelf(ostream& os, vtkIndent indent);
104 
106 
112  void SetContext(vtkRenderWindow*);
113  vtkRenderWindow* GetContext();
115 
117 
121  vtkGetMacro(Width, unsigned int);
122  vtkGetMacro(Height, unsigned int);
123  vtkGetMacro(Depth, unsigned int);
124  vtkGetMacro(Components, int);
125  unsigned int GetTuples()
126  { return this->Width*this->Height*this->Depth; }
128 
129  vtkGetMacro(NumberOfDimensions, int);
130 
132 
135  vtkGetMacro(Target, unsigned int);
137 
139 
142  vtkGetMacro(Handle, unsigned int);
144 
146 
151  void Bind();
152  void UnBind();
154 
156 
159  void Activate(unsigned int texUnit);
160  void Deactivate(unsigned int texUnit);
162 
163 
168  bool IsBound();
169 
171 
177  void SendParameters();
178  vtkSetMacro(AutoParameters, int);
179  vtkGetMacro(AutoParameters, int);
181 
192  bool Create1D(int numComps,
194  bool shaderSupportsTextureInt);
195 
202  bool Create2D(unsigned int width, unsigned int height, int numComps,
204  bool shaderSupportsTextureInt);
205 
210  bool CreateDepth(unsigned int width,
211  unsigned int height,
212  int internalFormat,
213  vtkPixelBufferObject *pbo);
214 
219  bool CreateDepthFromRaw(unsigned int width,
220  unsigned int height,
221  int internalFormat,
222  int rawType,
223  void *raw);
224 
228  bool AllocateDepth(unsigned int width, unsigned int height,
229  int internalFormat);
230 
235  bool Allocate1D(unsigned int width, int numComps, int vtkType);
236 
241  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
242  int vtkType);
243 
248  bool Allocate3D(unsigned int width, unsigned int height,
249  unsigned int depth, int numComps,
250  int vtkType);
251 
252 
259  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
260  int numComps, vtkPixelBufferObject *pbo,
261  bool shaderSupportsTextureInt);
262 
263 
265 
270  bool Create2D(unsigned int width, unsigned int height, int numComps,
271  int vtktype,
272  bool shaderSupportsTextureInt);
273  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
274  int numComps, int vtktype,
275  bool shaderSupportsTextureInt);
277 
284  vtkPixelBufferObject* Download();
285 
289  int GetDataType();
290 
291  unsigned int GetInternalFormat(int vtktype, int numComps,
292  bool shaderSupportsTextureInt);
293  unsigned int GetFormat(int vtktype, int numComps,
294  bool shaderSupportsTextureInt);
295 
297 
303  vtkSetMacro(RequireDepthBufferFloat, bool);
304  vtkGetMacro(RequireDepthBufferFloat, bool);
305  vtkGetMacro(SupportsDepthBufferFloat, bool);
307 
309 
315  vtkSetMacro(RequireTextureFloat, bool);
316  vtkGetMacro(RequireTextureFloat, bool);
317  vtkGetMacro(SupportsTextureFloat, bool);
319 
321 
327  vtkSetMacro(RequireTextureInteger, bool);
328  vtkGetMacro(RequireTextureInteger, bool);
329  vtkGetMacro(SupportsTextureInteger, bool);
331 
333 
343  vtkGetMacro(WrapS, int);
344  vtkSetMacro(WrapS, int);
346 
348 
358  vtkGetMacro(WrapT, int);
359  vtkSetMacro(WrapT, int);
361 
363 
373  vtkGetMacro(WrapR, int);
374  vtkSetMacro(WrapR, int);
376 
378 
391  vtkGetMacro(MinificationFilter, int);
392  vtkSetMacro(MinificationFilter, int);
394 
396 
403  vtkGetMacro(MagnificationFilter, int);
404  vtkSetMacro(MagnificationFilter, int);
406 
411  void SetLinearMagnification(bool val)
412  { this->SetMagnificationFilter(val?Linear:Nearest); }
413 
415  { return this->MagnificationFilter==Linear; }
416 
418 
423  vtkSetVector4Macro(BorderColor, float);
424  vtkGetVector4Macro(BorderColor, float);
426 
428 
433  vtkSetMacro(Priority, float);
434  vtkGetMacro(Priority, float);
436 
438 
442  vtkSetMacro(MinLOD, float);
443  vtkGetMacro(MinLOD, float);
445 
447 
451  vtkSetMacro(MaxLOD, float);
452  vtkGetMacro(MaxLOD, float);
454 
456 
461  vtkSetMacro(BaseLevel, int);
462  vtkGetMacro(BaseLevel, int);
464 
466 
471  vtkSetMacro(MaxLevel, int);
472  vtkGetMacro(MaxLevel, int);
474 
476 
486  vtkGetMacro(DepthTextureCompare, bool);
487  vtkSetMacro(DepthTextureCompare, bool);
489 
491 
511  vtkGetMacro(DepthTextureCompareFunction, int);
512  vtkSetMacro(DepthTextureCompareFunction, int);
514 
516 
525  vtkGetMacro(DepthTextureMode, int);
526  vtkSetMacro(DepthTextureMode, int);
528 
530 
535  vtkGetMacro(GenerateMipmap, bool);
536  vtkSetMacro(GenerateMipmap, bool);
538 
544  static bool IsSupported(
545  vtkRenderWindow* renWin,
546  bool requireTexFloat,
547  bool requireDepthFloat,
548  bool requireTexInt);
549 
553  static bool IsSupported(vtkRenderWindow* renWin)
554  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
555 
582  void CopyToFrameBuffer(int srcXmin,
583  int srcYmin,
584  int srcXmax,
585  int srcYmax,
586  int dstXmin,
587  int dstYmin,
588  int width,
589  int height);
590 
591 
603  void CopyFromFrameBuffer(int srcXmin,
604  int srcYmin,
605  int dstXmin,
606  int dstYmin,
607  int width,
608  int height);
609 
610 protected:
612  ~vtkTextureObject();
613 
617  bool LoadRequiredExtensions(vtkRenderWindow *renWin);
618 
622  void CreateTexture();
623 
627  void DestroyTexture();
628 
630  unsigned int Width;
631  unsigned int Height;
632  unsigned int Depth;
633 
634  unsigned int Target; // GLenum
635  unsigned int Format; // GLenum
636  unsigned int Type; // GLenum
638 
640  unsigned int Handle;
647 
648  int WrapS;
649  int WrapT;
650  int WrapR;
654  float BorderColor[4];
655 
656  float Priority;
657  float MinLOD;
658  float MaxLOD;
660  int MaxLevel;
661 
662 
666 
668 
671 
672 private:
673  vtkTextureObject(const vtkTextureObject&) VTK_DELETE_FUNCTION;
674  void operator=(const vtkTextureObject&) VTK_DELETE_FUNCTION;
675 
676 };
677 
678 #endif
vtkTextureObject::DepthTextureCompare
bool DepthTextureCompare
Definition: vtkTextureObject.h:663
vtkTextureObject::Intensity
Definition: vtkTextureObject.h:62
vtkTextureObject::Equal
Definition: vtkTextureObject.h:51
vtkTextureObject::Depth
unsigned int Depth
Definition: vtkTextureObject.h:632
vtkTextureObject::IsSupported
static bool IsSupported(vtkRenderWindow *renWin)
Check for feature support, without any optional features.
Definition: vtkTextureObject.h:553
vtkTextureObject::NumberOfDimensions
int NumberOfDimensions
Definition: vtkTextureObject.h:629
vtkTextureObject::LinearMagnification
bool LinearMagnification
Definition: vtkTextureObject.h:653
vtkTextureObject::SendParametersTime
vtkTimeStamp SendParametersTime
Definition: vtkTextureObject.h:670
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkTextureObject::RequireTextureFloat
bool RequireTextureFloat
Definition: vtkTextureObject.h:643
vtkTextureObject::Target
unsigned int Target
Definition: vtkTextureObject.h:634
vtkTextureObject::WrapR
int WrapR
Definition: vtkTextureObject.h:650
vtkTextureObject::NotEqual
Definition: vtkTextureObject.h:52
vtkTextureObject::MagnificationFilter
int MagnificationFilter
Definition: vtkTextureObject.h:652
vtkTextureObject::Float32
Definition: vtkTextureObject.h:97
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkTextureObject::GenerateMipmap
bool GenerateMipmap
Definition: vtkTextureObject.h:667
vtkTextureObject::SupportsTextureInteger
bool SupportsTextureInteger
Definition: vtkTextureObject.h:642
vtkTextureObject::SupportsDepthBufferFloat
bool SupportsDepthBufferFloat
Definition: vtkTextureObject.h:646
vtkTextureObject::Alpha
Definition: vtkTextureObject.h:63
vtkTextureObject::LinearMipmapNearest
Definition: vtkTextureObject.h:85
vtkTextureObject::GetLinearMagnification
bool GetLinearMagnification()
Definition: vtkTextureObject.h:414
vtkTextureObject::Context
vtkWeakPointer< vtkRenderWindow > Context
Definition: vtkTextureObject.h:639
vtkTextureObject::Fixed32
Definition: vtkTextureObject.h:96
vtkTextureObject::MaxLevel
int MaxLevel
Definition: vtkTextureObject.h:660
vtkTextureObject::AlwaysTrue
Definition: vtkTextureObject.h:53
vtkTextureObject::NearestMipmapLinear
Definition: vtkTextureObject.h:84
vtkTextureObject::Priority
float Priority
Definition: vtkTextureObject.h:656
vtkTextureObject::Repeat
Definition: vtkTextureObject.h:72
vtkTextureObject::MinificationFilter
int MinificationFilter
Definition: vtkTextureObject.h:651
vtkTextureObject::GetTuples
unsigned int GetTuples()
Definition: vtkTextureObject.h:125
vtkTextureObject::RequireDepthBufferFloat
bool RequireDepthBufferFloat
Definition: vtkTextureObject.h:645
vtkOpenGLExtensionManager
Interface class for querying and using OpenGL extensions.
vtkTextureObject::NearestMipmapNearest
Definition: vtkTextureObject.h:83
vtkX3D::height
Definition: vtkX3D.h:254
vtkTextureObject::Linear
Definition: vtkTextureObject.h:82
vtkTextureObject::Components
int Components
Definition: vtkTextureObject.h:637
vtkTextureObject::ClampToBorder
Definition: vtkTextureObject.h:73
vtkTextureObject::RequireTextureInteger
bool RequireTextureInteger
Definition: vtkTextureObject.h:641
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkTextureObject::Width
unsigned int Width
Definition: vtkTextureObject.h:630
vtkTextureObject::LinearMipmapLinear
Definition: vtkTextureObject.h:86
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWeakPointer.h
vtkTextureObject::MirroredRepeat
Definition: vtkTextureObject.h:74
vtkObject.h
vtkTextureObject::MaxLOD
float MaxLOD
Definition: vtkTextureObject.h:658
vtkTextureObject::ClampToEdge
Definition: vtkTextureObject.h:71
vtkTextureObject::Fixed24
Definition: vtkTextureObject.h:95
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkTextureObject::Gequal
Definition: vtkTextureObject.h:48
vtkTextureObject::Never
Definition: vtkTextureObject.h:54
vtkTextureObject::Less
Definition: vtkTextureObject.h:49
vtkTextureObject::SupportsTextureFloat
bool SupportsTextureFloat
Definition: vtkTextureObject.h:644
vtkTextureObject::WrapS
int WrapS
Definition: vtkTextureObject.h:648
vtkTextureObject::Handle
unsigned int Handle
Definition: vtkTextureObject.h:640
vtkTextureObject::AutoParameters
int AutoParameters
Definition: vtkTextureObject.h:669
vtkTextureObject::Height
unsigned int Height
Definition: vtkTextureObject.h:631
vtkTextureObject::Fixed16
Definition: vtkTextureObject.h:94
vtkTextureObject::Format
unsigned int Format
Definition: vtkTextureObject.h:635
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:38
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:86
vtkTextureObject::WrapT
int WrapT
Definition: vtkTextureObject.h:649
vtkTextureObject::SetLinearMagnification
void SetLinearMagnification(bool val)
Tells if the magnification mode is linear (true) or nearest (false).
Definition: vtkTextureObject.h:411
vtkTextureObject::DepthTextureCompareFunction
int DepthTextureCompareFunction
Definition: vtkTextureObject.h:664
vtkTextureObject::DepthTextureMode
int DepthTextureMode
Definition: vtkTextureObject.h:665
vtkTextureObject::BaseLevel
int BaseLevel
Definition: vtkTextureObject.h:659
vtkTextureObject::Type
unsigned int Type
Definition: vtkTextureObject.h:636
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:43
vtkWeakPointer< vtkRenderWindow >
vtkTextureObject::IsSupported
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
vtkTextureObject::MinLOD
float MinLOD
Definition: vtkTextureObject.h:657
vtkTextureObject::Greater
Definition: vtkTextureObject.h:50