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;
39 class vtkShaderProgram;
40 class vtkWindow;
42 
43 
44 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
45 {
46 public:
47 
48  // DepthTextureCompareFunction values.
49  enum
50  {
51  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
52  Gequal, // r=R>=Dt ? 1.0 : 0.0
53  Less, // r=R<D_t ? 1.0 : 0.0
54  Greater, // r=R>Dt ? 1.0 : 0.0
55  Equal, // r=R==Dt ? 1.0 : 0.0
56  NotEqual, // r=R!=Dt ? 1.0 : 0.0
57  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
58  Never, // r=0.0
59  NumberOfDepthTextureCompareFunctions
60  };
61 
62 // ClampToBorder is not supported in ES 2.0
63 // Wrap values.
64 #if GL_ES_VERSION_3_0 != 1
65  enum
66  {
67  ClampToEdge=0,
71  NumberOfWrapModes
72  };
73 #else
74  enum
75  {
76  ClampToEdge=0,
77  Repeat,
78  MirroredRepeat,
79  NumberOfWrapModes
80  };
81 #endif
82 
83  // MinificationFilter values.
84  enum
85  {
86  Nearest=0,
92  NumberOfMinificationModes
93  };
94 
95  // depth/color format
96  enum
97  {
98  Native=0, // will try to match with the depth buffer format.
105  NumberOfDepthFormats
106  };
107 
108  static vtkTextureObject* New();
109  vtkTypeMacro(vtkTextureObject, vtkObject);
110  void PrintSelf(ostream& os, vtkIndent indent) override;
111 
113 
122  void SetContext(vtkOpenGLRenderWindow*);
123  vtkOpenGLRenderWindow* GetContext();
125 
127 
131  vtkGetMacro(Width, unsigned int);
132  vtkGetMacro(Height, unsigned int);
133  vtkGetMacro(Depth, unsigned int);
134  vtkGetMacro(Samples, unsigned int);
135  vtkGetMacro(Components, int);
136  unsigned int GetTuples()
137  { return this->Width*this->Height*this->Depth; }
139 
140  vtkGetMacro(NumberOfDimensions, int);
141 
142  //for MSAA textures set the number of samples
143  vtkSetMacro(Samples, unsigned int);
144 
146 
149  vtkGetMacro(Target, unsigned int);
151 
153 
156  vtkGetMacro(Handle, unsigned int);
158 
162  int GetTextureUnit();
163 
165 
170  void Bind();
172 
176  void Activate();
177 
181  void Deactivate();
182 
186  void ReleaseGraphicsResources(vtkWindow *win);
187 
192  bool IsBound();
193 
195 
201  void SendParameters();
202  vtkSetMacro(AutoParameters, int);
203  vtkGetMacro(AutoParameters, int);
205 
210  bool Create2DFromRaw(unsigned int width, unsigned int height,
211  int numComps, int dataType, void *data);
212 
217  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
218  int internalFormat, int rawType,
219  void *raw);
220 
225  bool CreateTextureBuffer(unsigned int numValues, int numComps,
226  int dataType, vtkOpenGLBufferObject *bo);
227 
233  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
234  int numComps, int dataType, void *data[6]);
235 
236 // 1D textures are not supported in ES 2.0 or 3.0
237 #if GL_ES_VERSION_3_0 != 1
238 
249  bool Create1D(int numComps,
251  bool shaderSupportsTextureInt);
252 
256  bool Create1DFromRaw(unsigned int width, int numComps,
257  int dataType, void *data);
258 #endif
259 
266  bool Create2D(unsigned int width, unsigned int height, int numComps,
268  bool shaderSupportsTextureInt);
269 
276  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
277  int numComps, vtkPixelBufferObject *pbo,
278  bool shaderSupportsTextureInt);
279 
284  bool Create3DFromRaw(unsigned int width, unsigned int height,
285  unsigned int depth, int numComps,
286  int dataType, void *data);
287 
294  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
295  unsigned int const depth, int const numComps, int const dataType);
296 
303  vtkPixelBufferObject* Download();
304 
309  bool CreateDepth(unsigned int width,
310  unsigned int height,
311  int internalFormat,
312  vtkPixelBufferObject *pbo);
313 
317  bool AllocateDepth(unsigned int width, unsigned int height,
318  int internalFormat);
319 
324  bool Allocate1D(unsigned int width, int numComps, int vtkType);
325 
330  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
331  int vtkType, int level = 0);
332 
337  bool Allocate3D(unsigned int width, unsigned int height,
338  unsigned int depth, int numComps,
339  int vtkType);
340 
341 
343 
346  bool Create2D(unsigned int width, unsigned int height, int numComps,
347  int vtktype, bool ){
348  return this->Allocate2D(width, height, numComps, vtktype); }
349  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
350  int numComps, int vtktype, bool ) {
351  return this->Allocate3D(width, height, depth, numComps, vtktype); }
353 
357  int GetVTKDataType();
358 
360 
363  int GetDataType(int vtk_scalar_type);
364  void SetDataType(unsigned int glType);
365  int GetDefaultDataType(int vtk_scalar_type);
367 
369 
374  unsigned int GetInternalFormat(int vtktype, int numComps,
375  bool shaderSupportsTextureInt);
376  void SetInternalFormat(unsigned int glInternalFormat);
377  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
378  bool shaderSupportsTextureInt);
380 
382 
387  unsigned int GetFormat(int vtktype, int numComps,
388  bool shaderSupportsTextureInt);
389  void SetFormat(unsigned int glFormat);
390  unsigned int GetDefaultFormat(int vtktype, int numComps,
391  bool shaderSupportsTextureInt);
393 
402  void ResetFormatAndType();
403 
404  unsigned int GetMinificationFilterMode(int vtktype);
405  unsigned int GetMagnificationFilterMode(int vtktype);
406  unsigned int GetWrapSMode(int vtktype);
407  unsigned int GetWrapTMode(int vtktype);
408  unsigned int GetWrapRMode(int vtktype);
409 
411 
417  vtkSetMacro(RequireDepthBufferFloat, bool);
418  vtkGetMacro(RequireDepthBufferFloat, bool);
419  vtkGetMacro(SupportsDepthBufferFloat, bool);
421 
423 
429  vtkSetMacro(RequireTextureFloat, bool);
430  vtkGetMacro(RequireTextureFloat, bool);
431  vtkGetMacro(SupportsTextureFloat, bool);
433 
435 
441  vtkSetMacro(RequireTextureInteger, bool);
442  vtkGetMacro(RequireTextureInteger, bool);
443  vtkGetMacro(SupportsTextureInteger, bool);
445 
447 
457  vtkGetMacro(WrapS, int);
458  vtkSetMacro(WrapS, int);
460 
462 
472  vtkGetMacro(WrapT, int);
473  vtkSetMacro(WrapT, int);
475 
477 
487  vtkGetMacro(WrapR, int);
488  vtkSetMacro(WrapR, int);
490 
492 
505  vtkGetMacro(MinificationFilter, int);
506  vtkSetMacro(MinificationFilter, int);
508 
510 
517  vtkGetMacro(MagnificationFilter, int);
518  vtkSetMacro(MagnificationFilter, int);
520 
525  void SetLinearMagnification(bool val)
526  { this->SetMagnificationFilter(val?Linear:Nearest); }
527 
529  { return this->MagnificationFilter==Linear; }
530 
532 
537  vtkSetVector4Macro(BorderColor, float);
538  vtkGetVector4Macro(BorderColor, float);
540 
542 
546  vtkSetMacro(MinLOD, float);
547  vtkGetMacro(MinLOD, float);
549 
551 
555  vtkSetMacro(MaxLOD, float);
556  vtkGetMacro(MaxLOD, float);
558 
560 
565  vtkSetMacro(BaseLevel, int);
566  vtkGetMacro(BaseLevel, int);
568 
570 
575  vtkSetMacro(MaxLevel, int);
576  vtkGetMacro(MaxLevel, int);
578 
580 
590  vtkGetMacro(DepthTextureCompare, bool);
591  vtkSetMacro(DepthTextureCompare, bool);
593 
595 
615  vtkGetMacro(DepthTextureCompareFunction, int);
616  vtkSetMacro(DepthTextureCompareFunction, int);
618 
620 
625  vtkGetMacro(GenerateMipmap, bool);
626  vtkSetMacro(GenerateMipmap, bool);
628 
630 
639  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
640  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
641 
647  int GetMaximumTextureSize3D();
649 
655  static bool IsSupported(
657  bool /* requireTexFloat */,
658  bool /* requireDepthFloat */,
659  bool /* requireTexInt */) { return true; }
660 
665  { return true; }
666 
668 
673  void CopyToFrameBuffer(vtkShaderProgram *program,
675  // part of a texture to part of a viewport, scaling as needed
676  void CopyToFrameBuffer(int srcXmin, int srcYmin,
677  int srcXmax, int srcYmax,
678  int dstXmin, int dstYmin,
679  int dstXmax, int dstYmax,
680  int dstSizeX, int dstSizeY,
681  vtkShaderProgram *program,
683  );
684  // copy part of a texure to part of a viewport, no scalaing
685  void CopyToFrameBuffer(int srcXmin, int srcYmin,
686  int srcXmax, int srcYmax,
687  int dstXmin, int dstYmin,
688  int dstSizeX, int dstSizeY,
689  vtkShaderProgram *program,
691  );
692  // copy a texture to a quad using the provided tcoords and verts
693  void CopyToFrameBuffer(float *tcoords, float *verts,
694  vtkShaderProgram *program,
696  );
698 
699 
711  void CopyFromFrameBuffer(int srcXmin,
712  int srcYmin,
713  int dstXmin,
714  int dstYmin,
715  int width,
716  int height);
717 
730  void GetShiftAndScale(float &shift, float &scale);
731 
732  // resizes an existing texture, any existing
733  // data values are lost
734  void Resize(unsigned int width, unsigned int height);
735 
737 
743  vtkGetMacro(UseSRGBColorSpace, bool);
744  vtkSetMacro(UseSRGBColorSpace, bool);
745  vtkBooleanMacro(UseSRGBColorSpace, bool);
747 
748 
749 protected:
751  ~vtkTextureObject() override;
752 
754 
758  void CreateTexture();
759 
763  void DestroyTexture();
764 
766  unsigned int Width;
767  unsigned int Height;
768  unsigned int Depth;
769  unsigned int Samples;
771 
772  unsigned int Target; // GLenum
773  unsigned int Format; // GLenum
774  unsigned int InternalFormat; // GLenum
775  unsigned int Type; // GLenum
777 
779  unsigned int Handle;
786 
787  int WrapS;
788  int WrapT;
789  int WrapR;
792 
793  float MinLOD;
794  float MaxLOD;
796  int MaxLevel;
797  float BorderColor[4];
798 
801 
803 
806 
807  // used for copying to framebuffer
809 
810  // for texturebuffers we hold on to the Buffer
812 
813 private:
814  vtkTextureObject(const vtkTextureObject&) = delete;
815  void operator=(const vtkTextureObject&) = delete;
816 };
817 
818 #endif
OpenGL rendering window.
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 Format
unsigned int Handle
unsigned int GetTuples()
Get the texture dimensions.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
unsigned int InternalFormat
unsigned int Samples
unsigned int Width
vtkTimeStamp SendParametersTime
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
unsigned int Target
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).
unsigned int Depth
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
static bool IsSupported(vtkOpenGLRenderWindow *, bool, bool, bool)
Returns if the context supports the required extensions.
abstracts an OpenGL texture object.
OpenGL buffer object.
static bool IsSupported(vtkOpenGLRenderWindow *)
Check for feature support, without any optional features.
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.
unsigned int Height
The ShaderProgram uses one or more Shader objects.