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 
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);
330  int GetDefaultDataType(int vtk_scalar_type);
332 
334 
336  unsigned int GetInternalFormat(int vtktype, int numComps,
337  bool shaderSupportsTextureInt);
338  void SetInternalFormat(unsigned int glInternalFormat);
339  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
340  bool shaderSupportsTextureInt);
342 
344 
346  unsigned int GetFormat(int vtktype, int numComps,
347  bool shaderSupportsTextureInt);
348  void SetFormat(unsigned int glFormat);
349  unsigned int GetDefaultFormat(int vtktype, int numComps,
350  bool shaderSupportsTextureInt);
352 
357  void ResetFormatAndType();
358 
359  unsigned int GetMinificationFilterMode(int vtktype);
360  unsigned int GetMagnificationFilterMode(int vtktype);
361  unsigned int GetWrapSMode(int vtktype);
362  unsigned int GetWrapTMode(int vtktype);
363  unsigned int GetWrapRMode(int vtktype);
364 
366 
369  vtkSetMacro(RequireDepthBufferFloat, bool);
370  vtkGetMacro(RequireDepthBufferFloat, bool);
371  vtkGetMacro(SupportsDepthBufferFloat, bool);
373 
375 
378  vtkSetMacro(RequireTextureFloat,bool);
379  vtkGetMacro(RequireTextureFloat,bool);
380  vtkGetMacro(SupportsTextureFloat,bool);
382 
384 
387  vtkSetMacro(RequireTextureInteger,bool);
388  vtkGetMacro(RequireTextureInteger,bool);
389  vtkGetMacro(SupportsTextureInteger,bool);
391 
393 
396  vtkGetMacro(WrapS,int);
397  vtkSetMacro(WrapS,int);
399 
401 
404  vtkGetMacro(WrapT,int);
405  vtkSetMacro(WrapT,int);
407 
409 
412  vtkGetMacro(WrapR,int);
413  vtkSetMacro(WrapR,int);
415 
417 
422  vtkGetMacro(MinificationFilter,int);
423  vtkSetMacro(MinificationFilter,int);
425 
427 
429  vtkGetMacro(MagnificationFilter,int);
430  vtkSetMacro(MagnificationFilter,int);
432 
434 
436  void SetLinearMagnification(bool val)
437  { this->SetMagnificationFilter(val?Linear:Nearest); }
439 
441  { return this->MagnificationFilter==Linear; }
442 
444 
447  vtkSetVector4Macro(BorderColor,float);
448  vtkGetVector4Macro(BorderColor,float);
450 
452 
454  vtkSetMacro(MinLOD,float);
455  vtkGetMacro(MinLOD,float);
457 
459 
461  vtkSetMacro(MaxLOD,float);
462  vtkGetMacro(MaxLOD,float);
464 
466 
469  vtkSetMacro(BaseLevel,int);
470  vtkGetMacro(BaseLevel,int);
472 
474 
477  vtkSetMacro(MaxLevel,int);
478  vtkGetMacro(MaxLevel,int);
480 
482 
488  vtkGetMacro(DepthTextureCompare,bool);
489  vtkSetMacro(DepthTextureCompare,bool);
491 
493 
503  vtkGetMacro(DepthTextureCompareFunction,int);
504  vtkSetMacro(DepthTextureCompareFunction,int);
506 
508 
510  vtkGetMacro(GenerateMipmap,bool);
511  vtkSetMacro(GenerateMipmap,bool);
513 
515 
518  static bool IsSupported(
519  vtkOpenGLRenderWindow* renWin,
520  bool requireTexFloat,
521  bool requireDepthFloat,
522  bool requireTexInt);
524 
526 
527  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
528  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
530 
532 
535  void CopyToFrameBuffer(vtkShaderProgram *program,
537  // part of a texture to part of a viewport, scaling as needed
538  void CopyToFrameBuffer(int srcXmin, int srcYmin,
539  int srcXmax, int srcYmax,
540  int dstXmin, int dstYmin,
541  int dstXmax, int dstYmax,
542  int dstSizeX, int dstSizeY,
543  vtkShaderProgram *program,
545  );
546  // copy part of a texure to part of a viewport, no scalaing
547  void CopyToFrameBuffer(int srcXmin, int srcYmin,
548  int srcXmax, int srcYmax,
549  int dstXmin, int dstYmin,
550  int dstSizeX, int dstSizeY,
551  vtkShaderProgram *program,
553  );
554  // copy a texture to a quad using the provided tcoords and verts
555  void CopyToFrameBuffer(float *tcoords, float *verts,
556  vtkShaderProgram *program,
558  );
560 
561 
563 
571  void CopyFromFrameBuffer(int srcXmin,
572  int srcYmin,
573  int dstXmin,
574  int dstYmin,
575  int width,
576  int height);
578 
579 
580 
581 protected:
583  ~vtkTextureObject();
584 
586  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
587 
589  void CreateTexture();
590 
592  void DestroyTexture();
593 
594  int NumberOfDimensions;
595  unsigned int Width;
596  unsigned int Height;
597  unsigned int Depth;
598 
599  unsigned int Target; // GLenum
600  unsigned int Format; // GLenum
601  unsigned int InternalFormat; // GLenum
602  unsigned int Type; // GLenum
603  int Components;
604 
606  unsigned int Handle;
607  bool RequireTextureInteger;
608  bool SupportsTextureInteger;
609  bool RequireTextureFloat;
610  bool SupportsTextureFloat;
611  bool RequireDepthBufferFloat;
612  bool SupportsDepthBufferFloat;
613 
614  int WrapS;
615  int WrapT;
616  int WrapR;
617  int MinificationFilter;
618  int MagnificationFilter;
619  bool LinearMagnification;
620 
621  float MinLOD;
622  float MaxLOD;
623  int BaseLevel;
624  int MaxLevel;
625  float BorderColor[4];
626 
627  bool DepthTextureCompare;
628  int DepthTextureCompareFunction;
629 
630  bool GenerateMipmap;
631 
632  int AutoParameters;
633  vtkTimeStamp SendParametersTime;
634 
635  // used for copying to framebuffer
637 
638  // for texturebuffers we hold on to the Buffer
640 
641 private:
642  vtkTextureObject(const vtkTextureObject&); // Not implemented.
643  void operator=(const vtkTextureObject&); // Not implemented.
644 };
645 
646 #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()
#define VTKRENDERINGOPENGL2_EXPORT
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.