VTK  9.2.6
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 "vtkObject.h"
31 #include "vtkRenderingOpenGL2Module.h" // For export macro
32 #include "vtkWeakPointer.h" // for render context
33 
35 class vtkOpenGLHelper;
39 class vtkShaderProgram;
40 class vtkWindow;
42 
43 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
44 {
45 public:
46  // DepthTextureCompareFunction values.
47  enum
48  {
49  Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
50  Gequal, // r=R>=Dt ? 1.0 : 0.0
51  Less, // r=R<D_t ? 1.0 : 0.0
52  Greater, // r=R>Dt ? 1.0 : 0.0
53  Equal, // r=R==Dt ? 1.0 : 0.0
54  NotEqual, // r=R!=Dt ? 1.0 : 0.0
55  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
56  Never, // r=0.0
57  NumberOfDepthTextureCompareFunctions
58  };
59 
60 // ClampToBorder is not supported in ES 2.0
61 // Wrap values.
62 #ifndef GL_ES_VERSION_3_0
63  enum { ClampToEdge = 0, Repeat, MirroredRepeat, ClampToBorder, NumberOfWrapModes };
64 #else
65  enum
66  {
67  ClampToEdge = 0,
68  Repeat,
69  MirroredRepeat,
70  NumberOfWrapModes
71  };
72 #endif
73 
74  // MinificationFilter values.
75  enum
76  {
77  Nearest = 0,
83  NumberOfMinificationModes
84  };
85 
86  // depth/color format
87  enum
88  {
89  Native = 0, // will try to match with the depth buffer format.
96  NumberOfDepthFormats
97  };
98 
99  static vtkTextureObject* New();
100  vtkTypeMacro(vtkTextureObject, vtkObject);
101  void PrintSelf(ostream& os, vtkIndent indent) override;
102 
104 
113  void SetContext(vtkOpenGLRenderWindow*);
114  vtkOpenGLRenderWindow* GetContext();
116 
118 
122  vtkGetMacro(Width, unsigned int);
123  vtkGetMacro(Height, unsigned int);
124  vtkGetMacro(Depth, unsigned int);
125  vtkGetMacro(Samples, unsigned int);
126  vtkGetMacro(Components, int);
127  unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
129 
130  vtkGetMacro(NumberOfDimensions, int);
131 
132  // for MSAA textures set the number of samples
133  vtkSetMacro(Samples, unsigned int);
134 
136 
139  vtkGetMacro(Target, unsigned int);
141 
143 
146  vtkGetMacro(Handle, unsigned int);
148 
152  int GetTextureUnit();
153 
155 
160  void Bind();
162 
166  virtual void Activate();
167 
171  void Deactivate();
172 
176  virtual void ReleaseGraphicsResources(vtkWindow* win);
177 
182  bool IsBound();
183 
190  void SendParameters();
191 
193 
197  vtkSetMacro(AutoParameters, int);
198  vtkGetMacro(AutoParameters, int);
199  vtkBooleanMacro(AutoParameters, int);
201 
206  bool Create2DFromRaw(
207  unsigned int width, unsigned int height, int numComps, int dataType, void* data);
208 
214  bool CreateDepthFromRaw(
215  unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
216 
221  bool CreateTextureBuffer(
222  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
223 
229  bool CreateCubeFromRaw(
230  unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
231 
242  bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
243 
247  bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
248 
255  bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
256  bool shaderSupportsTextureInt);
257 
264  bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
265  vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
266 
271  bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
272  int dataType, void* data);
273 
280  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
281  unsigned int const depth, int const numComps, int const dataType);
282 
289  vtkPixelBufferObject* Download();
290  vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
291 
296  bool CreateDepth(
297  unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
298 
302  bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
303 
307  bool AllocateDepthStencil(unsigned int width, unsigned int height);
308 
313  bool Allocate1D(unsigned int width, int numComps, int vtkType);
314 
319  bool Allocate2D(
320  unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
321 
326  bool Allocate3D(
327  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
328 
330 
333  bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
334  {
335  return this->Allocate2D(width, height, numComps, vtktype);
336  }
337  bool Create3D(
338  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
339  {
340  return this->Allocate3D(width, height, depth, numComps, vtktype);
341  }
343 
347  int GetVTKDataType();
348 
350 
353  int GetDataType(int vtk_scalar_type);
354  void SetDataType(unsigned int glType);
355  int GetDefaultDataType(int vtk_scalar_type);
357 
359 
364  unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
365  void SetInternalFormat(unsigned int glInternalFormat);
366  unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
368 
370 
375  unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
376  void SetFormat(unsigned int glFormat);
377  unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
379 
388  void ResetFormatAndType();
389 
390  unsigned int GetMinificationFilterMode(int vtktype);
391  unsigned int GetMagnificationFilterMode(int vtktype);
392  unsigned int GetWrapSMode(int vtktype);
393  unsigned int GetWrapTMode(int vtktype);
394  unsigned int GetWrapRMode(int vtktype);
395 
397 
403  vtkSetMacro(RequireDepthBufferFloat, bool);
404  vtkGetMacro(RequireDepthBufferFloat, bool);
405  vtkGetMacro(SupportsDepthBufferFloat, bool);
407 
409 
415  vtkSetMacro(RequireTextureFloat, bool);
416  vtkGetMacro(RequireTextureFloat, bool);
417  vtkGetMacro(SupportsTextureFloat, bool);
419 
421 
427  vtkSetMacro(RequireTextureInteger, bool);
428  vtkGetMacro(RequireTextureInteger, bool);
429  vtkGetMacro(SupportsTextureInteger, bool);
431 
433 
443  vtkGetMacro(WrapS, int);
444  vtkSetMacro(WrapS, int);
446 
448 
458  vtkGetMacro(WrapT, int);
459  vtkSetMacro(WrapT, int);
461 
463 
473  vtkGetMacro(WrapR, int);
474  vtkSetMacro(WrapR, int);
476 
478 
491  vtkGetMacro(MinificationFilter, int);
492  vtkSetMacro(MinificationFilter, int);
494 
496 
503  vtkGetMacro(MagnificationFilter, int);
504  vtkSetMacro(MagnificationFilter, int);
506 
511  void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
512 
513  bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
514 
516 
521  vtkSetVector4Macro(BorderColor, float);
522  vtkGetVector4Macro(BorderColor, float);
524 
526 
530  vtkSetMacro(MinLOD, float);
531  vtkGetMacro(MinLOD, float);
533 
535 
539  vtkSetMacro(MaxLOD, float);
540  vtkGetMacro(MaxLOD, float);
542 
544 
549  vtkSetMacro(BaseLevel, int);
550  vtkGetMacro(BaseLevel, int);
552 
554 
559  vtkSetMacro(MaxLevel, int);
560  vtkGetMacro(MaxLevel, int);
562 
564 
574  vtkGetMacro(DepthTextureCompare, bool);
575  vtkSetMacro(DepthTextureCompare, bool);
577 
579 
599  vtkGetMacro(DepthTextureCompareFunction, int);
600  vtkSetMacro(DepthTextureCompareFunction, int);
602 
604 
609  vtkGetMacro(GenerateMipmap, bool);
610  vtkSetMacro(GenerateMipmap, bool);
612 
614 
619  vtkSetMacro(MaximumAnisotropicFiltering, float);
620  vtkGetMacro(MaximumAnisotropicFiltering, float);
622 
624 
633  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
634  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
635 
641  int GetMaximumTextureSize3D();
643 
649  static bool IsSupported(vtkOpenGLRenderWindow*, bool /* requireTexFloat */,
650  bool /* requireDepthFloat */, bool /* requireTexInt */)
651  {
652  return true;
653  }
654 
658  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
659 
661 
666  void CopyToFrameBuffer(vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
667  // part of a texture to part of a viewport, scaling as needed
668  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
669  int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
671  // copy part of a texture to part of a viewport, no scalaing
672  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
673  int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
675  // copy a texture to a quad using the provided tcoords and verts
676  void CopyToFrameBuffer(
677  float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
679 
691  void CopyFromFrameBuffer(
692  int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
693 
706  void GetShiftAndScale(float& shift, float& scale);
707 
708  // resizes an existing texture, any existing
709  // data values are lost
710  void Resize(unsigned int width, unsigned int height);
711 
713 
719  vtkGetMacro(UseSRGBColorSpace, bool);
720  vtkSetMacro(UseSRGBColorSpace, bool);
721  vtkBooleanMacro(UseSRGBColorSpace, bool);
723 
732  void AssignToExistingTexture(unsigned int handle, unsigned int target);
733 
734 protected:
736  ~vtkTextureObject() override;
737 
739 
743  void CreateTexture();
744 
748  void DestroyTexture();
749 
751  unsigned int Width;
752  unsigned int Height;
753  unsigned int Depth;
754  unsigned int Samples;
756 
758 
759  unsigned int Target; // GLenum
760  unsigned int Format; // GLenum
761  unsigned int InternalFormat; // GLenum
762  unsigned int Type; // GLenum
764 
766  unsigned int Handle;
767  bool OwnHandle;
774 
775  int WrapS;
776  int WrapT;
777  int WrapR;
780 
781  float MinLOD;
782  float MaxLOD;
784  int MaxLevel;
785  float BorderColor[4];
786 
789 
791 
794 
795  // used for copying to framebuffer
797 
798  // for texturebuffers we hold on to the Buffer
800 
801 private:
802  vtkTextureObject(const vtkTextureObject&) = delete;
803  void operator=(const vtkTextureObject&) = delete;
804 };
805 
806 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:62
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
DatabaseFormatType GetFormat(const Ioss::GroupingEntity *entity)
Given any GroupingEntity pointer, returns the format that the associated database is in...
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
unsigned int Target
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
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.
float MaximumAnisotropicFiltering
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.