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 =========================================================================*/
24 #ifndef vtkTextureObject_h
25 #define vtkTextureObject_h
26 
27 #include "vtkRenderingOpenGL2Module.h" // For export macro
28 #include "vtkObject.h"
29 #include "vtkWeakPointer.h" // for render context
30 
32 class vtkOpenGLHelper;
35 class vtkShaderProgram;
36 class vtkWindow;
38 
39 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
41 #endif
42 
43 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
44 {
45 public:
46 
47  // DepthTextureCompareFunction values.
48  enum
49  {
50  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
51  Gequal, // r=R>=Dt ? 1.0 : 0.0
52  Less, // r=R<D_t ? 1.0 : 0.0
53  Greater, // r=R>Dt ? 1.0 : 0.0
54  Equal, // r=R==Dt ? 1.0 : 0.0
55  NotEqual, // r=R!=Dt ? 1.0 : 0.0
56  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
57  Never, // r=0.0
58  NumberOfDepthTextureCompareFunctions
59  };
60 
61 // ClampToBorder is not supported in ES 2.0
62 // Wrap values.
63 #if GL_ES_VERSION_2_0 != 1
64  enum
65  {
66  ClampToEdge=0,
67  Repeat,
68  MirroredRepeat,
69  ClampToBorder,
70  NumberOfWrapModes
71  };
72 #else
73  enum
74  {
75  ClampToEdge=0,
76  Repeat,
77  MirroredRepeat,
78  NumberOfWrapModes
79  };
80 #endif
81 
82  // MinificationFilter values.
83  enum
84  {
85  Nearest=0,
86  Linear,
87  NearestMipmapNearest,
88  NearestMipmapLinear,
89  LinearMipmapNearest,
90  LinearMipmapLinear,
91  NumberOfMinificationModes
92  };
93 
94  // Internal depth format
95  enum
96  {
97  Native=0, // will try to match with the depth buffer format.
98  Fixed16,
99  Fixed24,
100  Fixed32,
101  Float32,
102  NumberOfDepthFormats
103  };
104 
105  // Internal alpha format
106  enum
107  {
108  alpha=0,
113  NumberOfAlphaFormats
114  };
115 
116  // Depth mode formats
117  enum
118  {
119  DepthAlpha=0,
122  NumberOfDepthModeFormats
123  };
124 
126  vtkTypeMacro(vtkTextureObject, vtkObject);
127  void PrintSelf(ostream& os, vtkIndent indent);
128 
130 
142 
144 
148  vtkGetMacro(Width, unsigned int);
149  vtkGetMacro(Height, unsigned int);
150  vtkGetMacro(Depth, unsigned int);
151  vtkGetMacro(Components, int);
152  unsigned int GetTuples()
153  { return this->Width*this->Height*this->Depth; }
155 
156  vtkGetMacro(NumberOfDimensions, int);
157 
159 
162  vtkGetMacro(Target, unsigned int);
164 
166 
169  vtkGetMacro(Handle, unsigned int);
171 
176 
178 
183  void Bind();
184  void UnBind();
186 
190  void Activate();
191 
195  void Deactivate();
196 
201 
206  bool IsBound();
207 
209 
216  vtkSetMacro(AutoParameters, int);
217  vtkGetMacro(AutoParameters, int);
219 
224  bool Create2DFromRaw(unsigned int width, unsigned int height,
225  int numComps, int dataType, void *data);
226 
231  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
232  int internalFormat, int rawType,
233  void *raw);
234 
239  bool CreateTextureBuffer(unsigned int numValues, int numComps,
240  int dataType, vtkOpenGLBufferObject *bo);
241 
247  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
248  int numComps, int dataType, void *data[6]);
249 
250 // 1D textures are not supported in ES 2.0 or 3.0
251 #if GL_ES_VERSION_2_0 != 1
252 
263  bool Create1D(int numComps,
265  bool shaderSupportsTextureInt);
266 
270  bool Create1DFromRaw(unsigned int width, int numComps,
271  int dataType, void *data);
276  bool CreateAlphaFromRaw(unsigned int width,
277  int internalFormat,
278  int rawType,
279  void *raw);
280 #endif
281 
282 // PBO's, and 3D textures are not supported in ES 2.0
283 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
284 
291  bool Create2D(unsigned int width, unsigned int height, int numComps,
293  bool shaderSupportsTextureInt);
294 
301  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
302  int numComps, vtkPixelBufferObject *pbo,
303  bool shaderSupportsTextureInt);
304 
309  bool Create3DFromRaw(unsigned int width, unsigned int height,
310  unsigned int depth, int numComps,
311  int dataType, void *data);
312 
320 
325  bool CreateDepth(unsigned int width,
326  unsigned int height,
327  int internalFormat,
328  vtkPixelBufferObject *pbo);
329 
330 #endif
331 
335  bool AllocateDepth(unsigned int width, unsigned int height,
336  int internalFormat);
337 
342  bool Allocate1D(unsigned int width, int numComps, int vtkType);
343 
348  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
349  int vtkType);
350 
355  bool Allocate3D(unsigned int width, unsigned int height,
356  unsigned int depth, int numComps,
357  int vtkType);
358 
359 
361 
364  bool Create2D(unsigned int width, unsigned int height, int numComps,
365  int vtktype, bool shaderSupportsTextureInt);
366  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
367  int numComps, int vtktype, bool shaderSupportsTextureInt);
369 
374 
376 
379  int GetDataType(int vtk_scalar_type);
380  void SetDataType(unsigned int glType);
381  int GetDefaultDataType(int vtk_scalar_type);
383 
385 
390  unsigned int GetInternalFormat(int vtktype, int numComps,
391  bool shaderSupportsTextureInt);
392  void SetInternalFormat(unsigned int glInternalFormat);
393  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
394  bool shaderSupportsTextureInt);
396 
398 
403  unsigned int GetFormat(int vtktype, int numComps,
404  bool shaderSupportsTextureInt);
405  void SetFormat(unsigned int glFormat);
406  unsigned int GetDefaultFormat(int vtktype, int numComps,
407  bool shaderSupportsTextureInt);
409 
419 
420  unsigned int GetMinificationFilterMode(int vtktype);
421  unsigned int GetMagnificationFilterMode(int vtktype);
422  unsigned int GetWrapSMode(int vtktype);
423  unsigned int GetWrapTMode(int vtktype);
424  unsigned int GetWrapRMode(int vtktype);
425 
427 
433  vtkSetMacro(RequireDepthBufferFloat, bool);
434  vtkGetMacro(RequireDepthBufferFloat, bool);
435  vtkGetMacro(SupportsDepthBufferFloat, bool);
437 
439 
445  vtkSetMacro(RequireTextureFloat, bool);
446  vtkGetMacro(RequireTextureFloat, bool);
447  vtkGetMacro(SupportsTextureFloat, bool);
449 
451 
457  vtkSetMacro(RequireTextureInteger, bool);
458  vtkGetMacro(RequireTextureInteger, bool);
459  vtkGetMacro(SupportsTextureInteger, bool);
461 
463 
473  vtkGetMacro(WrapS, int);
474  vtkSetMacro(WrapS, int);
476 
478 
488  vtkGetMacro(WrapT, int);
489  vtkSetMacro(WrapT, int);
491 
493 
503  vtkGetMacro(WrapR, int);
504  vtkSetMacro(WrapR, int);
506 
508 
521  vtkGetMacro(MinificationFilter, int);
522  vtkSetMacro(MinificationFilter, int);
524 
526 
533  vtkGetMacro(MagnificationFilter, int);
534  vtkSetMacro(MagnificationFilter, int);
536 
541  void SetLinearMagnification(bool val)
542  { this->SetMagnificationFilter(val?Linear:Nearest); }
543 
545  { return this->MagnificationFilter==Linear; }
546 
548 
553  vtkSetVector4Macro(BorderColor, float);
554  vtkGetVector4Macro(BorderColor, float);
556 
558 
562  vtkSetMacro(MinLOD, float);
563  vtkGetMacro(MinLOD, float);
565 
567 
571  vtkSetMacro(MaxLOD, float);
572  vtkGetMacro(MaxLOD, float);
574 
576 
581  vtkSetMacro(BaseLevel, int);
582  vtkGetMacro(BaseLevel, int);
584 
586 
591  vtkSetMacro(MaxLevel, int);
592  vtkGetMacro(MaxLevel, int);
594 
596 
606  vtkGetMacro(DepthTextureCompare, bool);
607  vtkSetMacro(DepthTextureCompare, bool);
609 
611 
631  vtkGetMacro(DepthTextureCompareFunction, int);
632  vtkSetMacro(DepthTextureCompareFunction, int);
634 
636 
641  vtkGetMacro(GenerateMipmap, bool);
642  vtkSetMacro(GenerateMipmap, bool);
644 
655 
661  static bool IsSupported(
662  vtkOpenGLRenderWindow* renWin,
663  bool requireTexFloat,
664  bool requireDepthFloat,
665  bool requireTexInt);
666 
670  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
671  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
672 
674 
681  // part of a texture to part of a viewport, scaling as needed
682  void CopyToFrameBuffer(int srcXmin, int srcYmin,
683  int srcXmax, int srcYmax,
684  int dstXmin, int dstYmin,
685  int dstXmax, int dstYmax,
686  int dstSizeX, int dstSizeY,
687  vtkShaderProgram *program,
689  );
690  // copy part of a texure to part of a viewport, no scalaing
691  void CopyToFrameBuffer(int srcXmin, int srcYmin,
692  int srcXmax, int srcYmax,
693  int dstXmin, int dstYmin,
694  int dstSizeX, int dstSizeY,
695  vtkShaderProgram *program,
697  );
698  // copy a texture to a quad using the provided tcoords and verts
699  void CopyToFrameBuffer(float *tcoords, float *verts,
700  vtkShaderProgram *program,
702  );
704 
705 
717  void CopyFromFrameBuffer(int srcXmin,
718  int srcYmin,
719  int dstXmin,
720  int dstYmin,
721  int width,
722  int height);
723 
736  void GetShiftAndScale(float &shift, float &scale);
737 
738 protected:
741 
743 
748 
753 
758 
759  int NumberOfDimensions;
760  unsigned int Width;
761  unsigned int Height;
762  unsigned int Depth;
763 
764  unsigned int Target; // GLenum
765  unsigned int Format; // GLenum
766  unsigned int InternalFormat; // GLenum
767  unsigned int Type; // GLenum
768  int Components;
769 
771  unsigned int Handle;
772  bool RequireTextureInteger;
773  bool SupportsTextureInteger;
774  bool RequireTextureFloat;
775  bool SupportsTextureFloat;
776  bool RequireDepthBufferFloat;
777  bool SupportsDepthBufferFloat;
778 
779  int WrapS;
780  int WrapT;
781  int WrapR;
782  int MinificationFilter;
783  int MagnificationFilter;
784 
785  float MinLOD;
786  float MaxLOD;
787  int BaseLevel;
788  int MaxLevel;
789  float BorderColor[4];
790 
791  bool DepthTextureCompare;
792  int DepthTextureCompareFunction;
793 
794  bool GenerateMipmap;
795 
796  int AutoParameters;
797  vtkTimeStamp SendParametersTime;
798 
799  // used for copying to framebuffer
801 
802  // for texturebuffers we hold on to the Buffer
804 
805 private:
806  vtkTextureObject(const vtkTextureObject&) VTK_DELETE_FUNCTION;
807  void operator=(const vtkTextureObject&) VTK_DELETE_FUNCTION;
808 };
809 
810 #endif
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
OpenGL buffer object.
OpenGL rendering window.
The VertexArrayObject class uses, or emulates, vertex array objects.
abstracts an OpenGL pixel buffer object.
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
static bool IsSupported(vtkOpenGLRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
unsigned int InternalFormat
bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat)
Create a 2D depth texture but does not initialize its values.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void SetContext(vtkOpenGLRenderWindow *)
Get/Set the context.
void Activate()
Activate and Bind the texture.
bool Create2DFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data)
Create a 2D texture from client memory numComps must be in [1-4].
vtkOpenGLHelper * ShaderProgram
bool IsBound()
Tells if the texture object is bound to the active texture image unit.
void SetInternalFormat(unsigned int glInternalFormat)
int GetDefaultDataType(int vtk_scalar_type)
void ReleaseGraphicsResources(vtkWindow *win)
Deactivate and UnBind the texture.
bool Allocate1D(unsigned int width, int numComps, int vtkType)
Create a 1D color texture but does not initialize its values.
unsigned int GetWrapTMode(int vtktype)
bool Create1D(int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
Create a 1D texture using the PBO.
void CopyToFrameBuffer(vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
Copy the texture (src) in the current framebuffer.
void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin, int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
int GetVTKDataType()
Get the data type for the texture as a vtk type int i.e.
void GetShiftAndScale(float &shift, float &scale)
Get the shift and scale required in the shader to return the texture values to their original range.
unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
Get/Set format (OpenGL internal format) that should be used.
void DestroyTexture()
Destroy the texture.
void SetLinearMagnification(bool val)
Tells if the magnification mode is linear (true) or nearest (false).
unsigned int GetMinificationFilterMode(int vtktype)
int GetTextureUnit()
Return the texture unit used for this texture.
void ResetFormatAndType()
Reset format, internal format, and type of the texture.
bool CreateTextureBuffer(unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject *bo)
Create a texture buffer basically a 1D texture that can be very large for passing data into the fragm...
static vtkTextureObject * New()
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void CreateTexture()
Creates a texture handle if not already created.
static int GetMaximumTextureSize(vtkOpenGLRenderWindow *context)
Query and return maximum texture size (dimension) supported by the OpenGL driver for a particular con...
vtkOpenGLBufferObject * BufferObject
unsigned int GetWrapRMode(int vtktype)
bool CreateCubeFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data[6])
Create a cube texture from 6 buffers from client memory.
unsigned int GetWrapSMode(int vtktype)
void CopyToFrameBuffer(float *tcoords, float *verts, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
Create a 3D texture using the PBO.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Check for feature support, without any optional features.
void SetDataType(unsigned int glType)
void Deactivate()
Deactivate and UnBind the texture.
vtkWeakPointer< vtkOpenGLRenderWindow > Context
bool CreateDepthFromRaw(unsigned int width, unsigned int height, int internalFormat, int rawType, void *raw)
Create a 2D depth texture using a raw pointer.
void SetFormat(unsigned int glFormat)
unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
Get/Set internal format (OpenGL internal format) that should be used.
unsigned int GetTuples()
unsigned int GetMagnificationFilterMode(int vtktype)
bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType, void *data)
Create a 3D texture from client memory numComps must be in [1-4].
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
Create a 2D texture using the PBO.
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool shaderSupportsTextureInt)
int GetDataType(int vtk_scalar_type)
Get the data type for the texture as GLenum type.
bool Allocate3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType)
Create a 3D color texture but does not initialize its values.
bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool shaderSupportsTextureInt)
Create texture without uploading any data.
unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
bool CreateDepth(unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject *pbo)
Create a 2D depth texture using a PBO.
void CopyFromFrameBuffer(int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height)
Copy a sub-part of a logical buffer of the framebuffer (color or depth) to the texture object.
bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
Load all necessary extensions.
vtkOpenGLRenderWindow * GetContext()
unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
bool CreateAlphaFromRaw(unsigned int width, int internalFormat, int rawType, void *raw)
Create a 1D alpha texture using a raw pointer.
void SendParameters()
Send all the texture object parameters to the hardware if not done yet.
void Bind()
Bind UnBind The texture must have been created using Create().
bool Allocate2D(unsigned int width, unsigned int height, int numComps, int vtkType)
Create a 2D color texture but does not initialize its values.
bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void *data)
Create 1D texture from client memory.
void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin, int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
vtkPixelBufferObject * Download()
This is used to download raw data from the texture into a pixel bufer.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ scale
Definition: vtkX3D.h:229
@ alpha
Definition: vtkX3D.h:250
@ height
Definition: vtkX3D.h:254
@ data
Definition: vtkX3D.h:315
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.