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=========================================================================*/
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
54class vtkOpenGLHelper;
59class vtkWindow;
61
62class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
63{
64public:
65 // DepthTextureCompareFunction values.
66 enum
67 {
68 Lequal = 0, // r=R<=Dt ? 1.0 : 0.0
69 Gequal, // r=R>=Dt ? 1.0 : 0.0
70 Less, // r=R<D_t ? 1.0 : 0.0
71 Greater, // r=R>Dt ? 1.0 : 0.0
72 Equal, // r=R==Dt ? 1.0 : 0.0
73 NotEqual, // r=R!=Dt ? 1.0 : 0.0
74 AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
75 Never, // r=0.0
76 NumberOfDepthTextureCompareFunctions
77 };
78
79// ClampToBorder is not supported in ES 2.0
80// Wrap values.
81#ifndef GL_ES_VERSION_3_0
82 enum { ClampToEdge = 0, Repeat, MirroredRepeat, ClampToBorder, NumberOfWrapModes };
83#else
84 enum
85 {
86 ClampToEdge = 0,
87 Repeat,
88 MirroredRepeat,
89 NumberOfWrapModes
90 };
91#endif
92
93 // MinificationFilter values.
94 enum
95 {
96 Nearest = 0,
102 NumberOfMinificationModes
103 };
104
105 // depth/color format
106 enum
107 {
108 Native = 0, // will try to match with the depth buffer format.
115 NumberOfDepthFormats
116 };
117
120 void PrintSelf(ostream& os, vtkIndent indent) override;
121
123
135
137
141 vtkGetMacro(Width, unsigned int);
142 vtkGetMacro(Height, unsigned int);
143 vtkGetMacro(Depth, unsigned int);
144 vtkGetMacro(Samples, unsigned int);
145 vtkGetMacro(Components, int);
146 unsigned int GetTuples() { return this->Width * this->Height * this->Depth; }
148
149 vtkGetMacro(NumberOfDimensions, int);
150
151 // for MSAA textures set the number of samples
152 vtkSetMacro(Samples, unsigned int);
153
155
158 vtkGetMacro(Target, unsigned int);
160
162
165 vtkGetMacro(Handle, unsigned int);
167
172
174
179 void Bind();
181
185 virtual void Activate();
186
191
196
201 bool IsBound();
202
210
212
216 vtkSetMacro(AutoParameters, int);
217 vtkGetMacro(AutoParameters, int);
218 vtkBooleanMacro(AutoParameters, int);
220
226 unsigned int width, unsigned int height, int numComps, int dataType, void* data);
227
234 unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
235
241 unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
242
249 unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
250
261 bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
262
266 bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
267
274 bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
275 bool shaderSupportsTextureInt);
276
283 bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
284 vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
285
290 bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
291 int dataType, void* data);
292
299 bool AllocateProxyTexture3D(unsigned int const width, unsigned int const height,
300 unsigned int const depth, int const numComps, int const dataType);
301
309 vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
310
316 unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
317
321 bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
322
326 bool AllocateDepthStencil(unsigned int width, unsigned int height);
327
332 bool Allocate1D(unsigned int width, int numComps, int vtkType);
333
339 unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
340
346 unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
347
349
352 bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
353 {
354 return this->Allocate2D(width, height, numComps, vtktype);
355 }
357 unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
358 {
359 return this->Allocate3D(width, height, depth, numComps, vtktype);
360 }
362
367
369
372 int GetDataType(int vtk_scalar_type);
373 void SetDataType(unsigned int glType);
374 int GetDefaultDataType(int vtk_scalar_type);
376
378
383 unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
384 void SetInternalFormat(unsigned int glInternalFormat);
385 unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
387
389
394 unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
395 void SetFormat(unsigned int glFormat);
396 unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
398
408
409 unsigned int GetMinificationFilterMode(int vtktype);
410 unsigned int GetMagnificationFilterMode(int vtktype);
411 unsigned int GetWrapSMode(int vtktype);
412 unsigned int GetWrapTMode(int vtktype);
413 unsigned int GetWrapRMode(int vtktype);
414
416
422 vtkSetMacro(RequireDepthBufferFloat, bool);
423 vtkGetMacro(RequireDepthBufferFloat, bool);
424 vtkGetMacro(SupportsDepthBufferFloat, bool);
426
428
434 vtkSetMacro(RequireTextureFloat, bool);
435 vtkGetMacro(RequireTextureFloat, bool);
436 vtkGetMacro(SupportsTextureFloat, bool);
438
440
446 vtkSetMacro(RequireTextureInteger, bool);
447 vtkGetMacro(RequireTextureInteger, bool);
448 vtkGetMacro(SupportsTextureInteger, bool);
450
452
462 vtkGetMacro(WrapS, int);
463 vtkSetMacro(WrapS, int);
465
467
477 vtkGetMacro(WrapT, int);
478 vtkSetMacro(WrapT, int);
480
482
492 vtkGetMacro(WrapR, int);
493 vtkSetMacro(WrapR, int);
495
497
510 vtkGetMacro(MinificationFilter, int);
511 vtkSetMacro(MinificationFilter, int);
513
515
522 vtkGetMacro(MagnificationFilter, int);
523 vtkSetMacro(MagnificationFilter, int);
525
530 void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
531
532 bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
533
535
540 vtkSetVector4Macro(BorderColor, float);
541 vtkGetVector4Macro(BorderColor, float);
543
545
549 vtkSetMacro(MinLOD, float);
550 vtkGetMacro(MinLOD, float);
552
554
558 vtkSetMacro(MaxLOD, float);
559 vtkGetMacro(MaxLOD, float);
561
563
568 vtkSetMacro(BaseLevel, int);
569 vtkGetMacro(BaseLevel, int);
571
573
578 vtkSetMacro(MaxLevel, int);
579 vtkGetMacro(MaxLevel, int);
581
583
593 vtkGetMacro(DepthTextureCompare, bool);
594 vtkSetMacro(DepthTextureCompare, bool);
596
598
618 vtkGetMacro(DepthTextureCompareFunction, int);
619 vtkSetMacro(DepthTextureCompareFunction, int);
621
623
628 vtkGetMacro(GenerateMipmap, bool);
629 vtkSetMacro(GenerateMipmap, bool);
631
633
638 vtkSetMacro(MaximumAnisotropicFiltering, float);
639 vtkGetMacro(MaximumAnisotropicFiltering, float);
641
643
654
662
668 static bool IsSupported(vtkOpenGLRenderWindow*, bool /* requireTexFloat */,
669 bool /* requireDepthFloat */, bool /* requireTexInt */)
670 {
671 return true;
672 }
673
677 static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
678
680
686 // part of a texture to part of a viewport, scaling as needed
687 void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
688 int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
690 // copy part of a texture to part of a viewport, no scalaing
691 void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
692 int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
694 // copy a texture to a quad using the provided tcoords and verts
696 float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
698
711 int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
712
725 void GetShiftAndScale(float& shift, float& scale);
726
727 // resizes an existing texture, any existing
728 // data values are lost
729 void Resize(unsigned int width, unsigned int height);
730
732
738 vtkGetMacro(UseSRGBColorSpace, bool);
739 vtkSetMacro(UseSRGBColorSpace, bool);
740 vtkBooleanMacro(UseSRGBColorSpace, bool);
742
751 void AssignToExistingTexture(unsigned int handle, unsigned int target);
752
753protected:
756
758
763
768
770 unsigned int Width;
771 unsigned int Height;
772 unsigned int Depth;
773 unsigned int Samples;
775
777
778 unsigned int Target; // GLenum
779 unsigned int Format; // GLenum
780 unsigned int InternalFormat; // GLenum
781 unsigned int Type; // GLenum
783
785 unsigned int Handle;
793
794 int WrapS;
795 int WrapT;
796 int WrapR;
799
800 float MinLOD;
801 float MaxLOD;
804 float BorderColor[4];
805
808
810
813
814 // used for copying to framebuffer
816
817 // for texturebuffers we hold on to the Buffer
819
820private:
821 vtkTextureObject(const vtkTextureObject&) = delete;
822 void operator=(const vtkTextureObject&) = delete;
823};
824
825#endif
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:79
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].
vtkOpenGLRenderWindow * GetContext()
Get/Set the context.
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...
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.
unsigned int Height
static vtkTextureObject * New()
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.
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.
vtkPixelBufferObject * Download(unsigned int target, unsigned int level)
record modification and/or execution time
Definition: vtkTimeStamp.h:55
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
@ level
Definition: vtkX3D.h:401
@ scale
Definition: vtkX3D.h:235
@ height
Definition: vtkX3D.h:260
@ data
Definition: vtkX3D.h:321
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)