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 =========================================================================*/
27 #ifndef vtkTextureObject_h
28 #define vtkTextureObject_h
29 
30 #include "vtkRenderingOpenGL2Module.h" // For export macro
31 #include "vtkObject.h"
32 #include "vtkWeakPointer.h" // for render context
33 
35 class vtkOpenGLHelper;
38 class vtkShaderProgram;
39 class vtkWindow;
41 
42 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
44 #endif
45 
46 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
47 {
48 public:
49 
50  // DepthTextureCompareFunction values.
51  enum
52  {
53  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
54  Gequal, // r=R>=Dt ? 1.0 : 0.0
55  Less, // r=R<D_t ? 1.0 : 0.0
56  Greater, // r=R>Dt ? 1.0 : 0.0
57  Equal, // r=R==Dt ? 1.0 : 0.0
58  NotEqual, // r=R!=Dt ? 1.0 : 0.0
59  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
60  Never, // r=0.0
61  NumberOfDepthTextureCompareFunctions
62  };
63 
64 // ClampToBorder is not supported in ES 2.0
65 // Wrap values.
66 #if GL_ES_VERSION_2_0 != 1
67  enum
68  {
69  ClampToEdge=0,
70  Repeat,
71  MirroredRepeat,
72  ClampToBorder,
73  NumberOfWrapModes
74  };
75 #else
76  enum
77  {
78  ClampToEdge=0,
79  Repeat,
80  MirroredRepeat,
81  NumberOfWrapModes
82  };
83 #endif
84 
85  // MinificationFilter values.
86  enum
87  {
88  Nearest=0,
89  Linear,
90  NearestMipmapNearest,
91  NearestMipmapLinear,
92  LinearMipmapNearest,
93  LinearMipmapLinear,
94  NumberOfMinificationModes
95  };
96 
97  // Internal depth format
98  enum
99  {
100  Native=0, // will try to match with the depth buffer format.
101  Fixed16,
102  Fixed24,
103  Fixed32,
104  Float32,
105  NumberOfDepthFormats
106  };
107 
108  // Internal alpha format
109  enum
110  {
111  alpha=0,
116  NumberOfAlphaFormats
117  };
118 
119  // Depth mode formats
120  enum
121  {
122  DepthAlpha=0,
125  NumberOfDepthModeFormats
126  };
127 
128  static vtkTextureObject* New();
129  vtkTypeMacro(vtkTextureObject, vtkObject);
130  void PrintSelf(ostream& os, vtkIndent indent);
131 
133 
142  void SetContext(vtkOpenGLRenderWindow*);
143  vtkOpenGLRenderWindow* GetContext();
145 
147 
151  vtkGetMacro(Width, unsigned int);
152  vtkGetMacro(Height, unsigned int);
153  vtkGetMacro(Depth, unsigned int);
154  vtkGetMacro(Components, int);
155  unsigned int GetTuples()
156  { return this->Width*this->Height*this->Depth; }
158 
159  vtkGetMacro(NumberOfDimensions, int);
160 
162 
165  vtkGetMacro(Target, unsigned int);
167 
169 
172  vtkGetMacro(Handle, unsigned int);
174 
178  int GetTextureUnit();
179 
181 
186  void Bind();
187  void UnBind();
189 
193  void Activate();
194 
198  void Deactivate();
199 
203  void ReleaseGraphicsResources(vtkWindow *win);
204 
209  bool IsBound();
210 
212 
218  void SendParameters();
219  vtkSetMacro(AutoParameters, int);
220  vtkGetMacro(AutoParameters, int);
222 
227  bool Create2DFromRaw(unsigned int width, unsigned int height,
228  int numComps, int dataType, void *data);
229 
234  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
235  int internalFormat, int rawType,
236  void *raw);
237 
242  bool CreateTextureBuffer(unsigned int numValues, int numComps,
243  int dataType, vtkOpenGLBufferObject *bo);
244 
250  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
251  int numComps, int dataType, void *data[6]);
252 
253 // 1D textures are not supported in ES 2.0 or 3.0
254 #if GL_ES_VERSION_2_0 != 1
255 
266  bool Create1D(int numComps,
268  bool shaderSupportsTextureInt);
269 
273  bool Create1DFromRaw(unsigned int width, int numComps,
274  int dataType, void *data);
279  bool CreateAlphaFromRaw(unsigned int width,
280  int internalFormat,
281  int rawType,
282  void *raw);
283 #endif
284 
285 // PBO's, and 3D textures are not supported in ES 2.0
286 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
287 
294  bool Create2D(unsigned int width, unsigned int height, int numComps,
296  bool shaderSupportsTextureInt);
297 
304  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
305  int numComps, vtkPixelBufferObject *pbo,
306  bool shaderSupportsTextureInt);
307 
312  bool Create3DFromRaw(unsigned int width, unsigned int height,
313  unsigned int depth, int numComps,
314  int dataType, void *data);
315 
322  vtkPixelBufferObject* Download();
323 
328  bool CreateDepth(unsigned int width,
329  unsigned int height,
330  int internalFormat,
331  vtkPixelBufferObject *pbo);
332 
333 #endif
334 
338  bool AllocateDepth(unsigned int width, unsigned int height,
339  int internalFormat);
340 
345  bool Allocate1D(unsigned int width, int numComps, int vtkType);
346 
351  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
352  int vtkType);
353 
358  bool Allocate3D(unsigned int width, unsigned int height,
359  unsigned int depth, int numComps,
360  int vtkType);
361 
362 
364 
367  bool Create2D(unsigned int width, unsigned int height, int numComps,
368  int vtktype, bool shaderSupportsTextureInt);
369  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
370  int numComps, int vtktype, bool shaderSupportsTextureInt);
372 
376  int GetVTKDataType();
377 
379 
382  int GetDataType(int vtk_scalar_type);
383  void SetDataType(unsigned int glType);
384  int GetDefaultDataType(int vtk_scalar_type);
386 
388 
393  unsigned int GetInternalFormat(int vtktype, int numComps,
394  bool shaderSupportsTextureInt);
395  void SetInternalFormat(unsigned int glInternalFormat);
396  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
397  bool shaderSupportsTextureInt);
399 
401 
406  unsigned int GetFormat(int vtktype, int numComps,
407  bool shaderSupportsTextureInt);
408  void SetFormat(unsigned int glFormat);
409  unsigned int GetDefaultFormat(int vtktype, int numComps,
410  bool shaderSupportsTextureInt);
412 
421  void ResetFormatAndType();
422 
423  unsigned int GetMinificationFilterMode(int vtktype);
424  unsigned int GetMagnificationFilterMode(int vtktype);
425  unsigned int GetWrapSMode(int vtktype);
426  unsigned int GetWrapTMode(int vtktype);
427  unsigned int GetWrapRMode(int vtktype);
428 
430 
436  vtkSetMacro(RequireDepthBufferFloat, bool);
437  vtkGetMacro(RequireDepthBufferFloat, bool);
438  vtkGetMacro(SupportsDepthBufferFloat, bool);
440 
442 
448  vtkSetMacro(RequireTextureFloat, bool);
449  vtkGetMacro(RequireTextureFloat, bool);
450  vtkGetMacro(SupportsTextureFloat, bool);
452 
454 
460  vtkSetMacro(RequireTextureInteger, bool);
461  vtkGetMacro(RequireTextureInteger, bool);
462  vtkGetMacro(SupportsTextureInteger, bool);
464 
466 
476  vtkGetMacro(WrapS, int);
477  vtkSetMacro(WrapS, int);
479 
481 
491  vtkGetMacro(WrapT, int);
492  vtkSetMacro(WrapT, int);
494 
496 
506  vtkGetMacro(WrapR, int);
507  vtkSetMacro(WrapR, int);
509 
511 
524  vtkGetMacro(MinificationFilter, int);
525  vtkSetMacro(MinificationFilter, int);
527 
529 
536  vtkGetMacro(MagnificationFilter, int);
537  vtkSetMacro(MagnificationFilter, int);
539 
544  void SetLinearMagnification(bool val)
545  { this->SetMagnificationFilter(val?Linear:Nearest); }
546 
548  { return this->MagnificationFilter==Linear; }
549 
551 
556  vtkSetVector4Macro(BorderColor, float);
557  vtkGetVector4Macro(BorderColor, float);
559 
561 
565  vtkSetMacro(MinLOD, float);
566  vtkGetMacro(MinLOD, float);
568 
570 
574  vtkSetMacro(MaxLOD, float);
575  vtkGetMacro(MaxLOD, float);
577 
579 
584  vtkSetMacro(BaseLevel, int);
585  vtkGetMacro(BaseLevel, int);
587 
589 
594  vtkSetMacro(MaxLevel, int);
595  vtkGetMacro(MaxLevel, int);
597 
599 
609  vtkGetMacro(DepthTextureCompare, bool);
610  vtkSetMacro(DepthTextureCompare, bool);
612 
614 
634  vtkGetMacro(DepthTextureCompareFunction, int);
635  vtkSetMacro(DepthTextureCompareFunction, int);
637 
639 
644  vtkGetMacro(GenerateMipmap, bool);
645  vtkSetMacro(GenerateMipmap, bool);
647 
657  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
658 
664  static bool IsSupported(
665  vtkOpenGLRenderWindow* renWin,
666  bool requireTexFloat,
667  bool requireDepthFloat,
668  bool requireTexInt);
669 
673  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
674  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
675 
677 
682  void CopyToFrameBuffer(vtkShaderProgram *program,
684  // part of a texture to part of a viewport, scaling as needed
685  void CopyToFrameBuffer(int srcXmin, int srcYmin,
686  int srcXmax, int srcYmax,
687  int dstXmin, int dstYmin,
688  int dstXmax, int dstYmax,
689  int dstSizeX, int dstSizeY,
690  vtkShaderProgram *program,
692  );
693  // copy part of a texure to part of a viewport, no scalaing
694  void CopyToFrameBuffer(int srcXmin, int srcYmin,
695  int srcXmax, int srcYmax,
696  int dstXmin, int dstYmin,
697  int dstSizeX, int dstSizeY,
698  vtkShaderProgram *program,
700  );
701  // copy a texture to a quad using the provided tcoords and verts
702  void CopyToFrameBuffer(float *tcoords, float *verts,
703  vtkShaderProgram *program,
705  );
707 
708 
720  void CopyFromFrameBuffer(int srcXmin,
721  int srcYmin,
722  int dstXmin,
723  int dstYmin,
724  int width,
725  int height);
726 
739  void GetShiftAndScale(float &shift, float &scale);
740 
741 protected:
743  ~vtkTextureObject();
744 
746 
750  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
751 
755  void CreateTexture();
756 
760  void DestroyTexture();
761 
762  int NumberOfDimensions;
763  unsigned int Width;
764  unsigned int Height;
765  unsigned int Depth;
766 
767  unsigned int Target; // GLenum
768  unsigned int Format; // GLenum
769  unsigned int InternalFormat; // GLenum
770  unsigned int Type; // GLenum
771  int Components;
772 
774  unsigned int Handle;
775  bool RequireTextureInteger;
776  bool SupportsTextureInteger;
777  bool RequireTextureFloat;
778  bool SupportsTextureFloat;
779  bool RequireDepthBufferFloat;
780  bool SupportsDepthBufferFloat;
781 
782  int WrapS;
783  int WrapT;
784  int WrapR;
785  int MinificationFilter;
786  int MagnificationFilter;
787 
788  float MinLOD;
789  float MaxLOD;
790  int BaseLevel;
791  int MaxLevel;
792  float BorderColor[4];
793 
794  bool DepthTextureCompare;
795  int DepthTextureCompareFunction;
796 
797  bool GenerateMipmap;
798 
799  int AutoParameters;
800  vtkTimeStamp SendParametersTime;
801 
802  // used for copying to framebuffer
804 
805  // for texturebuffers we hold on to the Buffer
807 
808 private:
809  vtkTextureObject(const vtkTextureObject&) VTK_DELETE_FUNCTION;
810  void operator=(const vtkTextureObject&) VTK_DELETE_FUNCTION;
811 };
812 
813 #endif
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Check for feature support, without any optional features.
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkOpenGLHelper * ShaderProgram
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned int GetTuples()
Get the texture dimensions.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
unsigned int InternalFormat
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkWeakPointer< vtkOpenGLRenderWindow > Context
void SetLinearMagnification(bool val)
Tells if the magnification mode is linear (true) or nearest (false).
abstracts an OpenGL pixel buffer object.
vtkOpenGLBufferObject * BufferObject
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstracts an OpenGL texture object.
OpenGL buffer object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
The ShaderProgram uses one or more Shader objects.