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 
123  static vtkTextureObject* New();
124  vtkTypeMacro(vtkTextureObject, vtkObject);
125  void PrintSelf(ostream& os, vtkIndent indent);
126 
128 
132  void SetContext(vtkOpenGLRenderWindow*);
133  vtkOpenGLRenderWindow* GetContext();
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 
160  int GetTextureUnit();
161 
163 
166  void Bind();
167  void UnBind();
169 
171  void Activate();
172 
174  void Deactivate();
175 
177  void ReleaseGraphicsResources(vtkWindow *win);
178 
181  bool IsBound();
182 
184 
187  void SendParameters();
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 
276  vtkPixelBufferObject* Download();
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 
324  int GetVTKDataType();
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 
352  void ResetFormatAndType();
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 
432  void SetLinearMagnification(bool val)
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 
506  vtkGetMacro(GenerateMipmap,bool);
507  vtkSetMacro(GenerateMipmap,bool);
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 
531  void CopyToFrameBuffer(vtkShaderProgram *program,
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,
539  vtkShaderProgram *program,
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,
547  vtkShaderProgram *program,
549  );
550  // copy a texture to a quad using the provided tcoords and verts
551  void CopyToFrameBuffer(float *tcoords, float *verts,
552  vtkShaderProgram *program,
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:
579  ~vtkTextureObject();
580 
582  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
583 
585  void CreateTexture();
586 
588  void DestroyTexture();
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
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkOpenGLHelper * ShaderProgram
unsigned int GetTuples()
record modification and/or execution time
Definition: vtkTimeStamp.h:34
unsigned int InternalFormat
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkWeakPointer< vtkOpenGLRenderWindow > Context
void SetLinearMagnification(bool val)
abstracts an OpenGL pixel buffer object.
vtkOpenGLBufferObject * BufferObject
abstracts an OpenGL texture object.
OpenGL buffer object.
static vtkObject * New()
The ShaderProgram uses one or more Shader objects.