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 
30 class vtkWindow;
31 class vtkShaderProgram;
33 namespace vtkgl
34 {
35 class VertexArrayObject;
36 class CellBO;
37 }
38 
39 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
41 #endif
42 
43 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
44 {
45 public:
46 
47  // DepthTextureCompareFunction values.
48  enum
49  {
50  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
51  Gequal, // r=R>=Dt ? 1.0 : 0.0
52  Less, // r=R<D_t ? 1.0 : 0.0
53  Greater, // r=R>Dt ? 1.0 : 0.0
54  Equal, // r=R==Dt ? 1.0 : 0.0
55  NotEqual, // r=R!=Dt ? 1.0 : 0.0
56  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
57  Never, // r=0.0
58  NumberOfDepthTextureCompareFunctions
59  };
60 
61 // ClampToBorder is not supported in ES 2.0
62 // Wrap values.
63 #if GL_ES_VERSION_2_0 != 1
64  enum
65  {
66  ClampToEdge=0,
67  Repeat,
68  MirroredRepeat,
69  ClampToBorder,
70  NumberOfWrapModes
71  };
72 #else
73  enum
74  {
75  ClampToEdge=0,
76  Repeat,
77  MirroredRepeat,
78  NumberOfWrapModes
79  };
80 #endif
81 
82  // MinificationFilter values.
83  enum
84  {
85  Nearest=0,
86  Linear,
87  NearestMipmapNearest,
88  NearestMipmapLinear,
89  LinearMipmapNearest,
90  LinearMipmapLinear,
91  NumberOfMinificationModes
92  };
93 
94  // Internal depth format
95  enum
96  {
97  Native=0, // will try to match with the depth buffer format.
98  Fixed16,
99  Fixed24,
100  Fixed32,
101  Float32,
102  NumberOfDepthFormats
103  };
104 
105  // Internal alpha format
106  enum
107  {
108  alpha=0,
113  NumberOfAlphaFormats
114  };
115 
116  // Depth mode formats
117  enum
118  {
119  DepthAlpha=0,
122  NumberOfDepthModeFormats
123  };
124 
125  static vtkTextureObject* New();
127  void PrintSelf(ostream& os, vtkIndent indent);
128 
130 
134  void SetContext(vtkOpenGLRenderWindow*);
135  vtkOpenGLRenderWindow* GetContext();
137 
139 
141  vtkGetMacro(Width, unsigned int);
142  vtkGetMacro(Height, unsigned int);
143  vtkGetMacro(Depth, unsigned int);
144  vtkGetMacro(Components, int);
145  unsigned int GetTuples()
146  { return this->Width*this->Height*this->Depth; }
148 
149  vtkGetMacro(NumberOfDimensions, int);
150 
152 
153  vtkGetMacro(Target, unsigned int);
155 
157 
158  vtkGetMacro(Handle, unsigned int);
160 
162  int GetTextureUnit();
163 
165 
168  void Bind();
169  void UnBind();
171 
173  void Activate();
174 
176  void Deactivate();
177 
179  void ReleaseGraphicsResources(vtkWindow *win);
180 
183  bool IsBound();
184 
186 
189  void SendParameters();
190  vtkSetMacro(AutoParameters, int);
191  vtkGetMacro(AutoParameters, int);
193 
195 
196  bool Create2DFromRaw(unsigned int width, unsigned int height,
197  int numComps, int dataType, void *data);
199 
201 
203  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
204  int internalFormat, int rawType,
205  void *raw);
207 
208 // 1D textures are not supported in ES 2.0 or 3.0
209 #if GL_ES_VERSION_2_0 != 1
210 
212 
219  bool Create1D(int numComps,
221  bool shaderSupportsTextureInt);
223 
225 
226  bool Create1DFromRaw(unsigned int width, int numComps,
227  int dataType, void *data);
229 
230 
232  bool CreateAlphaFromRaw(unsigned int width,
233  int internalFormat,
234  int rawType,
235  void *raw);
236 #endif
237 
238 
239 // PBO's, and 3D textures are not supported in ES 2.0
240 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
241 
243 
246  bool Create2D(unsigned int width, unsigned int height, int numComps,
248  bool shaderSupportsTextureInt);
250 
252 
255  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
256  int numComps, vtkPixelBufferObject *pbo,
257  bool shaderSupportsTextureInt);
259 
261 
262  bool Create3DFromRaw(unsigned int width, unsigned int height,
263  unsigned int depth, int numComps,
264  int dataType, void *data);
266 
271  vtkPixelBufferObject* Download();
272 
274 
276  bool CreateDepth(unsigned int width,
277  unsigned int height,
278  int internalFormat,
279  vtkPixelBufferObject *pbo);
281 
282 #endif
283 
285 
286  bool AllocateDepth(unsigned int width,unsigned int height,
287  int internalFormat);
289 
292  bool Allocate1D(unsigned int width, int numComps,int vtkType);
293 
295 
297  bool Allocate2D(unsigned int width,unsigned int height, int numComps,
298  int vtkType);
300 
302 
304  bool Allocate3D(unsigned int width,unsigned int height,
305  unsigned int depth, int numComps,
306  int vtkType);
308 
309 
311 
312  bool Create2D(unsigned int width, unsigned int height, int numComps,
313  int vtktype, bool shaderSupportsTextureInt);
314  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
315  int numComps, int vtktype, bool shaderSupportsTextureInt);
317 
319 
320  int GetDataType(int vtk_scalar_type);
321  void SetDataType(unsigned int glType);
323 
325 
327  unsigned int GetInternalFormat(int vtktype, int numComps,
328  bool shaderSupportsTextureInt);
329  void SetInternalFormat(unsigned int glInternalFormat);
331 
333 
335  unsigned int GetFormat(int vtktype, int numComps,
336  bool shaderSupportsTextureInt);
337  void SetFormat(unsigned int glFormat);
339 
344  void ResetFormatAndType();
345 
346  unsigned int GetDepthTextureModeFormat(int vtktype);
347  unsigned int GetMinificationFilterMode(int vtktype);
348  unsigned int GetMagnificationFilterMode(int vtktype);
349  unsigned int GetWrapSMode(int vtktype);
350  unsigned int GetWrapTMode(int vtktype);
351  unsigned int GetWrapRMode(int vtktype);
352 
354 
357  vtkSetMacro(RequireDepthBufferFloat, bool);
358  vtkGetMacro(RequireDepthBufferFloat, bool);
359  vtkGetMacro(SupportsDepthBufferFloat, bool);
361 
363 
366  vtkSetMacro(RequireTextureFloat,bool);
367  vtkGetMacro(RequireTextureFloat,bool);
368  vtkGetMacro(SupportsTextureFloat,bool);
370 
372 
375  vtkSetMacro(RequireTextureInteger,bool);
376  vtkGetMacro(RequireTextureInteger,bool);
377  vtkGetMacro(SupportsTextureInteger,bool);
379 
381 
384  vtkGetMacro(WrapS,int);
385  vtkSetMacro(WrapS,int);
387 
389 
392  vtkGetMacro(WrapT,int);
393  vtkSetMacro(WrapT,int);
395 
397 
400  vtkGetMacro(WrapR,int);
401  vtkSetMacro(WrapR,int);
403 
405 
410  vtkGetMacro(MinificationFilter,int);
411  vtkSetMacro(MinificationFilter,int);
413 
415 
417  vtkGetMacro(MagnificationFilter,int);
418  vtkSetMacro(MagnificationFilter,int);
420 
422 
425  { this->SetMagnificationFilter(val?Linear:Nearest); }
427 
429  { return this->MagnificationFilter==Linear; }
430 
432 
435  vtkSetVector4Macro(BorderColor,float);
436  vtkGetVector4Macro(BorderColor,float);
438 
440 
442  vtkSetMacro(MinLOD,float);
443  vtkGetMacro(MinLOD,float);
445 
447 
449  vtkSetMacro(MaxLOD,float);
450  vtkGetMacro(MaxLOD,float);
452 
454 
457  vtkSetMacro(BaseLevel,int);
458  vtkGetMacro(BaseLevel,int);
460 
462 
465  vtkSetMacro(MaxLevel,int);
466  vtkGetMacro(MaxLevel,int);
468 
470 
476  vtkGetMacro(DepthTextureCompare,bool);
477  vtkSetMacro(DepthTextureCompare,bool);
479 
481 
491  vtkGetMacro(DepthTextureCompareFunction,int);
492  vtkSetMacro(DepthTextureCompareFunction,int);
494 
496 
501 
503 
506  static bool IsSupported(
507  vtkOpenGLRenderWindow* renWin,
508  bool requireTexFloat,
509  bool requireDepthFloat,
510  bool requireTexInt);
512 
514 
515  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
516  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
518 
520 
523  void CopyToFrameBuffer(vtkShaderProgram *program,
525  // part of a texture to part of a viewport, scaling as needed
526  void CopyToFrameBuffer(int srcXmin, int srcYmin,
527  int srcXmax, int srcYmax,
528  int dstXmin, int dstYmin,
529  int dstXmax, int dstYmax,
530  int dstSizeX, int dstSizeY,
531  vtkShaderProgram *program,
533  );
534  // copy part of a texure to part of a viewport, no scalaing
535  void CopyToFrameBuffer(int srcXmin, int srcYmin,
536  int srcXmax, int srcYmax,
537  int dstXmin, int dstYmin,
538  int dstSizeX, int dstSizeY,
539  vtkShaderProgram *program,
541  );
542  // copy a texture to a quad using the provided tcoords and verts
543  void CopyToFrameBuffer(float *tcoords, float *verts,
544  vtkShaderProgram *program,
546  );
548 
549 
551 
559  void CopyFromFrameBuffer(int srcXmin,
560  int srcYmin,
561  int dstXmin,
562  int dstYmin,
563  int width,
564  int height);
566 
567 
568 
569 protected:
571  ~vtkTextureObject();
572 
574  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
575 
577  void CreateTexture();
578 
580  void DestroyTexture();
581 
582  int NumberOfDimensions;
583  unsigned int Width;
584  unsigned int Height;
585  unsigned int Depth;
586 
587  unsigned int Target; // GLenum
588  unsigned int Format; // GLenum
589  unsigned int InternalFormat; // GLenum
590  unsigned int Type; // GLenum
591  int Components;
592 
594  unsigned int Handle;
595  bool RequireTextureInteger;
596  bool SupportsTextureInteger;
597  bool RequireTextureFloat;
598  bool SupportsTextureFloat;
599  bool RequireDepthBufferFloat;
600  bool SupportsDepthBufferFloat;
601 
602  int WrapS;
603  int WrapT;
604  int WrapR;
605  int MinificationFilter;
606  int MagnificationFilter;
607  bool LinearMagnification;
608 
609  float MinLOD;
610  float MaxLOD;
611  int BaseLevel;
612  int MaxLevel;
613  float BorderColor[4];
614 
615  bool DepthTextureCompare;
616  int DepthTextureCompareFunction;
617 
618  bool GenerateMipmap;
619 
620  int AutoParameters;
621  vtkTimeStamp SendParametersTime;
622 
623  // used for copying to framebuffer
625 
626 private:
627  vtkTextureObject(const vtkTextureObject&); // Not implemented.
628  void operator=(const vtkTextureObject&); // Not implemented.
629 };
630 
631 #endif
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
abstract base class for most VTK objects
Definition: vtkObject.h:61
unsigned int GetTuples()
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
record modification and/or execution time
Definition: vtkTimeStamp.h:34
unsigned int InternalFormat
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
vtkgl::CellBO * ShaderProgram
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
window superclass for vtkRenderWindow
Definition: vtkWindow.h:33
GLint GLint GLsizei GLsizei GLsizei depth
Definition: vtkgl.h:11316
#define vtkSetVector4Macro(name, type)
Definition: vtkSetGet.h:312
a simple class to control print indentation
Definition: vtkIndent.h:38
GLint GLint GLsizei width
Definition: vtkgl.h:11316
vtkWeakPointer< vtkOpenGLRenderWindow > Context
Definition: vtkgl.h:11267
void SetLinearMagnification(bool val)
#define vtkGetVector4Macro(name, type)
Definition: vtkSetGet.h:331
abstracts an OpenGL pixel buffer object.
The VertexArrayObject class uses, or emulates, vertex array objects.
abstracts an OpenGL texture object.
GLenum internalFormat
Definition: vtkgl.h:15195
GLuint program
Definition: vtkgl.h:13011
VTKRENDERINGOPENGL_EXPORT PFNGLGENERATEMIPMAPPROC GenerateMipmap
GLclampf GLclampf GLclampf alpha
Definition: vtkgl.h:11313
GLuint GLfloat * val
Definition: vtkgl.h:13789
The ShaderProgram uses one or more Shader objects.
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69