VTK  9.5.20250516
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
23VTK_ABI_NAMESPACE_BEGIN
25class vtkOpenGLHelper;
30class vtkWindow;
32
33class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkTextureObject : public vtkObject
34{
35public:
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
87 void PrintSelf(ostream& os, vtkIndent indent) override;
88
90
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
139
141
146 void Bind();
148
152 virtual void Activate();
153
158
163
168 bool IsBound();
169
177
179
183 vtkSetMacro(AutoParameters, int);
184 vtkGetMacro(AutoParameters, int);
185 vtkBooleanMacro(AutoParameters, int);
187
193 unsigned int width, unsigned int height, int numComps, int dataType, void* data);
194
202 unsigned int width, unsigned int height, int numComps, int dataType, int nbLayers, void* data);
203
210 unsigned int width, unsigned int height, int internalFormat, int rawType, void* raw);
211
217 unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
218
226 unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo);
227
234 unsigned int width, unsigned int height, int numComps, int dataType, void* data[6]);
235
246 bool Create1D(int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
247
251 bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data);
252
259 bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject* pbo,
260 bool shaderSupportsTextureInt);
261
268 bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps,
269 vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt);
270
275 bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps,
276 int dataType, void* data);
277
285 unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType);
286
294 vtkPixelBufferObject* Download(unsigned int target, unsigned int level);
295
301 unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject* pbo);
302
306 bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat);
307
311 bool AllocateDepthStencil(unsigned int width, unsigned int height);
312
317 bool Allocate1D(unsigned int width, int numComps, int vtkType);
318
324 unsigned int width, unsigned int height, int numComps, int vtkType, int level = 0);
325
331 unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType);
332
334
337 bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool)
338 {
339 return this->Allocate2D(width, height, numComps, vtktype);
340 }
342 unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool)
343 {
344 return this->Allocate3D(width, height, depth, numComps, vtktype);
345 }
347
352
354
357 int GetDataType(int vtk_scalar_type);
358 void SetDataType(unsigned int glType);
359 int GetDefaultDataType(int vtk_scalar_type);
361
363
368 unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
369 void SetInternalFormat(unsigned int glInternalFormat);
370 unsigned int GetDefaultInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
372
374
379 unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
380 void SetFormat(unsigned int glFormat);
381 unsigned int GetDefaultFormat(int vtktype, int numComps, bool shaderSupportsTextureInt);
383
393
394 unsigned int GetMinificationFilterMode(int vtktype);
395 unsigned int GetMagnificationFilterMode(int vtktype);
396 unsigned int GetWrapSMode(int vtktype);
397 unsigned int GetWrapTMode(int vtktype);
398 unsigned int GetWrapRMode(int vtktype);
399
401
407 vtkSetMacro(RequireDepthBufferFloat, bool);
408 vtkGetMacro(RequireDepthBufferFloat, bool);
409 vtkGetMacro(SupportsDepthBufferFloat, bool);
411
413
419 vtkSetMacro(RequireTextureFloat, bool);
420 vtkGetMacro(RequireTextureFloat, bool);
421 vtkGetMacro(SupportsTextureFloat, bool);
423
425
431 vtkSetMacro(RequireTextureInteger, bool);
432 vtkGetMacro(RequireTextureInteger, bool);
433 vtkGetMacro(SupportsTextureInteger, bool);
435
437
447 vtkGetMacro(WrapS, int);
448 vtkSetMacro(WrapS, int);
450
452
462 vtkGetMacro(WrapT, int);
463 vtkSetMacro(WrapT, int);
465
467
477 vtkGetMacro(WrapR, int);
478 vtkSetMacro(WrapR, int);
480
482
495 vtkGetMacro(MinificationFilter, int);
496 vtkSetMacro(MinificationFilter, int);
498
500
507 vtkGetMacro(MagnificationFilter, int);
508 vtkSetMacro(MagnificationFilter, int);
510
515 void SetLinearMagnification(bool val) { this->SetMagnificationFilter(val ? Linear : Nearest); }
516
517 bool GetLinearMagnification() { return this->MagnificationFilter == Linear; }
518
520
525 vtkSetVector4Macro(BorderColor, float);
526 vtkGetVector4Macro(BorderColor, float);
528
530
534 vtkSetMacro(MinLOD, float);
535 vtkGetMacro(MinLOD, float);
537
539
543 vtkSetMacro(MaxLOD, float);
544 vtkGetMacro(MaxLOD, float);
546
548
553 vtkSetMacro(BaseLevel, int);
554 vtkGetMacro(BaseLevel, int);
556
558
563 vtkSetMacro(MaxLevel, int);
564 vtkGetMacro(MaxLevel, int);
566
568
578 vtkGetMacro(DepthTextureCompare, bool);
579 vtkSetMacro(DepthTextureCompare, bool);
581
583
603 vtkGetMacro(DepthTextureCompareFunction, int);
604 vtkSetMacro(DepthTextureCompareFunction, int);
606
608
613 vtkGetMacro(GenerateMipmap, bool);
614 vtkSetMacro(GenerateMipmap, bool);
616
618
623 vtkSetMacro(MaximumAnisotropicFiltering, float);
624 vtkGetMacro(MaximumAnisotropicFiltering, float);
626
628
639
647
653 static bool IsSupported(vtkOpenGLRenderWindow* renWin, bool requireTexFloat,
654 bool requireDepthFloat, bool requireTexInt);
655
660 {
661 return vtkTextureObject::IsSupported(renWin, false, false, false);
662 }
663
665
671 // part of a texture to part of a viewport, scaling as needed
672 void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
673 int dstYmin, int dstXmax, int dstYmax, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
675 // copy part of a texture to part of a viewport, no scalaing
676 void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin,
677 int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram* program,
679 // copy a texture to a quad using the provided tcoords and verts
681 float* tcoords, float* verts, vtkShaderProgram* program, vtkOpenGLVertexArrayObject* vao);
683
696 int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height);
697
710 void GetShiftAndScale(float& shift, float& scale);
711
712 // resizes an existing texture, any existing
713 // data values are lost
714 void Resize(unsigned int width, unsigned int height);
715
717
723 vtkGetMacro(UseSRGBColorSpace, bool);
724 vtkSetMacro(UseSRGBColorSpace, bool);
725 vtkBooleanMacro(UseSRGBColorSpace, bool);
727
736 void AssignToExistingTexture(unsigned int handle, unsigned int target);
737
738protected:
741
743
748
753
758
760 unsigned int Width;
761 unsigned int Height;
762 unsigned int Depth;
763 unsigned int Samples;
765
767
768 unsigned int Target; // GLenum
769 unsigned int Format; // GLenum
770 unsigned int InternalFormat; // GLenum
771 unsigned int Type; // GLenum
773
775 unsigned int Handle;
783
784 int WrapS;
785 int WrapT;
786 int WrapR;
789
790 float MinLOD;
791 float MaxLOD;
794 float BorderColor[4];
795
798
800
803
804 // used for copying to framebuffer
806
807 // for texturebuffers we hold on to the Buffer
809
810private:
811 vtkTextureObject(const vtkTextureObject&) = delete;
812 void operator=(const vtkTextureObject&) = delete;
813};
814
815VTK_ABI_NAMESPACE_END
816#endif
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
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.
static bool IsSupported(vtkOpenGLRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
unsigned int InternalFormat
bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat)
Create a 2D depth texture but does not initialize its values.
void SetContext(vtkOpenGLRenderWindow *)
Get/Set the context.
bool AllocateProxyTexture3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType)
Create a 3D texture using the GL_PROXY_TEXTURE_3D target.
bool EmulateTextureBufferWith2DTextures(unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject *bo)
Emulates a texture buffer with 2D texture.
bool AllocateDepthStencil(unsigned int width, unsigned int height)
Create a 2D septh stencil texture but does not initialize its values.
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.
bool Create2DArrayFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, int nbLayers, void *data)
Create a 2D texture array from client memory data contains a pointer to the layers of the texture arr...
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.
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).
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.
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.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Check for feature support, without any optional features.
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.
unsigned int GetTuples()
Get the texture dimensions.
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.
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.
bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
Load all necessary extensions.
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
a weak reference to a vtkObject.
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_MARSHALAUTO