VTK  9.2.20221001
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 =========================================================================*/
46 #ifndef vtkTextureObject_h
47 #define vtkTextureObject_h
48 
49 #include "vtkObject.h"
50 #include "vtkRenderingOpenGL2Module.h" // For export macro
51 #include "vtkWeakPointer.h" // for render context
52 
53 VTK_ABI_NAMESPACE_BEGIN
55 class vtkOpenGLHelper;
59 class vtkShaderProgram;
60 class vtkWindow;
62 
63 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
64 {
65 public:
66  // DepthTextureCompareFunction values.
67  enum
68  {
69  Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
70  Gequal, // r=R>=Dt ? 1.0 : 0.0
71  Less, // r=R<D_t ? 1.0 : 0.0
72  Greater, // r=R>Dt ? 1.0 : 0.0
73  Equal, // r=R==Dt ? 1.0 : 0.0
74  NotEqual, // r=R!=Dt ? 1.0 : 0.0
75  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
76  Never, // r=0.0
77  NumberOfDepthTextureCompareFunctions
78  };
79 
80 // ClampToBorder is not supported in ES 2.0
81 // Wrap values.
82 #ifndef GL_ES_VERSION_3_0
83  enum { ClampToEdge = 0, Repeat, MirroredRepeat, ClampToBorder, NumberOfWrapModes };
84 #else
85  enum
86  {
87  ClampToEdge = 0,
88  Repeat,
89  MirroredRepeat,
90  NumberOfWrapModes
91  };
92 #endif
93 
94  // MinificationFilter values.
95  enum
96  {
97  Nearest = 0,
103  NumberOfMinificationModes
104  };
105 
106  // depth/color format
107  enum
108  {
109  Native = 0, // will try to match with the depth buffer format.
116  NumberOfDepthFormats
117  };
118 
120  vtkTypeMacro(vtkTextureObject, vtkObject);
121  void PrintSelf(ostream& os, vtkIndent indent) override;
122 
124 
136 
138 
142  vtkGetMacro(Width, unsigned int);
143  vtkGetMacro(Height, unsigned int);
144  vtkGetMacro(Depth, unsigned int);
145  vtkGetMacro(Samples, unsigned int);
146  vtkGetMacro(Components, int);
147  unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
149 
150  vtkGetMacro(NumberOfDimensions, int);
151 
152  // for MSAA textures set the number of samples
153  vtkSetMacro(Samples, unsigned int);
154 
156 
159  vtkGetMacro(Target, unsigned int);
161 
163 
166  vtkGetMacro(Handle, unsigned int);
168 
173 
175 
180  void Bind();
182 
186  virtual void Activate();
187 
191  void Deactivate();
192 
197 
202  bool IsBound();
203 
211 
213 
217  vtkSetMacro(AutoParameters, int);
218  vtkGetMacro(AutoParameters, int);
219  vtkBooleanMacro(AutoParameters, int);
221 
227  unsigned int width, unsigned int height, int numComps, int dataType, void* data);
228 
235  unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
236 
242  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
243 
250  unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
251 
262  bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
263 
267  bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
268 
275  bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
276  bool shaderSupportsTextureInt);
277 
284  bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
285  vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
286 
291  bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
292  int dataType, void* data);
293 
300  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
301  unsigned int const depth, int const numComps, int const dataType);
302 
310  vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
311 
317  unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
318 
322  bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
323 
327  bool AllocateDepthStencil(unsigned int width, unsigned int height);
328 
333  bool Allocate1D(unsigned int width, int numComps, int vtkType);
334 
340  unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
341 
347  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
348 
350 
353  bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
354  {
355  return this->Allocate2D(width, height, numComps, vtktype);
356  }
357  bool Create3D(
358  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
359  {
360  return this->Allocate3D(width, height, depth, numComps, vtktype);
361  }
363 
368 
370 
373  int GetDataType(int vtk_scalar_type);
374  void SetDataType(unsigned int glType);
375  int GetDefaultDataType(int vtk_scalar_type);
377 
379 
384  unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
385  void SetInternalFormat(unsigned int glInternalFormat);
386  unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
388 
390 
395  unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
396  void SetFormat(unsigned int glFormat);
397  unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
399 
409 
410  unsigned int GetMinificationFilterMode(int vtktype);
411  unsigned int GetMagnificationFilterMode(int vtktype);
412  unsigned int GetWrapSMode(int vtktype);
413  unsigned int GetWrapTMode(int vtktype);
414  unsigned int GetWrapRMode(int vtktype);
415 
417 
423  vtkSetMacro(RequireDepthBufferFloat, bool);
424  vtkGetMacro(RequireDepthBufferFloat, bool);
425  vtkGetMacro(SupportsDepthBufferFloat, bool);
427 
429 
435  vtkSetMacro(RequireTextureFloat, bool);
436  vtkGetMacro(RequireTextureFloat, bool);
437  vtkGetMacro(SupportsTextureFloat, bool);
439 
441 
447  vtkSetMacro(RequireTextureInteger, bool);
448  vtkGetMacro(RequireTextureInteger, bool);
449  vtkGetMacro(SupportsTextureInteger, bool);
451 
453 
463  vtkGetMacro(WrapS, int);
464  vtkSetMacro(WrapS, int);
466 
468 
478  vtkGetMacro(WrapT, int);
479  vtkSetMacro(WrapT, int);
481 
483 
493  vtkGetMacro(WrapR, int);
494  vtkSetMacro(WrapR, int);
496 
498 
511  vtkGetMacro(MinificationFilter, int);
512  vtkSetMacro(MinificationFilter, int);
514 
516 
523  vtkGetMacro(MagnificationFilter, int);
524  vtkSetMacro(MagnificationFilter, int);
526 
531  void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
532 
533  bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
534 
536 
541  vtkSetVector4Macro(BorderColor, float);
542  vtkGetVector4Macro(BorderColor, float);
544 
546 
550  vtkSetMacro(MinLOD, float);
551  vtkGetMacro(MinLOD, float);
553 
555 
559  vtkSetMacro(MaxLOD, float);
560  vtkGetMacro(MaxLOD, float);
562 
564 
569  vtkSetMacro(BaseLevel, int);
570  vtkGetMacro(BaseLevel, int);
572 
574 
579  vtkSetMacro(MaxLevel, int);
580  vtkGetMacro(MaxLevel, int);
582 
584 
594  vtkGetMacro(DepthTextureCompare, bool);
595  vtkSetMacro(DepthTextureCompare, bool);
597 
599 
619  vtkGetMacro(DepthTextureCompareFunction, int);
620  vtkSetMacro(DepthTextureCompareFunction, int);
622 
624 
629  vtkGetMacro(GenerateMipmap, bool);
630  vtkSetMacro(GenerateMipmap, bool);
632 
634 
639  vtkSetMacro(MaximumAnisotropicFiltering, float);
640  vtkGetMacro(MaximumAnisotropicFiltering, float);
642 
644 
655 
663 
669  static bool IsSupported(vtkOpenGLRenderWindow*, bool /* requireTexFloat */,
670  bool /* requireDepthFloat */, bool /* requireTexInt */)
671  {
672  return true;
673  }
674 
678  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
679 
681 
687  // part of a texture to part of a viewport, scaling as needed
688  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
689  int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
691  // copy part of a texture to part of a viewport, no scalaing
692  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
693  int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
695  // copy a texture to a quad using the provided tcoords and verts
697  float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
699 
712  int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
713 
726  void GetShiftAndScale(float& shift, float& scale);
727 
728  // resizes an existing texture, any existing
729  // data values are lost
730  void Resize(unsigned int width, unsigned int height);
731 
733 
739  vtkGetMacro(UseSRGBColorSpace, bool);
740  vtkSetMacro(UseSRGBColorSpace, bool);
741  vtkBooleanMacro(UseSRGBColorSpace, bool);
743 
752  void AssignToExistingTexture(unsigned int handle, unsigned int target);
753 
754 protected:
756  ~vtkTextureObject() override;
757 
759 
764 
769 
771  unsigned int Width;
772  unsigned int Height;
773  unsigned int Depth;
774  unsigned int Samples;
776 
778 
779  unsigned int Target; // GLenum
780  unsigned int Format; // GLenum
781  unsigned int InternalFormat; // GLenum
782  unsigned int Type; // GLenum
784 
786  unsigned int Handle;
787  bool OwnHandle;
794 
795  int WrapS;
796  int WrapT;
797  int WrapR;
800 
801  float MinLOD;
802  float MaxLOD;
804  int MaxLevel;
805  float BorderColor[4];
806 
809 
811 
814 
815  // used for copying to framebuffer
817 
818  // for texturebuffers we hold on to the Buffer
820 
821 private:
822  vtkTextureObject(const vtkTextureObject&) = delete;
823  void operator=(const vtkTextureObject&) = delete;
824 };
825 
826 VTK_ABI_NAMESPACE_END
827 #endif
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
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.
unsigned int Target
unsigned int InternalFormat
bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat)
Create a 2D depth texture but does not initialize its values.
static bool IsSupported(vtkOpenGLRenderWindow *, bool, bool, bool)
Returns if the context supports the required extensions.
void SetContext(vtkOpenGLRenderWindow *)
Get/Set the context.
bool AllocateDepthStencil(unsigned int width, unsigned int height)
Create a 2D septh stencil texture but does not initialize its values.
float MaximumAnisotropicFiltering
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].
unsigned int Depth
vtkOpenGLHelper * ShaderProgram
bool IsBound()
Tells if the texture object is bound to the active texture image unit.
void SetInternalFormat(unsigned int glInternalFormat)
Get/Set internal format (OpenGL internal format) that should be used.
int GetDefaultDataType(int vtk_scalar_type)
Get the data type for the texture as GLenum type.
void Resize(unsigned int width, unsigned int height)
bool Allocate1D(unsigned int width, int numComps, int vtkType)
Create a 1D color texture but does not initialize its values.
virtual void Activate()
Activate and Bind the texture.
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)
Copy the texture (src) in the current framebuffer.
int GetVTKDataType()
Get the data type for the texture as a vtk type int i.e.
unsigned int Handle
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).
bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height, unsigned int const depth, int const numComps, int const dataType)
Create a 3D texture using the GL_PROXY_TEXTURE_3D target.
vtkTimeStamp SendParametersTime
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 AssignToExistingTexture(unsigned int handle, unsigned int target)
Assign the TextureObject to a externally provided Handle and Target.
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 Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
Create texture without uploading any data.
unsigned int Format
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)
Copy the texture (src) in the current framebuffer.
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
Create a 3D texture using the PBO.
bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
Create texture without uploading any data.
virtual void ReleaseGraphicsResources(vtkWindow *win)
Deactivate and UnBind the texture.
void SetDataType(unsigned int glType)
Get the data type for the texture as GLenum type.
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)
Get/Set format (OpenGL internal format) that should be used.
~vtkTextureObject() override
unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
Get/Set internal format (OpenGL internal format) that should be used.
static bool IsSupported(vtkOpenGLRenderWindow *)
Check for feature support, without any optional features.
unsigned int GetTuples()
Get the texture dimensions.
unsigned int Width
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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].
bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
Create a 2D texture using the PBO.
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.
unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
Get/Set format (OpenGL internal format) that should be used.
static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow *context)
Query and return maximum texture size (dimension) supported by the OpenGL driver for a particular con...
bool CreateDepth(unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject *pbo)
Create a 2D depth texture using a PBO.
bool Allocate2D(unsigned int width, unsigned int height, int numComps, int vtkType, int level=0)
Create a 2D color texture but does not initialize its values.
vtkPixelBufferObject * Download(unsigned int target, unsigned int level)
unsigned int Height
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.
vtkOpenGLRenderWindow * GetContext()
Get/Set the context.
unsigned int Samples
int GetMaximumTextureSize3D()
Overload which uses the internal context to query the maximum 3D texture size.
unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
Get/Set internal format (OpenGL internal format) that should be used.
void SendParameters()
Send all the texture object parameters to the hardware if not done yet.
void Bind()
Bind the texture, must have been created using Create().
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)
Copy the texture (src) in the current framebuffer.
vtkPixelBufferObject * Download()
This is used to download raw data from the texture into a pixel buffer.
record modification and/or execution time
Definition: vtkTimeStamp.h:56
window superclass for vtkRenderWindow
Definition: vtkWindow.h:40
@ level
Definition: vtkX3D.h:407
@ scale
Definition: vtkX3D.h:241
@ height
Definition: vtkX3D.h:266
@ data
Definition: vtkX3D.h:327
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)