VTK  9.0.20200928
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 =========================================================================*/
24 #ifndef vtkTextureObject_h
25 #define vtkTextureObject_h
26 
27 #include "vtkObject.h"
28 #include "vtkRenderingOpenGL2Module.h" // For export macro
29 #include "vtkWeakPointer.h" // for render context
30 
32 class vtkOpenGLHelper;
36 class vtkShaderProgram;
37 class vtkWindow;
39 
40 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
41 {
42 public:
43  // DepthTextureCompareFunction values.
44  enum
45  {
46  Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
47  Gequal, // r=R>=Dt ? 1.0 : 0.0
48  Less, // r=R<D_t ? 1.0 : 0.0
49  Greater, // r=R>Dt ? 1.0 : 0.0
50  Equal, // r=R==Dt ? 1.0 : 0.0
51  NotEqual, // r=R!=Dt ? 1.0 : 0.0
52  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
53  Never, // r=0.0
54  NumberOfDepthTextureCompareFunctions
55  };
56 
57 // ClampToBorder is not supported in ES 2.0
58 // Wrap values.
59 #ifndef GL_ES_VERSION_3_0
60  enum { ClampToEdge = 0, Repeat, MirroredRepeat, ClampToBorder, NumberOfWrapModes };
61 #else
62  enum
63  {
64  ClampToEdge = 0,
65  Repeat,
66  MirroredRepeat,
67  NumberOfWrapModes
68  };
69 #endif
70 
71  // MinificationFilter values.
72  enum
73  {
74  Nearest = 0,
80  NumberOfMinificationModes
81  };
82 
83  // depth/color format
84  enum
85  {
86  Native = 0, // will try to match with the depth buffer format.
93  NumberOfDepthFormats
94  };
95 
96  static vtkTextureObject* New();
97  vtkTypeMacro(vtkTextureObject, vtkObject);
98  void PrintSelf(ostream& os, vtkIndent indent) override;
99 
101 
110  void SetContext(vtkOpenGLRenderWindow*);
111  vtkOpenGLRenderWindow* GetContext();
113 
115 
119  vtkGetMacro(Width, unsigned int);
120  vtkGetMacro(Height, unsigned int);
121  vtkGetMacro(Depth, unsigned int);
122  vtkGetMacro(Samples, unsigned int);
123  vtkGetMacro(Components, int);
124  unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
126 
127  vtkGetMacro(NumberOfDimensions, int);
128 
129  // for MSAA textures set the number of samples
130  vtkSetMacro(Samples, unsigned int);
131 
133 
136  vtkGetMacro(Target, unsigned int);
138 
140 
143  vtkGetMacro(Handle, unsigned int);
145 
149  int GetTextureUnit();
150 
152 
157  void Bind();
159 
163  virtual void Activate();
164 
168  void Deactivate();
169 
173  virtual void ReleaseGraphicsResources(vtkWindow* win);
174 
179  bool IsBound();
180 
187  void SendParameters();
188 
190 
194  vtkSetMacro(AutoParameters, int);
195  vtkGetMacro(AutoParameters, int);
196  vtkBooleanMacro(AutoParameters, int);
198 
203  bool Create2DFromRaw(
204  unsigned int width, unsigned int height, int numComps, int dataType, void* data);
205 
211  bool CreateDepthFromRaw(
212  unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
213 
218  bool CreateTextureBuffer(
219  unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
220 
226  bool CreateCubeFromRaw(
227  unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
228 
239  bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
240 
244  bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
245 
252  bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
253  bool shaderSupportsTextureInt);
254 
261  bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
262  vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
263 
268  bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
269  int dataType, void* data);
270 
277  bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
278  unsigned int const depth, int const numComps, int const dataType);
279 
286  vtkPixelBufferObject* Download();
287  vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
288 
293  bool CreateDepth(
294  unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
295 
299  bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
300 
304  bool AllocateDepthStencil(unsigned int width, unsigned int height);
305 
310  bool Allocate1D(unsigned int width, int numComps, int vtkType);
311 
316  bool Allocate2D(
317  unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
318 
323  bool Allocate3D(
324  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
325 
327 
330  bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
331  {
332  return this->Allocate2D(width, height, numComps, vtktype);
333  }
334  bool Create3D(
335  unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
336  {
337  return this->Allocate3D(width, height, depth, numComps, vtktype);
338  }
340 
344  int GetVTKDataType();
345 
347 
350  int GetDataType(int vtk_scalar_type);
351  void SetDataType(unsigned int glType);
352  int GetDefaultDataType(int vtk_scalar_type);
354 
356 
361  unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
362  void SetInternalFormat(unsigned int glInternalFormat);
363  unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
365 
367 
372  unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
373  void SetFormat(unsigned int glFormat);
374  unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
376 
385  void ResetFormatAndType();
386 
387  unsigned int GetMinificationFilterMode(int vtktype);
388  unsigned int GetMagnificationFilterMode(int vtktype);
389  unsigned int GetWrapSMode(int vtktype);
390  unsigned int GetWrapTMode(int vtktype);
391  unsigned int GetWrapRMode(int vtktype);
392 
394 
400  vtkSetMacro(RequireDepthBufferFloat, bool);
401  vtkGetMacro(RequireDepthBufferFloat, bool);
402  vtkGetMacro(SupportsDepthBufferFloat, bool);
404 
406 
412  vtkSetMacro(RequireTextureFloat, bool);
413  vtkGetMacro(RequireTextureFloat, bool);
414  vtkGetMacro(SupportsTextureFloat, bool);
416 
418 
424  vtkSetMacro(RequireTextureInteger, bool);
425  vtkGetMacro(RequireTextureInteger, bool);
426  vtkGetMacro(SupportsTextureInteger, bool);
428 
430 
440  vtkGetMacro(WrapS, int);
441  vtkSetMacro(WrapS, int);
443 
445 
455  vtkGetMacro(WrapT, int);
456  vtkSetMacro(WrapT, int);
458 
460 
470  vtkGetMacro(WrapR, int);
471  vtkSetMacro(WrapR, int);
473 
475 
488  vtkGetMacro(MinificationFilter, int);
489  vtkSetMacro(MinificationFilter, int);
491 
493 
500  vtkGetMacro(MagnificationFilter, int);
501  vtkSetMacro(MagnificationFilter, int);
503 
508  void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
509 
510  bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
511 
513 
518  vtkSetVector4Macro(BorderColor, float);
519  vtkGetVector4Macro(BorderColor, float);
521 
523 
527  vtkSetMacro(MinLOD, float);
528  vtkGetMacro(MinLOD, float);
530 
532 
536  vtkSetMacro(MaxLOD, float);
537  vtkGetMacro(MaxLOD, float);
539 
541 
546  vtkSetMacro(BaseLevel, int);
547  vtkGetMacro(BaseLevel, int);
549 
551 
556  vtkSetMacro(MaxLevel, int);
557  vtkGetMacro(MaxLevel, int);
559 
561 
571  vtkGetMacro(DepthTextureCompare, bool);
572  vtkSetMacro(DepthTextureCompare, bool);
574 
576 
596  vtkGetMacro(DepthTextureCompareFunction, int);
597  vtkSetMacro(DepthTextureCompareFunction, int);
599 
601 
606  vtkGetMacro(GenerateMipmap, bool);
607  vtkSetMacro(GenerateMipmap, bool);
609 
611 
616  vtkSetMacro(MaximumAnisotropicFiltering, float);
617  vtkGetMacro(MaximumAnisotropicFiltering, float);
619 
621 
630  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
631  static int GetMaximumTextureSize3D(vtkOpenGLRenderWindow* context);
632 
638  int GetMaximumTextureSize3D();
640 
646  static bool IsSupported(vtkOpenGLRenderWindow*, bool /* requireTexFloat */,
647  bool /* requireDepthFloat */, bool /* requireTexInt */)
648  {
649  return true;
650  }
651 
655  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
656 
658 
663  void CopyToFrameBuffer(vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
664  // part of a texture to part of a viewport, scaling as needed
665  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
666  int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
668  // copy part of a texure to part of a viewport, no scalaing
669  void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
670  int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
672  // copy a texture to a quad using the provided tcoords and verts
673  void CopyToFrameBuffer(
674  float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
676 
688  void CopyFromFrameBuffer(
689  int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
690 
703  void GetShiftAndScale(float& shift, float& scale);
704 
705  // resizes an existing texture, any existing
706  // data values are lost
707  void Resize(unsigned int width, unsigned int height);
708 
710 
716  vtkGetMacro(UseSRGBColorSpace, bool);
717  vtkSetMacro(UseSRGBColorSpace, bool);
718  vtkBooleanMacro(UseSRGBColorSpace, bool);
720 
729  void AssignToExistingTexture(unsigned int handle, unsigned int target);
730 
731 protected:
733  ~vtkTextureObject() override;
734 
736 
740  void CreateTexture();
741 
745  void DestroyTexture();
746 
748  unsigned int Width;
749  unsigned int Height;
750  unsigned int Depth;
751  unsigned int Samples;
753 
755 
756  unsigned int Target; // GLenum
757  unsigned int Format; // GLenum
758  unsigned int InternalFormat; // GLenum
759  unsigned int Type; // GLenum
761 
763  unsigned int Handle;
764  bool OwnHandle;
771 
772  int WrapS;
773  int WrapT;
774  int WrapR;
777 
778  float MinLOD;
779  float MaxLOD;
781  int MaxLevel;
782  float BorderColor[4];
783 
786 
788 
791 
792  // used for copying to framebuffer
794 
795  // for texturebuffers we hold on to the Buffer
797 
798 private:
799  vtkTextureObject(const vtkTextureObject&) = delete;
800  void operator=(const vtkTextureObject&) = delete;
801 };
802 
803 #endif
vtkTextureObject::DepthTextureCompare
bool DepthTextureCompare
Definition: vtkTextureObject.h:784
vtkTextureObject::UseSRGBColorSpace
bool UseSRGBColorSpace
Definition: vtkTextureObject.h:752
vtkTextureObject::NotEqual
Definition: vtkTextureObject.h:51
vtkTextureObject::ResourceCallback
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
Definition: vtkTextureObject.h:735
vtkTextureObject::BufferObject
vtkOpenGLBufferObject * BufferObject
Definition: vtkTextureObject.h:796
vtkTextureObject::Samples
unsigned int Samples
Definition: vtkTextureObject.h:751
vtkTextureObject::Depth
unsigned int Depth
Definition: vtkTextureObject.h:750
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkX3D::scale
Definition: vtkX3D.h:235
vtkTextureObject::NumberOfDimensions
int NumberOfDimensions
Definition: vtkTextureObject.h:747
vtkTextureObject::Create3D
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
Definition: vtkTextureObject.h:334
vtkTextureObject::SendParametersTime
vtkTimeStamp SendParametersTime
Definition: vtkTextureObject.h:790
vtkX3D::data
Definition: vtkX3D.h:321
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkTextureObject::RequireTextureFloat
bool RequireTextureFloat
Definition: vtkTextureObject.h:767
vtkTextureObject::Fixed32
Definition: vtkTextureObject.h:90
vtkTextureObject::Target
unsigned int Target
Definition: vtkTextureObject.h:756
vtkTextureObject::WrapR
int WrapR
Definition: vtkTextureObject.h:774
vtkTextureObject::MagnificationFilter
int MagnificationFilter
Definition: vtkTextureObject.h:776
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkTextureObject::GenerateMipmap
bool GenerateMipmap
Definition: vtkTextureObject.h:787
vtkTextureObject::LinearMipmapLinear
Definition: vtkTextureObject.h:79
vtkTextureObject::SupportsTextureInteger
bool SupportsTextureInteger
Definition: vtkTextureObject.h:766
vtkTextureObject::SupportsDepthBufferFloat
bool SupportsDepthBufferFloat
Definition: vtkTextureObject.h:770
vtkTextureObject::OwnHandle
bool OwnHandle
Definition: vtkTextureObject.h:764
vtkPolyData_detail::Target
Target
Definition: vtkPolyDataInternals.h:80
vtkTextureObject::GetLinearMagnification
bool GetLinearMagnification()
Definition: vtkTextureObject.h:510
vtkTextureObject::MaxLevel
int MaxLevel
Definition: vtkTextureObject.h:781
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkTextureObject::Context
vtkWeakPointer< vtkOpenGLRenderWindow > Context
Definition: vtkTextureObject.h:762
vtkTextureObject::Float32
Definition: vtkTextureObject.h:92
vtkTextureObject::Linear
Definition: vtkTextureObject.h:75
vtkTextureObject::MinificationFilter
int MinificationFilter
Definition: vtkTextureObject.h:775
vtkX3D::level
Definition: vtkX3D.h:401
vtkTextureObject::NearestMipmapNearest
Definition: vtkTextureObject.h:76
target
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:965
vtkTextureObject::GetTuples
unsigned int GetTuples()
Definition: vtkTextureObject.h:124
vtkTextureObject::RequireDepthBufferFloat
bool RequireDepthBufferFloat
Definition: vtkTextureObject.h:769
vtkTextureObject::Fixed16
Definition: vtkTextureObject.h:88
vtkTextureObject::ShaderProgram
vtkOpenGLHelper * ShaderProgram
Definition: vtkTextureObject.h:793
vtkX3D::height
Definition: vtkX3D.h:260
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:44
vtkTextureObject::IsSupported
static bool IsSupported(vtkOpenGLRenderWindow *)
Check for feature support, without any optional features.
Definition: vtkTextureObject.h:655
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:25
vtkTextureObject::NearestMipmapLinear
Definition: vtkTextureObject.h:77
vtkTextureObject::Components
int Components
Definition: vtkTextureObject.h:760
vtkOpenGLHelper
Definition: vtkOpenGLHelper.h:30
vtkTextureObject::Equal
Definition: vtkTextureObject.h:50
vtkTextureObject::RequireTextureInteger
bool RequireTextureInteger
Definition: vtkTextureObject.h:765
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkTextureObject::Width
unsigned int Width
Definition: vtkTextureObject.h:748
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWeakPointer.h
vtkTextureObject::Never
Definition: vtkTextureObject.h:53
vtkObject.h
vtkTextureObject::MaxLOD
float MaxLOD
Definition: vtkTextureObject.h:779
vtkTextureObject::LinearMipmapNearest
Definition: vtkTextureObject.h:78
vtkTextureObject::SupportsTextureFloat
bool SupportsTextureFloat
Definition: vtkTextureObject.h:768
vtkTextureObject::WrapS
int WrapS
Definition: vtkTextureObject.h:772
vtkTextureObject::Handle
unsigned int Handle
Definition: vtkTextureObject.h:763
vtkTextureObject::AutoParameters
int AutoParameters
Definition: vtkTextureObject.h:789
vtkTextureObject::AlwaysTrue
Definition: vtkTextureObject.h:52
vtkTextureObject::Gequal
Definition: vtkTextureObject.h:47
vtkTextureObject::Greater
Definition: vtkTextureObject.h:49
vtkTextureObject::Height
unsigned int Height
Definition: vtkTextureObject.h:749
vtkTextureObject::Float16
Definition: vtkTextureObject.h:91
vtkTextureObject::Format
unsigned int Format
Definition: vtkTextureObject.h:757
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:53
vtkTextureObject::Repeat
Definition: vtkTextureObject.h:60
vtkTextureObject::Create2D
bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
Create texture without uploading any data.
Definition: vtkTextureObject.h:330
vtkTextureObject::WrapT
int WrapT
Definition: vtkTextureObject.h:773
vtkTextureObject::Less
Definition: vtkTextureObject.h:48
vtkTextureObject::SetLinearMagnification
void SetLinearMagnification(bool val)
Tells if the magnification mode is linear (true) or nearest (false).
Definition: vtkTextureObject.h:508
vtkTextureObject::Fixed8
Definition: vtkTextureObject.h:87
vtkTextureObject::DepthTextureCompareFunction
int DepthTextureCompareFunction
Definition: vtkTextureObject.h:785
vtkTextureObject::Fixed24
Definition: vtkTextureObject.h:89
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkTextureObject::IsSupported
static bool IsSupported(vtkOpenGLRenderWindow *, bool, bool, bool)
Returns if the context supports the required extensions.
Definition: vtkTextureObject.h:646
vtkTextureObject::BaseLevel
int BaseLevel
Definition: vtkTextureObject.h:780
vtkTextureObject::Type
unsigned int Type
Definition: vtkTextureObject.h:759
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:43
vtkWeakPointer< vtkOpenGLRenderWindow >
vtkTextureObject::InternalFormat
unsigned int InternalFormat
Definition: vtkTextureObject.h:758
vtkTextureObject::MaximumAnisotropicFiltering
float MaximumAnisotropicFiltering
Definition: vtkTextureObject.h:754
vtkTextureObject::MinLOD
float MinLOD
Definition: vtkTextureObject.h:778