VTK  9.7.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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
22 
23 VTK_ABI_NAMESPACE_BEGIN
25 class vtkOpenGLHelper;
29 class vtkShaderProgram;
30 class vtkWindow;
32 
33 class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkTextureObject : public vtkObject
34 {
35 public:
36  // DepthTextureCompareFunction values.
37  enum
38  {
39  Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
40  Gequal, // r=R>=Dt ? 1.0 : 0.0
41  Less, // r=R<D_t ? 1.0 : 0.0
42  Greater, // r=R>Dt ? 1.0 : 0.0
43  Equal, // r=R==Dt ? 1.0 : 0.0
44  NotEqual, // r=R!=Dt ? 1.0 : 0.0
45  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
46  Never, // r=0.0
47  NumberOfDepthTextureCompareFunctions
48  };
49 
50  // Wrap values.
51  enum
52  {
53  ClampToEdge = 0,
57  NumberOfWrapModes
58  };
59 
60  // MinificationFilter values.
61  enum
62  {
63  Nearest = 0,
69  NumberOfMinificationModes
70  };
71 
72  // depth/color format
73  enum
74  {
75  Native = 0, // will try to match with the depth buffer format.
82  NumberOfDepthFormats
83  };
84 
85  static vtkTextureObject* New();
86  vtkTypeMacro(vtkTextureObject, vtkObject);
87  void PrintSelf(ostream& os, vtkIndent indent) override;
88 
90 
99  void SetContext(vtkOpenGLRenderWindow*);
100  vtkOpenGLRenderWindow* GetContext();
102 
104 
108  vtkGetMacro(Width, unsigned int);
109  vtkGetMacro(Height, unsigned int);
110  vtkGetMacro(Depth, unsigned int);
111  vtkGetMacro(Samples, unsigned int);
112  vtkGetMacro(Components, int);
113  unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
115 
116  vtkGetMacro(NumberOfDimensions, int);
117 
118  // for MSAA textures set the number of samples
119  vtkSetMacro(Samples, unsigned int);
120 
122 
125  vtkGetMacro(Target, unsigned int);
127 
129 
132  vtkGetMacro(Handle, unsigned int);
134 
138  int GetTextureUnit();
139 
141 
146  void Bind();
148 
152  virtual void Activate();
153 
157  void Deactivate();
158 
162  virtual void ReleaseGraphicsResources(vtkWindow* win);
163 
168  bool IsBound();
169 
176  void SendParameters();
177 
179 
183  vtkSetMacro(AutoParameters, int);
184  vtkGetMacro(AutoParameters, int);
185  vtkBooleanMacro(AutoParameters, int);
187 
192  bool Create2DFromRaw(
193  unsigned int width, unsigned int height, int numComps, int dataType, void* data);
194 
201  bool Create2DArrayFromRaw(
202  unsigned int width, unsigned int height, int numComps, int dataType, int nbLayers, void* data);
203 
209  bool CreateDepthFromRaw(
210  unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
211 
216  bool CreateTextureBuffer(
217  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
218 
225  bool EmulateTextureBufferWith2DTextures(
226  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
227 
236  bool EmulateTextureBufferWith2DTexturesFromRaw(
237  unsigned int numValues, int numComps, int dataType, void* data);
238 
253  bool UpdateTextureBuffer2DRegion(
254  unsigned int texelOffset, unsigned int numTexels, int numComps, int dataType, void* data);
255 
261  bool CreateCubeFromRaw(
262  unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
263 
274  bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
275 
279  bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
280 
287  bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
288  bool shaderSupportsTextureInt);
289 
296  bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
297  vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
298 
303  bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
304  int dataType, void* data);
305 
312  bool AllocateProxyTexture3D(
313  unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType);
314 
321  vtkPixelBufferObject* Download();
322  vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
323 
328  bool CreateDepth(
329  unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
330 
334  bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
335 
339  bool AllocateDepthStencil(unsigned int width, unsigned int height);
340 
345  bool Allocate1D(unsigned int width, int numComps, int vtkType);
346 
351  bool Allocate2D(
352  unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
353 
358  bool Allocate3D(
359  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
360 
362 
365  bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
366  {
367  return this->Allocate2D(width, height, numComps, vtktype);
368  }
369  bool Create3D(
370  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
371  {
372  return this->Allocate3D(width, height, depth, numComps, vtktype);
373  }
375 
379  int GetVTKDataType();
380 
382 
385  int GetDataType(int vtk_scalar_type);
386  void SetDataType(unsigned int glType);
387  int GetDefaultDataType(int vtk_scalar_type);
389 
391 
394  unsigned int GetFormat() { return this->Format; }
395  unsigned int GetInternalFormat() { return this->InternalFormat; }
396  unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
397  void SetInternalFormat(unsigned int glInternalFormat);
398  unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
400 
402 
407  unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
408  void SetFormat(unsigned int glFormat);
409  unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
411 
420  void ResetFormatAndType();
421 
422  unsigned int GetMinificationFilterMode(int vtktype);
423  unsigned int GetMagnificationFilterMode(int vtktype);
424  unsigned int GetWrapSMode(int vtktype);
425  unsigned int GetWrapTMode(int vtktype);
426  unsigned int GetWrapRMode(int vtktype);
427 
429 
435  vtkSetMacro(RequireDepthBufferFloat, bool);
436  vtkGetMacro(RequireDepthBufferFloat, bool);
437  vtkGetMacro(SupportsDepthBufferFloat, bool);
439 
441 
447  vtkSetMacro(RequireTextureFloat, bool);
448  vtkGetMacro(RequireTextureFloat, bool);
449  vtkGetMacro(SupportsTextureFloat, bool);
451 
453 
459  vtkSetMacro(RequireTextureInteger, bool);
460  vtkGetMacro(RequireTextureInteger, bool);
461  vtkGetMacro(SupportsTextureInteger, bool);
463 
465 
475  vtkGetMacro(WrapS, int);
476  vtkSetMacro(WrapS, int);
478 
480 
490  vtkGetMacro(WrapT, int);
491  vtkSetMacro(WrapT, int);
493 
495 
505  vtkGetMacro(WrapR, int);
506  vtkSetMacro(WrapR, int);
508 
510 
523  vtkGetMacro(MinificationFilter, int);
524  vtkSetMacro(MinificationFilter, int);
526 
528 
535  vtkGetMacro(MagnificationFilter, int);
536  vtkSetMacro(MagnificationFilter, int);
538 
543  void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
544 
545  bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
546 
548 
553  vtkSetVector4Macro(BorderColor, float);
554  vtkGetVector4Macro(BorderColor, float);
556 
558 
562  vtkSetMacro(MinLOD, float);
563  vtkGetMacro(MinLOD, float);
565 
567 
571  vtkSetMacro(MaxLOD, float);
572  vtkGetMacro(MaxLOD, float);
574 
576 
581  vtkSetMacro(BaseLevel, int);
582  vtkGetMacro(BaseLevel, int);
584 
586 
591  vtkSetMacro(MaxLevel, int);
592  vtkGetMacro(MaxLevel, int);
594 
596 
606  vtkGetMacro(DepthTextureCompare, bool);
607  vtkSetMacro(DepthTextureCompare, bool);
609 
611 
631  vtkGetMacro(DepthTextureCompareFunction, int);
632  vtkSetMacro(DepthTextureCompareFunction, int);
634 
636 
641  vtkGetMacro(GenerateMipmap, bool);
642  vtkSetMacro(GenerateMipmap, bool);
644 
646 
651  vtkSetMacro(MaximumAnisotropicFiltering, float);
652  vtkGetMacro(MaximumAnisotropicFiltering, float);
654 
656 
665  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
666  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
667 
673  int GetMaximumTextureSize3D();
675 
681  static bool IsSupported(vtkOpenGLRenderWindow* renWin, bool requireTexFloat,
682  bool requireDepthFloat, bool requireTexInt);
683 
687  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
688  {
689  return vtkTextureObject::IsSupported(renWin, false, false, false);
690  }
691 
693 
698  void CopyToFrameBuffer(vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
699  // part of a texture to part of a viewport, scaling as needed
700  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
701  int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
703  // copy part of a texture to part of a viewport, no scalaing
704  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
705  int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
707  // copy a texture to a quad using the provided tcoords and verts
708  void CopyToFrameBuffer(
709  float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
711 
723  void CopyFromFrameBuffer(
724  int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
725 
738  void GetShiftAndScale(float& shift, float& scale);
739 
740  // resizes an existing texture, any existing
741  // data values are lost
742  void Resize(unsigned int width, unsigned int height);
743 
745 
751  vtkGetMacro(UseSRGBColorSpace, bool);
752  vtkSetMacro(UseSRGBColorSpace, bool);
753  vtkBooleanMacro(UseSRGBColorSpace, bool);
755 
764  void AssignToExistingTexture(unsigned int handle, unsigned int target);
765 
766 protected:
768  ~vtkTextureObject() override;
769 
771 
775  bool LoadRequiredExtensions(vtkOpenGLRenderWindow* renWin);
776 
780  void CreateTexture();
781 
785  void DestroyTexture();
786 
788  unsigned int Width;
789  unsigned int Height;
790  unsigned int Depth;
791  unsigned int Samples;
793 
795 
796  unsigned int Target; // GLenum
797  unsigned int Format; // GLenum
798  unsigned int InternalFormat; // GLenum
799  unsigned int Type; // GLenum
801 
803  unsigned int Handle;
804  bool OwnHandle;
811 
812  int WrapS;
813  int WrapT;
814  int WrapR;
817 
818  float MinLOD;
819  float MaxLOD;
821  int MaxLevel;
822  float BorderColor[4];
823 
826 
828 
831 
832  // used for copying to framebuffer
834 
835  // for texturebuffers we hold on to the Buffer
837 
838 private:
839  vtkTextureObject(const vtkTextureObject&) = delete;
840  void operator=(const vtkTextureObject&) = delete;
841 };
842 
843 VTK_ABI_NAMESPACE_END
844 #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:52
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:41
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
unsigned int GetFormat()
Get the format (GLenum) and internal format (GLenum) in use.
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.
unsigned int GetInternalFormat()
Get the format (GLenum) and internal format (GLenum) in use.
vtkOpenGLBufferObject * BufferObject
abstracts an OpenGL texture object.
float MaximumAnisotropicFiltering
#define VTK_MARSHALAUTO
OpenGL buffer object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
static bool IsSupported(vtkOpenGLRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
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.