VTK
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 =========================================================================*/
23 #ifndef vtkTextureObject_h
24 #define vtkTextureObject_h
25 
26 #include "vtkRenderingOpenGL2Module.h" // For export macro
27 #include "vtkObject.h"
28 #include "vtkWeakPointer.h" // for render context
29 
31 class vtkOpenGLHelper;
34 class vtkShaderProgram;
35 class vtkWindow;
36 
37 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
39 #endif
40 
41 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
42 {
43 public:
44 
45  // DepthTextureCompareFunction values.
46  enum
47  {
48  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
49  Gequal, // r=R>=Dt ? 1.0 : 0.0
50  Less, // r=R<D_t ? 1.0 : 0.0
51  Greater, // r=R>Dt ? 1.0 : 0.0
52  Equal, // r=R==Dt ? 1.0 : 0.0
53  NotEqual, // r=R!=Dt ? 1.0 : 0.0
54  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
55  Never, // r=0.0
56  NumberOfDepthTextureCompareFunctions
57  };
58 
59 // ClampToBorder is not supported in ES 2.0
60 // Wrap values.
61 #if GL_ES_VERSION_2_0 != 1
62  enum
63  {
64  ClampToEdge=0,
65  Repeat,
66  MirroredRepeat,
67  ClampToBorder,
68  NumberOfWrapModes
69  };
70 #else
71  enum
72  {
73  ClampToEdge=0,
74  Repeat,
75  MirroredRepeat,
76  NumberOfWrapModes
77  };
78 #endif
79 
80  // MinificationFilter values.
81  enum
82  {
83  Nearest=0,
84  Linear,
85  NearestMipmapNearest,
86  NearestMipmapLinear,
87  LinearMipmapNearest,
88  LinearMipmapLinear,
89  NumberOfMinificationModes
90  };
91 
92  // Internal depth format
93  enum
94  {
95  Native=0, // will try to match with the depth buffer format.
96  Fixed16,
97  Fixed24,
98  Fixed32,
99  Float32,
100  NumberOfDepthFormats
101  };
102 
103  // Internal alpha format
104  enum
105  {
106  alpha=0,
111  NumberOfAlphaFormats
112  };
113 
114  // Depth mode formats
115  enum
116  {
117  DepthAlpha=0,
120  NumberOfDepthModeFormats
121  };
122 
125  void PrintSelf(ostream& os, vtkIndent indent);
126 
128 
135 
137 
139  vtkGetMacro(Width, unsigned int);
140  vtkGetMacro(Height, unsigned int);
141  vtkGetMacro(Depth, unsigned int);
142  vtkGetMacro(Components, int);
143  unsigned int GetTuples()
144  { return this->Width*this->Height*this->Depth; }
146 
147  vtkGetMacro(NumberOfDimensions, int);
148 
150 
151  vtkGetMacro(Target, unsigned int);
153 
155 
156  vtkGetMacro(Handle, unsigned int);
158 
161 
163 
166  void Bind();
167  void UnBind();
169 
171  void Activate();
172 
174  void Deactivate();
175 
178 
181  bool IsBound();
182 
184 
188  vtkSetMacro(AutoParameters, int);
189  vtkGetMacro(AutoParameters, int);
191 
193 
194  bool Create2DFromRaw(unsigned int width, unsigned int height,
195  int numComps, int dataType, void *data);
197 
199 
201  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
202  int internalFormat, int rawType,
203  void *raw);
205 
207 
209  bool CreateTextureBuffer(unsigned int numValues, int numComps,
210  int dataType, vtkOpenGLBufferObject *bo);
212 
213 // 1D textures are not supported in ES 2.0 or 3.0
214 #if GL_ES_VERSION_2_0 != 1
215 
217 
224  bool Create1D(int numComps,
226  bool shaderSupportsTextureInt);
228 
230 
231  bool Create1DFromRaw(unsigned int width, int numComps,
232  int dataType, void *data);
234 
235 
237  bool CreateAlphaFromRaw(unsigned int width,
238  int internalFormat,
239  int rawType,
240  void *raw);
241 #endif
242 
243 
244 // PBO's, and 3D textures are not supported in ES 2.0
245 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
246 
248 
251  bool Create2D(unsigned int width, unsigned int height, int numComps,
253  bool shaderSupportsTextureInt);
255 
257 
260  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
261  int numComps, vtkPixelBufferObject *pbo,
262  bool shaderSupportsTextureInt);
264 
266 
267  bool Create3DFromRaw(unsigned int width, unsigned int height,
268  unsigned int depth, int numComps,
269  int dataType, void *data);
271 
277 
279 
281  bool CreateDepth(unsigned int width,
282  unsigned int height,
283  int internalFormat,
284  vtkPixelBufferObject *pbo);
286 
287 #endif
288 
290 
291  bool AllocateDepth(unsigned int width,unsigned int height,
292  int internalFormat);
294 
297  bool Allocate1D(unsigned int width, int numComps,int vtkType);
298 
300 
302  bool Allocate2D(unsigned int width,unsigned int height, int numComps,
303  int vtkType);
305 
307 
309  bool Allocate3D(unsigned int width,unsigned int height,
310  unsigned int depth, int numComps,
311  int vtkType);
313 
314 
316 
317  bool Create2D(unsigned int width, unsigned int height, int numComps,
318  int vtktype, bool shaderSupportsTextureInt);
319  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
320  int numComps, int vtktype, bool shaderSupportsTextureInt);
322 
325 
327 
328  int GetDataType(int vtk_scalar_type);
329  void SetDataType(unsigned int glType);
331 
333 
335  unsigned int GetInternalFormat(int vtktype, int numComps,
336  bool shaderSupportsTextureInt);
337  void SetInternalFormat(unsigned int glInternalFormat);
339 
341 
343  unsigned int GetFormat(int vtktype, int numComps,
344  bool shaderSupportsTextureInt);
345  void SetFormat(unsigned int glFormat);
347 
353 
354  unsigned int GetDepthTextureModeFormat(int vtktype);
355  unsigned int GetMinificationFilterMode(int vtktype);
356  unsigned int GetMagnificationFilterMode(int vtktype);
357  unsigned int GetWrapSMode(int vtktype);
358  unsigned int GetWrapTMode(int vtktype);
359  unsigned int GetWrapRMode(int vtktype);
360 
362 
365  vtkSetMacro(RequireDepthBufferFloat, bool);
366  vtkGetMacro(RequireDepthBufferFloat, bool);
367  vtkGetMacro(SupportsDepthBufferFloat, bool);
369 
371 
374  vtkSetMacro(RequireTextureFloat,bool);
375  vtkGetMacro(RequireTextureFloat,bool);
376  vtkGetMacro(SupportsTextureFloat,bool);
378 
380 
383  vtkSetMacro(RequireTextureInteger,bool);
384  vtkGetMacro(RequireTextureInteger,bool);
385  vtkGetMacro(SupportsTextureInteger,bool);
387 
389 
392  vtkGetMacro(WrapS,int);
393  vtkSetMacro(WrapS,int);
395 
397 
400  vtkGetMacro(WrapT,int);
401  vtkSetMacro(WrapT,int);
403 
405 
408  vtkGetMacro(WrapR,int);
409  vtkSetMacro(WrapR,int);
411 
413 
418  vtkGetMacro(MinificationFilter,int);
419  vtkSetMacro(MinificationFilter,int);
421 
423 
425  vtkGetMacro(MagnificationFilter,int);
426  vtkSetMacro(MagnificationFilter,int);
428 
430 
433  { this->SetMagnificationFilter(val?Linear:Nearest); }
435 
437  { return this->MagnificationFilter==Linear; }
438 
440 
443  vtkSetVector4Macro(BorderColor,float);
444  vtkGetVector4Macro(BorderColor,float);
446 
448 
450  vtkSetMacro(MinLOD,float);
451  vtkGetMacro(MinLOD,float);
453 
455 
457  vtkSetMacro(MaxLOD,float);
458  vtkGetMacro(MaxLOD,float);
460 
462 
465  vtkSetMacro(BaseLevel,int);
466  vtkGetMacro(BaseLevel,int);
468 
470 
473  vtkSetMacro(MaxLevel,int);
474  vtkGetMacro(MaxLevel,int);
476 
478 
484  vtkGetMacro(DepthTextureCompare,bool);
485  vtkSetMacro(DepthTextureCompare,bool);
487 
489 
499  vtkGetMacro(DepthTextureCompareFunction,int);
500  vtkSetMacro(DepthTextureCompareFunction,int);
502 
504 
509 
511 
514  static bool IsSupported(
515  vtkOpenGLRenderWindow* renWin,
516  bool requireTexFloat,
517  bool requireDepthFloat,
518  bool requireTexInt);
520 
522 
523  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
524  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
526 
528 
533  // part of a texture to part of a viewport, scaling as needed
534  void CopyToFrameBuffer(int srcXmin, int srcYmin,
535  int srcXmax, int srcYmax,
536  int dstXmin, int dstYmin,
537  int dstXmax, int dstYmax,
538  int dstSizeX, int dstSizeY,
541  );
542  // copy part of a texure to part of a viewport, no scalaing
543  void CopyToFrameBuffer(int srcXmin, int srcYmin,
544  int srcXmax, int srcYmax,
545  int dstXmin, int dstYmin,
546  int dstSizeX, int dstSizeY,
549  );
550  // copy a texture to a quad using the provided tcoords and verts
551  void CopyToFrameBuffer(float *tcoords, float *verts,
554  );
556 
557 
559 
567  void CopyFromFrameBuffer(int srcXmin,
568  int srcYmin,
569  int dstXmin,
570  int dstYmin,
571  int width,
572  int height);
574 
575 
576 
577 protected:
580 
583 
586 
589 
590  int NumberOfDimensions;
591  unsigned int Width;
592  unsigned int Height;
593  unsigned int Depth;
594 
595  unsigned int Target; // GLenum
596  unsigned int Format; // GLenum
597  unsigned int InternalFormat; // GLenum
598  unsigned int Type; // GLenum
599  int Components;
600 
602  unsigned int Handle;
603  bool RequireTextureInteger;
604  bool SupportsTextureInteger;
605  bool RequireTextureFloat;
606  bool SupportsTextureFloat;
607  bool RequireDepthBufferFloat;
608  bool SupportsDepthBufferFloat;
609 
610  int WrapS;
611  int WrapT;
612  int WrapR;
613  int MinificationFilter;
614  int MagnificationFilter;
615  bool LinearMagnification;
616 
617  float MinLOD;
618  float MaxLOD;
619  int BaseLevel;
620  int MaxLevel;
621  float BorderColor[4];
622 
623  bool DepthTextureCompare;
624  int DepthTextureCompareFunction;
625 
626  bool GenerateMipmap;
627 
628  int AutoParameters;
629  vtkTimeStamp SendParametersTime;
630 
631  // used for copying to framebuffer
633 
634  // for texturebuffers we hold on to the Buffer
636 
637 private:
638  vtkTextureObject(const vtkTextureObject&); // Not implemented.
639  void operator=(const vtkTextureObject&); // Not implemented.
640 };
641 
642 #endif
vtkTextureObject::Allocate2D
bool Allocate2D(unsigned int width, unsigned int height, int numComps, int vtkType)
vtkTextureObject::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *win)
vtkTextureObject::CopyToFrameBuffer
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)
vtkgl::data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
vtkTextureObject::Create3DFromRaw
bool Create3DFromRaw(unsigned int width, unsigned int height, unsigned int depth, int numComps, int dataType, void *data)
vtkTextureObject::Create1D
bool Create1D(int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
vtkTextureObject::BufferObject
vtkOpenGLBufferObject * BufferObject
Definition: vtkTextureObject.h:635
vtkTextureObject::Create3D
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtktype, bool shaderSupportsTextureInt)
vtkTextureObject::CopyToFrameBuffer
void CopyToFrameBuffer(int srcXmin, int srcYmin, int srcXmax, int srcYmax, int dstXmin, int dstYmin, int dstSizeX, int dstSizeY, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
vtkTextureObject::CopyToFrameBuffer
void CopyToFrameBuffer(float *tcoords, float *verts, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkTextureObject::CreateTextureBuffer
bool CreateTextureBuffer(unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject *bo)
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkTextureObject::Download
vtkPixelBufferObject * Download()
vtkgl::GenerateMipmap
VTKRENDERINGOPENGL_EXPORT PFNGLGENERATEMIPMAPPROC GenerateMipmap
vtkTextureObject::LoadRequiredExtensions
bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkTextureObject::SetFormat
void SetFormat(unsigned int glFormat)
vtkTextureObject::alpha32f
@ alpha32f
Definition: vtkTextureObject.h:110
vtkTextureObject::SetContext
void SetContext(vtkOpenGLRenderWindow *)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkTextureObject::SetInternalFormat
void SetInternalFormat(unsigned int glInternalFormat)
vtkTextureObject::GetFormat
unsigned int GetFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
vtkTextureObject::AllocateDepth
bool AllocateDepth(unsigned int width, unsigned int height, int internalFormat)
vtkTextureObject::GetVTKDataType
int GetVTKDataType()
vtkTextureObject::GetLinearMagnification
bool GetLinearMagnification()
Definition: vtkTextureObject.h:436
vtkTextureObject::vtkTextureObject
vtkTextureObject()
vtkTextureObject::GetTextureUnit
int GetTextureUnit()
vtkgl::program
GLuint program
Definition: vtkgl.h:13011
vtkTextureObject::alpha16
@ alpha16
Definition: vtkTextureObject.h:108
vtkTextureObject::CreateDepth
bool CreateDepth(unsigned int width, unsigned int height, int internalFormat, vtkPixelBufferObject *pbo)
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkTextureObject::Context
vtkWeakPointer< vtkOpenGLRenderWindow > Context
Definition: vtkTextureObject.h:601
vtkTextureObject::GetInternalFormat
unsigned int GetInternalFormat(int vtktype, int numComps, bool shaderSupportsTextureInt)
vtkgl::val
GLuint GLfloat * val
Definition: vtkgl.h:13789
vtkTextureObject::GetMinificationFilterMode
unsigned int GetMinificationFilterMode(int vtktype)
vtkTextureObject::GetMagnificationFilterMode
unsigned int GetMagnificationFilterMode(int vtktype)
vtkgl::depth
GLint GLint GLsizei GLsizei GLsizei depth
Definition: vtkgl.h:11316
vtkTextureObject::GetTuples
unsigned int GetTuples()
Definition: vtkTextureObject.h:143
vtkTextureObject::CreateTexture
void CreateTexture()
vtkTextureObject::ShaderProgram
vtkOpenGLHelper * ShaderProgram
Definition: vtkTextureObject.h:632
vtkTextureObject::GetWrapRMode
unsigned int GetWrapRMode(int vtktype)
vtkTextureObject::IsSupported
static bool IsSupported(vtkOpenGLRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:43
vtkOpenGLHelper
Definition: vtkOpenGLHelper.h:31
vtkTextureObject::Deactivate
void Deactivate()
vtkTextureObject::Create2D
bool Create2D(unsigned int width, unsigned int height, int numComps, int vtktype, bool shaderSupportsTextureInt)
vtkTextureObject::alpha8
@ alpha8
Definition: vtkTextureObject.h:107
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkTextureObject::~vtkTextureObject
~vtkTextureObject()
vtkTextureObject::New
static vtkTextureObject * New()
vtkTextureObject::CopyFromFrameBuffer
void CopyFromFrameBuffer(int srcXmin, int srcYmin, int dstXmin, int dstYmin, int width, int height)
vtkTextureObject::Create3D
bool Create3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
vtkTextureObject::CreateAlphaFromRaw
bool CreateAlphaFromRaw(unsigned int width, int internalFormat, int rawType, void *raw)
vtkWeakPointer.h
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkTextureObject::ResetFormatAndType
void ResetFormatAndType()
vtkTextureObject::GetContext
vtkOpenGLRenderWindow * GetContext()
vtkTextureObject::Allocate1D
bool Allocate1D(unsigned int width, int numComps, int vtkType)
vtkTextureObject::SetDataType
void SetDataType(unsigned int glType)
vtkObject.h
vtkTextureObject::SendParameters
void SendParameters()
vtkTextureObject::DepthLuminance
@ DepthLuminance
Definition: vtkTextureObject.h:118
vtkgl::width
GLint GLint GLsizei width
Definition: vtkgl.h:11316
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkgl::alpha
GLclampf GLclampf GLclampf alpha
Definition: vtkgl.h:11313
vtkSetVector4Macro
#define vtkSetVector4Macro(name, type)
Definition: vtkSetGet.h:322
vtkTextureObject::Allocate3D
bool Allocate3D(unsigned int width, unsigned int height, unsigned int depth, int numComps, int vtkType)
vtkTextureObject::Create2D
bool Create2D(unsigned int width, unsigned int height, int numComps, vtkPixelBufferObject *pbo, bool shaderSupportsTextureInt)
vtkTextureObject::Create1DFromRaw
bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void *data)
vtkTextureObject::alpha16f
@ alpha16f
Definition: vtkTextureObject.h:109
vtkTextureObject::DepthIntensity
@ DepthIntensity
Definition: vtkTextureObject.h:119
vtkTextureObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkgl::internalFormat
GLenum internalFormat
Definition: vtkgl.h:15195
vtkTextureObject::IsBound
bool IsBound()
vtkTextureObject::GetDataType
int GetDataType(int vtk_scalar_type)
vtkTextureObject::GetDepthTextureModeFormat
unsigned int GetDepthTextureModeFormat(int vtktype)
vtkTextureObject::CopyToFrameBuffer
void CopyToFrameBuffer(vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
vtkTextureObject::GetWrapSMode
unsigned int GetWrapSMode(int vtktype)
vtkTextureObject::CreateDepthFromRaw
bool CreateDepthFromRaw(unsigned int width, unsigned int height, int internalFormat, int rawType, void *raw)
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:41
vtkTextureObject::Bind
void Bind()
vtkTextureObject::UnBind
void UnBind()
vtkTextureObject::GetWrapTMode
unsigned int GetWrapTMode(int vtktype)
vtkTextureObject::Create2DFromRaw
bool Create2DFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data)
vtkTextureObject::IsSupported
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Definition: vtkTextureObject.h:523
vtkTextureObject::SetLinearMagnification
void SetLinearMagnification(bool val)
Definition: vtkTextureObject.h:432
vtkGetVector4Macro
#define vtkGetVector4Macro(name, type)
Definition: vtkSetGet.h:341
vtkTextureObject::DestroyTexture
void DestroyTexture()
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:43
vtkTextureObject::Activate
void Activate()
vtkWeakPointer< vtkOpenGLRenderWindow >
vtkTextureObject::InternalFormat
unsigned int InternalFormat
Definition: vtkTextureObject.h:597
vtkgl::height
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
vtkTextureObject::IsSupported
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)