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  // Internal depth format
93  enum
94  {
95  Native=0, // will try to match with the depth buffer format.
96  Fixed16,
97  Fixed24,
98  Fixed32,
99  Float32,
100  NumberOfDepthFormats
101  };
102 
103  // Internal alpha format
104  enum
105  {
106  alpha=0,
111  NumberOfAlphaFormats
112  };
113 
114  // Depth mode formats
115  enum
116  {
117  DepthAlpha=0,
120  NumberOfDepthModeFormats
121  };
122 
123  static vtkTextureObject* New();
124  vtkTypeMacro(vtkTextureObject, vtkObject);
125  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
126 
128 
137  void SetContext(vtkOpenGLRenderWindow*);
138  vtkOpenGLRenderWindow* GetContext();
140 
142 
146  vtkGetMacro(Width, unsigned int);
147  vtkGetMacro(Height, unsigned int);
148  vtkGetMacro(Depth, unsigned int);
149  vtkGetMacro(Samples, unsigned int);
150  vtkGetMacro(Components, int);
151  unsigned int GetTuples()
152  { return this->Width*this->Height*this->Depth; }
154 
155  vtkGetMacro(NumberOfDimensions, int);
156 
157  //for MSAA textures set the number of samples
158  vtkSetMacro(Samples, unsigned int);
159 
161 
164  vtkGetMacro(Target, unsigned int);
166 
168 
171  vtkGetMacro(Handle, unsigned int);
173 
177  int GetTextureUnit();
178 
180 
185  void Bind();
186  void UnBind();
188 
192  void Activate();
193 
197  void Deactivate();
198 
202  void ReleaseGraphicsResources(vtkWindow *win);
203 
208  bool IsBound();
209 
211 
217  void SendParameters();
218  vtkSetMacro(AutoParameters, int);
219  vtkGetMacro(AutoParameters, int);
221 
226  bool Create2DFromRaw(unsigned int width, unsigned int height,
227  int numComps, int dataType, void *data);
228 
233  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
234  int internalFormat, int rawType,
235  void *raw);
236 
241  bool CreateTextureBuffer(unsigned int numValues, int numComps,
242  int dataType, vtkOpenGLBufferObject *bo);
243 
249  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
250  int numComps, int dataType, void *data[6]);
251 
252 // 1D textures are not supported in ES 2.0 or 3.0
253 #if GL_ES_VERSION_3_0 != 1
254 
265  bool Create1D(int numComps,
267  bool shaderSupportsTextureInt);
268 
272  bool Create1DFromRaw(unsigned int width, int numComps,
273  int dataType, void *data);
278  bool CreateAlphaFromRaw(unsigned int width,
279  int internalFormat,
280  int rawType,
281  void *raw);
282 #endif
283 
290  bool Create2D(unsigned int width, unsigned int height, int numComps,
292  bool shaderSupportsTextureInt);
293 
300  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
301  int numComps, vtkPixelBufferObject *pbo,
302  bool shaderSupportsTextureInt);
303 
308  bool Create3DFromRaw(unsigned int width, unsigned int height,
309  unsigned int depth, int numComps,
310  int dataType, void *data);
311 
318  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
319  unsigned int const depth, int const numComps, int const dataType);
320 
327  vtkPixelBufferObject* Download();
328 
333  bool CreateDepth(unsigned int width,
334  unsigned int height,
335  int internalFormat,
336  vtkPixelBufferObject *pbo);
337 
341  bool AllocateDepth(unsigned int width, unsigned int height,
342  int internalFormat);
343 
348  bool Allocate1D(unsigned int width, int numComps, int vtkType);
349 
354  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
355  int vtkType);
356 
361  bool Allocate3D(unsigned int width, unsigned int height,
362  unsigned int depth, int numComps,
363  int vtkType);
364 
365 
367 
370  bool Create2D(unsigned int width, unsigned int height, int numComps,
371  int vtktype, bool ){
372  return this->Allocate2D(width, height, numComps, vtktype); }
373  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
374  int numComps, int vtktype, bool ) {
375  return this->Allocate3D(width, height, depth, numComps, vtktype); }
377 
381  int GetVTKDataType();
382 
384 
387  int GetDataType(int vtk_scalar_type);
388  void SetDataType(unsigned int glType);
389  int GetDefaultDataType(int vtk_scalar_type);
391 
393 
398  unsigned int GetInternalFormat(int vtktype, int numComps,
399  bool shaderSupportsTextureInt);
400  void SetInternalFormat(unsigned int glInternalFormat);
401  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
402  bool shaderSupportsTextureInt);
404 
406 
411  unsigned int GetFormat(int vtktype, int numComps,
412  bool shaderSupportsTextureInt);
413  void SetFormat(unsigned int glFormat);
414  unsigned int GetDefaultFormat(int vtktype, int numComps,
415  bool shaderSupportsTextureInt);
417 
426  void ResetFormatAndType();
427 
428  unsigned int GetMinificationFilterMode(int vtktype);
429  unsigned int GetMagnificationFilterMode(int vtktype);
430  unsigned int GetWrapSMode(int vtktype);
431  unsigned int GetWrapTMode(int vtktype);
432  unsigned int GetWrapRMode(int vtktype);
433 
435 
441  vtkSetMacro(RequireDepthBufferFloat, bool);
442  vtkGetMacro(RequireDepthBufferFloat, bool);
443  vtkGetMacro(SupportsDepthBufferFloat, bool);
445 
447 
453  vtkSetMacro(RequireTextureFloat, bool);
454  vtkGetMacro(RequireTextureFloat, bool);
455  vtkGetMacro(SupportsTextureFloat, bool);
457 
459 
465  vtkSetMacro(RequireTextureInteger, bool);
466  vtkGetMacro(RequireTextureInteger, bool);
467  vtkGetMacro(SupportsTextureInteger, bool);
469 
471 
481  vtkGetMacro(WrapS, int);
482  vtkSetMacro(WrapS, int);
484 
486 
496  vtkGetMacro(WrapT, int);
497  vtkSetMacro(WrapT, int);
499 
501 
511  vtkGetMacro(WrapR, int);
512  vtkSetMacro(WrapR, int);
514 
516 
529  vtkGetMacro(MinificationFilter, int);
530  vtkSetMacro(MinificationFilter, int);
532 
534 
541  vtkGetMacro(MagnificationFilter, int);
542  vtkSetMacro(MagnificationFilter, int);
544 
549  void SetLinearMagnification(bool val)
550  { this->SetMagnificationFilter(val?Linear:Nearest); }
551 
553  { return this->MagnificationFilter==Linear; }
554 
556 
561  vtkSetVector4Macro(BorderColor, float);
562  vtkGetVector4Macro(BorderColor, float);
564 
566 
570  vtkSetMacro(MinLOD, float);
571  vtkGetMacro(MinLOD, float);
573 
575 
579  vtkSetMacro(MaxLOD, float);
580  vtkGetMacro(MaxLOD, float);
582 
584 
589  vtkSetMacro(BaseLevel, int);
590  vtkGetMacro(BaseLevel, int);
592 
594 
599  vtkSetMacro(MaxLevel, int);
600  vtkGetMacro(MaxLevel, int);
602 
604 
614  vtkGetMacro(DepthTextureCompare, bool);
615  vtkSetMacro(DepthTextureCompare, bool);
617 
619 
639  vtkGetMacro(DepthTextureCompareFunction, int);
640  vtkSetMacro(DepthTextureCompareFunction, int);
642 
644 
649  vtkGetMacro(GenerateMipmap, bool);
650  vtkSetMacro(GenerateMipmap, bool);
652 
654 
663  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
664  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
665 
671  int GetMaximumTextureSize3D();
673 
679  static bool IsSupported(
680  vtkOpenGLRenderWindow* renWin,
681  bool requireTexFloat,
682  bool requireDepthFloat,
683  bool requireTexInt);
684 
688  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
689  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
690 
692 
697  void CopyToFrameBuffer(vtkShaderProgram *program,
699  // part of a texture to part of a viewport, scaling as needed
700  void CopyToFrameBuffer(int srcXmin, int srcYmin,
701  int srcXmax, int srcYmax,
702  int dstXmin, int dstYmin,
703  int dstXmax, int dstYmax,
704  int dstSizeX, int dstSizeY,
705  vtkShaderProgram *program,
707  );
708  // copy part of a texure to part of a viewport, no scalaing
709  void CopyToFrameBuffer(int srcXmin, int srcYmin,
710  int srcXmax, int srcYmax,
711  int dstXmin, int dstYmin,
712  int dstSizeX, int dstSizeY,
713  vtkShaderProgram *program,
715  );
716  // copy a texture to a quad using the provided tcoords and verts
717  void CopyToFrameBuffer(float *tcoords, float *verts,
718  vtkShaderProgram *program,
720  );
722 
723 
735  void CopyFromFrameBuffer(int srcXmin,
736  int srcYmin,
737  int dstXmin,
738  int dstYmin,
739  int width,
740  int height);
741 
754  void GetShiftAndScale(float &shift, float &scale);
755 
756  // resizes an existing texture, any existing
757  // data values are lost
758  void Resize(unsigned int width, unsigned int height);
759 
760 protected:
762  ~vtkTextureObject() VTK_OVERRIDE;
763 
765 
769  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
770 
774  void CreateTexture();
775 
779  void DestroyTexture();
780 
781  int NumberOfDimensions;
782  unsigned int Width;
783  unsigned int Height;
784  unsigned int Depth;
785  unsigned int Samples;
786 
787  unsigned int Target; // GLenum
788  unsigned int Format; // GLenum
789  unsigned int InternalFormat; // GLenum
790  unsigned int Type; // GLenum
791  int Components;
792 
794  unsigned int Handle;
795  bool RequireTextureInteger;
796  bool SupportsTextureInteger;
797  bool RequireTextureFloat;
798  bool SupportsTextureFloat;
799  bool RequireDepthBufferFloat;
800  bool SupportsDepthBufferFloat;
801 
802  int WrapS;
803  int WrapT;
804  int WrapR;
805  int MinificationFilter;
806  int MagnificationFilter;
807 
808  float MinLOD;
809  float MaxLOD;
810  int BaseLevel;
811  int MaxLevel;
812  float BorderColor[4];
813 
814  bool DepthTextureCompare;
815  int DepthTextureCompareFunction;
816 
817  bool GenerateMipmap;
818 
819  int AutoParameters;
820  vtkTimeStamp SendParametersTime;
821 
822  // used for copying to framebuffer
824 
825  // for texturebuffers we hold on to the Buffer
827 
828 private:
829  vtkTextureObject(const vtkTextureObject&) VTK_DELETE_FUNCTION;
830  void operator=(const vtkTextureObject&) VTK_DELETE_FUNCTION;
831 };
832 
833 #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:53
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:32
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:34
a simple class to control print indentation
Definition: vtkIndent.h:33
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.
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.