VTK  9.3.1
vtkTextureObject.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
15 #ifndef vtkTextureObject_h
16 #define vtkTextureObject_h
17 
18 #include "vtkObject.h"
19 #include "vtkRenderingOpenGL2Module.h" // For export macro
20 #include "vtkWeakPointer.h" // for render context
21 
22 VTK_ABI_NAMESPACE_BEGIN
24 class vtkOpenGLHelper;
28 class vtkShaderProgram;
29 class vtkWindow;
31 
32 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
33 {
34 public:
35  // DepthTextureCompareFunction values.
36  enum
37  {
38  Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
39  Gequal, // r=R>=Dt ? 1.0 : 0.0
40  Less, // r=R<D_t ? 1.0 : 0.0
41  Greater, // r=R>Dt ? 1.0 : 0.0
42  Equal, // r=R==Dt ? 1.0 : 0.0
43  NotEqual, // r=R!=Dt ? 1.0 : 0.0
44  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
45  Never, // r=0.0
46  NumberOfDepthTextureCompareFunctions
47  };
48 
49 // ClampToBorder is not supported in ES 2.0
50 // Wrap values.
51 #ifndef GL_ES_VERSION_3_0
52  enum { ClampToEdge = 0, Repeat, MirroredRepeat, ClampToBorder, NumberOfWrapModes };
53 #else
54  enum
55  {
56  ClampToEdge = 0,
57  Repeat,
58  MirroredRepeat,
59  NumberOfWrapModes
60  };
61 #endif
62 
63  // MinificationFilter values.
64  enum
65  {
66  Nearest = 0,
72  NumberOfMinificationModes
73  };
74 
75  // depth/color format
76  enum
77  {
78  Native = 0, // will try to match with the depth buffer format.
85  NumberOfDepthFormats
86  };
87 
88  static vtkTextureObject* New();
89  vtkTypeMacro(vtkTextureObject, vtkObject);
90  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
93 
102  void SetContext(vtkOpenGLRenderWindow*);
103  vtkOpenGLRenderWindow* GetContext();
105 
107 
111  vtkGetMacro(Width, unsigned int);
112  vtkGetMacro(Height, unsigned int);
113  vtkGetMacro(Depth, unsigned int);
114  vtkGetMacro(Samples, unsigned int);
115  vtkGetMacro(Components, int);
116  unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
118 
119  vtkGetMacro(NumberOfDimensions, int);
120 
121  // for MSAA textures set the number of samples
122  vtkSetMacro(Samples, unsigned int);
123 
125 
128  vtkGetMacro(Target, unsigned int);
130 
132 
135  vtkGetMacro(Handle, unsigned int);
137 
141  int GetTextureUnit();
142 
144 
149  void Bind();
151 
155  virtual void Activate();
156 
160  void Deactivate();
161 
165  virtual void ReleaseGraphicsResources(vtkWindow* win);
166 
171  bool IsBound();
172 
179  void SendParameters();
180 
182 
186  vtkSetMacro(AutoParameters, int);
187  vtkGetMacro(AutoParameters, int);
188  vtkBooleanMacro(AutoParameters, int);
190 
195  bool Create2DFromRaw(
196  unsigned int width, unsigned int height, int numComps, int dataType, void* data);
197 
203  bool CreateDepthFromRaw(
204  unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
205 
210  bool CreateTextureBuffer(
211  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
212 
219  bool EmulateTextureBufferWith2DTextures(
220  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
221 
227  bool CreateCubeFromRaw(
228  unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
229 
240  bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
241 
245  bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
246 
253  bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
254  bool shaderSupportsTextureInt);
255 
262  bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
263  vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
264 
269  bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
270  int dataType, void* data);
271 
278  bool AllocateProxyTexture3D(
279  unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType);
280 
287  vtkPixelBufferObject* Download();
288  vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
289 
294  bool CreateDepth(
295  unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
296 
300  bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
301 
305  bool AllocateDepthStencil(unsigned int width, unsigned int height);
306 
311  bool Allocate1D(unsigned int width, int numComps, int vtkType);
312 
317  bool Allocate2D(
318  unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
319 
324  bool Allocate3D(
325  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
326 
328 
331  bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
332  {
333  return this->Allocate2D(width, height, numComps, vtktype);
334  }
335  bool Create3D(
336  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
337  {
338  return this->Allocate3D(width, height, depth, numComps, vtktype);
339  }
341 
345  int GetVTKDataType();
346 
348 
351  int GetDataType(int vtk_scalar_type);
352  void SetDataType(unsigned int glType);
353  int GetDefaultDataType(int vtk_scalar_type);
355 
357 
362  unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
363  void SetInternalFormat(unsigned int glInternalFormat);
364  unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
366 
368 
373  unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
374  void SetFormat(unsigned int glFormat);
375  unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
377 
386  void ResetFormatAndType();
387 
388  unsigned int GetMinificationFilterMode(int vtktype);
389  unsigned int GetMagnificationFilterMode(int vtktype);
390  unsigned int GetWrapSMode(int vtktype);
391  unsigned int GetWrapTMode(int vtktype);
392  unsigned int GetWrapRMode(int vtktype);
393 
395 
401  vtkSetMacro(RequireDepthBufferFloat, bool);
402  vtkGetMacro(RequireDepthBufferFloat, bool);
403  vtkGetMacro(SupportsDepthBufferFloat, bool);
405 
407 
413  vtkSetMacro(RequireTextureFloat, bool);
414  vtkGetMacro(RequireTextureFloat, bool);
415  vtkGetMacro(SupportsTextureFloat, bool);
417 
419 
425  vtkSetMacro(RequireTextureInteger, bool);
426  vtkGetMacro(RequireTextureInteger, bool);
427  vtkGetMacro(SupportsTextureInteger, bool);
429 
431 
441  vtkGetMacro(WrapS, int);
442  vtkSetMacro(WrapS, int);
444 
446 
456  vtkGetMacro(WrapT, int);
457  vtkSetMacro(WrapT, int);
459 
461 
471  vtkGetMacro(WrapR, int);
472  vtkSetMacro(WrapR, int);
474 
476 
489  vtkGetMacro(MinificationFilter, int);
490  vtkSetMacro(MinificationFilter, int);
492 
494 
501  vtkGetMacro(MagnificationFilter, int);
502  vtkSetMacro(MagnificationFilter, int);
504 
509  void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
510 
511  bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
512 
514 
519  vtkSetVector4Macro(BorderColor, float);
520  vtkGetVector4Macro(BorderColor, float);
522 
524 
528  vtkSetMacro(MinLOD, float);
529  vtkGetMacro(MinLOD, float);
531 
533 
537  vtkSetMacro(MaxLOD, float);
538  vtkGetMacro(MaxLOD, float);
540 
542 
547  vtkSetMacro(BaseLevel, int);
548  vtkGetMacro(BaseLevel, int);
550 
552 
557  vtkSetMacro(MaxLevel, int);
558  vtkGetMacro(MaxLevel, int);
560 
562 
572  vtkGetMacro(DepthTextureCompare, bool);
573  vtkSetMacro(DepthTextureCompare, bool);
575 
577 
597  vtkGetMacro(DepthTextureCompareFunction, int);
598  vtkSetMacro(DepthTextureCompareFunction, int);
600 
602 
607  vtkGetMacro(GenerateMipmap, bool);
608  vtkSetMacro(GenerateMipmap, bool);
610 
612 
617  vtkSetMacro(MaximumAnisotropicFiltering, float);
618  vtkGetMacro(MaximumAnisotropicFiltering, float);
620 
622 
631  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
632  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
633 
639  int GetMaximumTextureSize3D();
641 
647  static bool IsSupported(vtkOpenGLRenderWindow*, bool /* requireTexFloat */,
648  bool /* requireDepthFloat */, bool /* requireTexInt */)
649  {
650  return true;
651  }
652 
656  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
657 
659 
664  void CopyToFrameBuffer(vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
665  // part of a texture to part of a viewport, scaling as needed
666  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
667  int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
669  // copy part of a texture to part of a viewport, no scalaing
670  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
671  int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
673  // copy a texture to a quad using the provided tcoords and verts
674  void CopyToFrameBuffer(
675  float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
677 
689  void CopyFromFrameBuffer(
690  int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
691 
704  void GetShiftAndScale(float& shift, float& scale);
705 
706  // resizes an existing texture, any existing
707  // data values are lost
708  void Resize(unsigned int width, unsigned int height);
709 
711 
717  vtkGetMacro(UseSRGBColorSpace, bool);
718  vtkSetMacro(UseSRGBColorSpace, bool);
719  vtkBooleanMacro(UseSRGBColorSpace, bool);
721 
730  void AssignToExistingTexture(unsigned int handle, unsigned int target);
731 
732 protected:
734  ~vtkTextureObject() override;
735 
737 
741  void CreateTexture();
742 
746  void DestroyTexture();
747 
749  unsigned int Width;
750  unsigned int Height;
751  unsigned int Depth;
752  unsigned int Samples;
754 
756 
757  unsigned int Target; // GLenum
758  unsigned int Format; // GLenum
759  unsigned int InternalFormat; // GLenum
760  unsigned int Type; // GLenum
762 
764  unsigned int Handle;
765  bool OwnHandle;
772 
773  int WrapS;
774  int WrapT;
775  int WrapR;
778 
779  float MinLOD;
780  float MaxLOD;
782  int MaxLevel;
783  float BorderColor[4];
784 
787 
789 
792 
793  // used for copying to framebuffer
795 
796  // for texturebuffers we hold on to the Buffer
798 
799 private:
800  vtkTextureObject(const vtkTextureObject&) = delete;
801  void operator=(const vtkTextureObject&) = delete;
802 };
803 
804 VTK_ABI_NAMESPACE_END
805 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:24
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:27
unsigned int Target
a simple class to control print indentation
Definition: vtkIndent.h:28
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.