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;
36 class vtkShaderProgram;
37 class vtkWindow;
39 
40 
41 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
42 {
43 public:
44 
45  // DepthTextureCompareFunction values.
46  enum
47  {
48  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
49  Gequal, // r=R>=Dt ? 1.0 : 0.0
50  Less, // r=R<D_t ? 1.0 : 0.0
51  Greater, // r=R>Dt ? 1.0 : 0.0
52  Equal, // r=R==Dt ? 1.0 : 0.0
53  NotEqual, // r=R!=Dt ? 1.0 : 0.0
54  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
55  Never, // r=0.0
56  NumberOfDepthTextureCompareFunctions
57  };
58 
59 // ClampToBorder is not supported in ES 2.0
60 // Wrap values.
61 #if GL_ES_VERSION_3_0 != 1
62  enum
63  {
64  ClampToEdge=0,
65  Repeat,
66  MirroredRepeat,
67  ClampToBorder,
68  NumberOfWrapModes
69  };
70 #else
71  enum
72  {
73  ClampToEdge=0,
74  Repeat,
75  MirroredRepeat,
76  NumberOfWrapModes
77  };
78 #endif
79 
80  // MinificationFilter values.
81  enum
82  {
83  Nearest=0,
84  Linear,
85  NearestMipmapNearest,
86  NearestMipmapLinear,
87  LinearMipmapNearest,
88  LinearMipmapLinear,
89  NumberOfMinificationModes
90  };
91 
92  // depth/color format
93  enum
94  {
95  Native=0, // will try to match with the depth buffer format.
97  Fixed16,
98  Fixed24,
99  Fixed32,
101  Float32,
102  NumberOfDepthFormats
103  };
104 
105  static vtkTextureObject* New();
106  vtkTypeMacro(vtkTextureObject, vtkObject);
107  void PrintSelf(ostream& os, vtkIndent indent) override;
108 
110 
119  void SetContext(vtkOpenGLRenderWindow*);
120  vtkOpenGLRenderWindow* GetContext();
122 
124 
128  vtkGetMacro(Width, unsigned int);
129  vtkGetMacro(Height, unsigned int);
130  vtkGetMacro(Depth, unsigned int);
131  vtkGetMacro(Samples, unsigned int);
132  vtkGetMacro(Components, int);
133  unsigned int GetTuples()
134  { return this->Width*this->Height*this->Depth; }
136 
137  vtkGetMacro(NumberOfDimensions, int);
138 
139  //for MSAA textures set the number of samples
140  vtkSetMacro(Samples, unsigned int);
141 
143 
146  vtkGetMacro(Target, unsigned int);
148 
150 
153  vtkGetMacro(Handle, unsigned int);
155 
159  int GetTextureUnit();
160 
162 
167  void Bind();
169 
173  void Activate();
174 
178  void Deactivate();
179 
183  void ReleaseGraphicsResources(vtkWindow *win);
184 
189  bool IsBound();
190 
192 
198  void SendParameters();
199  vtkSetMacro(AutoParameters, int);
200  vtkGetMacro(AutoParameters, int);
202 
207  bool Create2DFromRaw(unsigned int width, unsigned int height,
208  int numComps, int dataType, void *data);
209 
214  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
215  int internalFormat, int rawType,
216  void *raw);
217 
222  bool CreateTextureBuffer(unsigned int numValues, int numComps,
223  int dataType, vtkOpenGLBufferObject *bo);
224 
230  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
231  int numComps, int dataType, void *data[6]);
232 
233 // 1D textures are not supported in ES 2.0 or 3.0
234 #if GL_ES_VERSION_3_0 != 1
235 
246  bool Create1D(int numComps,
248  bool shaderSupportsTextureInt);
249 
253  bool Create1DFromRaw(unsigned int width, int numComps,
254  int dataType, void *data);
255 #endif
256 
263  bool Create2D(unsigned int width, unsigned int height, int numComps,
265  bool shaderSupportsTextureInt);
266 
273  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
274  int numComps, vtkPixelBufferObject *pbo,
275  bool shaderSupportsTextureInt);
276 
281  bool Create3DFromRaw(unsigned int width, unsigned int height,
282  unsigned int depth, int numComps,
283  int dataType, void *data);
284 
291  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
292  unsigned int const depth, int const numComps, int const dataType);
293 
300  vtkPixelBufferObject* Download();
301 
306  bool CreateDepth(unsigned int width,
307  unsigned int height,
308  int internalFormat,
309  vtkPixelBufferObject *pbo);
310 
314  bool AllocateDepth(unsigned int width, unsigned int height,
315  int internalFormat);
316 
321  bool Allocate1D(unsigned int width, int numComps, int vtkType);
322 
327  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
328  int vtkType);
329 
334  bool Allocate3D(unsigned int width, unsigned int height,
335  unsigned int depth, int numComps,
336  int vtkType);
337 
338 
340 
343  bool Create2D(unsigned int width, unsigned int height, int numComps,
344  int vtktype, bool ){
345  return this->Allocate2D(width, height, numComps, vtktype); }
346  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
347  int numComps, int vtktype, bool ) {
348  return this->Allocate3D(width, height, depth, numComps, vtktype); }
350 
354  int GetVTKDataType();
355 
357 
360  int GetDataType(int vtk_scalar_type);
361  void SetDataType(unsigned int glType);
362  int GetDefaultDataType(int vtk_scalar_type);
364 
366 
371  unsigned int GetInternalFormat(int vtktype, int numComps,
372  bool shaderSupportsTextureInt);
373  void SetInternalFormat(unsigned int glInternalFormat);
374  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
375  bool shaderSupportsTextureInt);
377 
379 
384  unsigned int GetFormat(int vtktype, int numComps,
385  bool shaderSupportsTextureInt);
386  void SetFormat(unsigned int glFormat);
387  unsigned int GetDefaultFormat(int vtktype, int numComps,
388  bool shaderSupportsTextureInt);
390 
399  void ResetFormatAndType();
400 
401  unsigned int GetMinificationFilterMode(int vtktype);
402  unsigned int GetMagnificationFilterMode(int vtktype);
403  unsigned int GetWrapSMode(int vtktype);
404  unsigned int GetWrapTMode(int vtktype);
405  unsigned int GetWrapRMode(int vtktype);
406 
408 
414  vtkSetMacro(RequireDepthBufferFloat, bool);
415  vtkGetMacro(RequireDepthBufferFloat, bool);
416  vtkGetMacro(SupportsDepthBufferFloat, bool);
418 
420 
426  vtkSetMacro(RequireTextureFloat, bool);
427  vtkGetMacro(RequireTextureFloat, bool);
428  vtkGetMacro(SupportsTextureFloat, bool);
430 
432 
438  vtkSetMacro(RequireTextureInteger, bool);
439  vtkGetMacro(RequireTextureInteger, bool);
440  vtkGetMacro(SupportsTextureInteger, bool);
442 
444 
454  vtkGetMacro(WrapS, int);
455  vtkSetMacro(WrapS, int);
457 
459 
469  vtkGetMacro(WrapT, int);
470  vtkSetMacro(WrapT, int);
472 
474 
484  vtkGetMacro(WrapR, int);
485  vtkSetMacro(WrapR, int);
487 
489 
502  vtkGetMacro(MinificationFilter, int);
503  vtkSetMacro(MinificationFilter, int);
505 
507 
514  vtkGetMacro(MagnificationFilter, int);
515  vtkSetMacro(MagnificationFilter, int);
517 
522  void SetLinearMagnification(bool val)
523  { this->SetMagnificationFilter(val?Linear:Nearest); }
524 
526  { return this->MagnificationFilter==Linear; }
527 
529 
534  vtkSetVector4Macro(BorderColor, float);
535  vtkGetVector4Macro(BorderColor, float);
537 
539 
543  vtkSetMacro(MinLOD, float);
544  vtkGetMacro(MinLOD, float);
546 
548 
552  vtkSetMacro(MaxLOD, float);
553  vtkGetMacro(MaxLOD, float);
555 
557 
562  vtkSetMacro(BaseLevel, int);
563  vtkGetMacro(BaseLevel, int);
565 
567 
572  vtkSetMacro(MaxLevel, int);
573  vtkGetMacro(MaxLevel, int);
575 
577 
587  vtkGetMacro(DepthTextureCompare, bool);
588  vtkSetMacro(DepthTextureCompare, bool);
590 
592 
612  vtkGetMacro(DepthTextureCompareFunction, int);
613  vtkSetMacro(DepthTextureCompareFunction, int);
615 
617 
622  vtkGetMacro(GenerateMipmap, bool);
623  vtkSetMacro(GenerateMipmap, bool);
625 
627 
636  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
637  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
638 
644  int GetMaximumTextureSize3D();
646 
652  static bool IsSupported(
653  vtkOpenGLRenderWindow* renWin,
654  bool requireTexFloat,
655  bool requireDepthFloat,
656  bool requireTexInt);
657 
661  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
662  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
663 
665 
670  void CopyToFrameBuffer(vtkShaderProgram *program,
672  // part of a texture to part of a viewport, scaling as needed
673  void CopyToFrameBuffer(int srcXmin, int srcYmin,
674  int srcXmax, int srcYmax,
675  int dstXmin, int dstYmin,
676  int dstXmax, int dstYmax,
677  int dstSizeX, int dstSizeY,
678  vtkShaderProgram *program,
680  );
681  // copy part of a texure to part of a viewport, no scalaing
682  void CopyToFrameBuffer(int srcXmin, int srcYmin,
683  int srcXmax, int srcYmax,
684  int dstXmin, int dstYmin,
685  int dstSizeX, int dstSizeY,
686  vtkShaderProgram *program,
688  );
689  // copy a texture to a quad using the provided tcoords and verts
690  void CopyToFrameBuffer(float *tcoords, float *verts,
691  vtkShaderProgram *program,
693  );
695 
696 
708  void CopyFromFrameBuffer(int srcXmin,
709  int srcYmin,
710  int dstXmin,
711  int dstYmin,
712  int width,
713  int height);
714 
727  void GetShiftAndScale(float &shift, float &scale);
728 
729  // resizes an existing texture, any existing
730  // data values are lost
731  void Resize(unsigned int width, unsigned int height);
732 
734 
740  vtkGetMacro(UseSRGBColorSpace, bool);
741  vtkSetMacro(UseSRGBColorSpace, bool);
742  vtkBooleanMacro(UseSRGBColorSpace, bool);
744 
745 
746 protected:
748  ~vtkTextureObject() override;
749 
751 
755  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
756 
760  void CreateTexture();
761 
765  void DestroyTexture();
766 
767  int NumberOfDimensions;
768  unsigned int Width;
769  unsigned int Height;
770  unsigned int Depth;
771  unsigned int Samples;
773 
774  unsigned int Target; // GLenum
775  unsigned int Format; // GLenum
776  unsigned int InternalFormat; // GLenum
777  unsigned int Type; // GLenum
778  int Components;
779 
781  unsigned int Handle;
782  bool RequireTextureInteger;
783  bool SupportsTextureInteger;
784  bool RequireTextureFloat;
785  bool SupportsTextureFloat;
786  bool RequireDepthBufferFloat;
787  bool SupportsDepthBufferFloat;
788 
789  int WrapS;
790  int WrapT;
791  int WrapR;
792  int MinificationFilter;
793  int MagnificationFilter;
794 
795  float MinLOD;
796  float MaxLOD;
797  int BaseLevel;
798  int MaxLevel;
799  float BorderColor[4];
800 
801  bool DepthTextureCompare;
802  int DepthTextureCompareFunction;
803 
804  bool GenerateMipmap;
805 
806  int AutoParameters;
807  vtkTimeStamp SendParametersTime;
808 
809  // used for copying to framebuffer
811 
812  // for texturebuffers we hold on to the Buffer
814 
815 private:
816  vtkTextureObject(const vtkTextureObject&) = delete;
817  void operator=(const vtkTextureObject&) = delete;
818 };
819 
820 #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.
unsigned int Samples
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.
bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
Create texture without uploading any data.
vtkOpenGLBufferObject * BufferObject
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstracts an OpenGL texture object.
OpenGL buffer object.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
Create texture without uploading any data.
The ShaderProgram uses one or more Shader objects.