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 =========================================================================*/
27 #ifndef vtkTextureObject_h
28 #define vtkTextureObject_h
29 
30 #include "vtkRenderingOpenGL2Module.h" // For export macro
31 #include "vtkObject.h"
32 #include "vtkWeakPointer.h" // for render context
33 
35 class vtkOpenGLHelper;
39 class vtkShaderProgram;
40 class vtkWindow;
42 
43 
44 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
45 {
46 public:
47 
48  // DepthTextureCompareFunction values.
49  enum
50  {
51  Lequal=0, // r=R<=Dt ? 1.0 : 0.0
52  Gequal, // r=R>=Dt ? 1.0 : 0.0
53  Less, // r=R<D_t ? 1.0 : 0.0
54  Greater, // r=R>Dt ? 1.0 : 0.0
55  Equal, // r=R==Dt ? 1.0 : 0.0
56  NotEqual, // r=R!=Dt ? 1.0 : 0.0
57  AlwaysTrue, // r=1.0 // WARNING "Always" is macro defined in X11/X.h...
58  Never, // r=0.0
59  NumberOfDepthTextureCompareFunctions
60  };
61 
62 // ClampToBorder is not supported in ES 2.0
63 // Wrap values.
64 #if GL_ES_VERSION_3_0 != 1
65  enum
66  {
67  ClampToEdge=0,
68  Repeat,
69  MirroredRepeat,
70  ClampToBorder,
71  NumberOfWrapModes
72  };
73 #else
74  enum
75  {
76  ClampToEdge=0,
77  Repeat,
78  MirroredRepeat,
79  NumberOfWrapModes
80  };
81 #endif
82 
83  // MinificationFilter values.
84  enum
85  {
86  Nearest=0,
87  Linear,
88  NearestMipmapNearest,
89  NearestMipmapLinear,
90  LinearMipmapNearest,
91  LinearMipmapLinear,
92  NumberOfMinificationModes
93  };
94 
95  // Internal depth format
96  enum
97  {
98  Native=0, // will try to match with the depth buffer format.
99  Fixed16,
100  Fixed24,
101  Fixed32,
102  Float32,
103  NumberOfDepthFormats
104  };
105 
106  // Internal alpha format
107  enum
108  {
109  alpha=0,
114  NumberOfAlphaFormats
115  };
116 
117  // Depth mode formats
118  enum
119  {
120  DepthAlpha=0,
123  NumberOfDepthModeFormats
124  };
125 
126  static vtkTextureObject* New();
127  vtkTypeMacro(vtkTextureObject, vtkObject);
128  void PrintSelf(ostream& os, vtkIndent indent);
129 
131 
140  void SetContext(vtkOpenGLRenderWindow*);
141  vtkOpenGLRenderWindow* GetContext();
143 
145 
149  vtkGetMacro(Width, unsigned int);
150  vtkGetMacro(Height, unsigned int);
151  vtkGetMacro(Depth, unsigned int);
152  vtkGetMacro(Components, int);
153  unsigned int GetTuples()
154  { return this->Width*this->Height*this->Depth; }
156 
157  vtkGetMacro(NumberOfDimensions, int);
158 
160 
163  vtkGetMacro(Target, unsigned int);
165 
167 
170  vtkGetMacro(Handle, unsigned int);
172 
176  int GetTextureUnit();
177 
179 
184  void Bind();
185  void UnBind();
187 
191  void Activate();
192 
196  void Deactivate();
197 
201  void ReleaseGraphicsResources(vtkWindow *win);
202 
207  bool IsBound();
208 
210 
216  void SendParameters();
217  vtkSetMacro(AutoParameters, int);
218  vtkGetMacro(AutoParameters, int);
220 
225  bool Create2DFromRaw(unsigned int width, unsigned int height,
226  int numComps, int dataType, void *data);
227 
232  bool CreateDepthFromRaw(unsigned int width, unsigned int height,
233  int internalFormat, int rawType,
234  void *raw);
235 
240  bool CreateTextureBuffer(unsigned int numValues, int numComps,
241  int dataType, vtkOpenGLBufferObject *bo);
242 
248  bool CreateCubeFromRaw(unsigned int width, unsigned int height,
249  int numComps, int dataType, void *data[6]);
250 
251 // 1D textures are not supported in ES 2.0 or 3.0
252 #if GL_ES_VERSION_3_0 != 1
253 
264  bool Create1D(int numComps,
266  bool shaderSupportsTextureInt);
267 
271  bool Create1DFromRaw(unsigned int width, int numComps,
272  int dataType, void *data);
277  bool CreateAlphaFromRaw(unsigned int width,
278  int internalFormat,
279  int rawType,
280  void *raw);
281 #endif
282 
289  bool Create2D(unsigned int width, unsigned int height, int numComps,
291  bool shaderSupportsTextureInt);
292 
299  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
300  int numComps, vtkPixelBufferObject *pbo,
301  bool shaderSupportsTextureInt);
302 
307  bool Create3DFromRaw(unsigned int width, unsigned int height,
308  unsigned int depth, int numComps,
309  int dataType, void *data);
310 
317  vtkPixelBufferObject* Download();
318 
323  bool CreateDepth(unsigned int width,
324  unsigned int height,
325  int internalFormat,
326  vtkPixelBufferObject *pbo);
327 
331  bool AllocateDepth(unsigned int width, unsigned int height,
332  int internalFormat);
333 
338  bool Allocate1D(unsigned int width, int numComps, int vtkType);
339 
344  bool Allocate2D(unsigned int width, unsigned int height, int numComps,
345  int vtkType);
346 
351  bool Allocate3D(unsigned int width, unsigned int height,
352  unsigned int depth, int numComps,
353  int vtkType);
354 
355 
357 
360  bool Create2D(unsigned int width, unsigned int height, int numComps,
361  int vtktype, bool shaderSupportsTextureInt);
362  bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
363  int numComps, int vtktype, bool shaderSupportsTextureInt);
365 
369  int GetVTKDataType();
370 
372 
375  int GetDataType(int vtk_scalar_type);
376  void SetDataType(unsigned int glType);
377  int GetDefaultDataType(int vtk_scalar_type);
379 
381 
386  unsigned int GetInternalFormat(int vtktype, int numComps,
387  bool shaderSupportsTextureInt);
388  void SetInternalFormat(unsigned int glInternalFormat);
389  unsigned int GetDefaultInternalFormat(int vtktype, int numComps,
390  bool shaderSupportsTextureInt);
392 
394 
399  unsigned int GetFormat(int vtktype, int numComps,
400  bool shaderSupportsTextureInt);
401  void SetFormat(unsigned int glFormat);
402  unsigned int GetDefaultFormat(int vtktype, int numComps,
403  bool shaderSupportsTextureInt);
405 
414  void ResetFormatAndType();
415 
416  unsigned int GetMinificationFilterMode(int vtktype);
417  unsigned int GetMagnificationFilterMode(int vtktype);
418  unsigned int GetWrapSMode(int vtktype);
419  unsigned int GetWrapTMode(int vtktype);
420  unsigned int GetWrapRMode(int vtktype);
421 
423 
429  vtkSetMacro(RequireDepthBufferFloat, bool);
430  vtkGetMacro(RequireDepthBufferFloat, bool);
431  vtkGetMacro(SupportsDepthBufferFloat, bool);
433 
435 
441  vtkSetMacro(RequireTextureFloat, bool);
442  vtkGetMacro(RequireTextureFloat, bool);
443  vtkGetMacro(SupportsTextureFloat, bool);
445 
447 
453  vtkSetMacro(RequireTextureInteger, bool);
454  vtkGetMacro(RequireTextureInteger, bool);
455  vtkGetMacro(SupportsTextureInteger, bool);
457 
459 
469  vtkGetMacro(WrapS, int);
470  vtkSetMacro(WrapS, int);
472 
474 
484  vtkGetMacro(WrapT, int);
485  vtkSetMacro(WrapT, int);
487 
489 
499  vtkGetMacro(WrapR, int);
500  vtkSetMacro(WrapR, int);
502 
504 
517  vtkGetMacro(MinificationFilter, int);
518  vtkSetMacro(MinificationFilter, int);
520 
522 
529  vtkGetMacro(MagnificationFilter, int);
530  vtkSetMacro(MagnificationFilter, int);
532 
537  void SetLinearMagnification(bool val)
538  { this->SetMagnificationFilter(val?Linear:Nearest); }
539 
541  { return this->MagnificationFilter==Linear; }
542 
544 
549  vtkSetVector4Macro(BorderColor, float);
550  vtkGetVector4Macro(BorderColor, float);
552 
554 
558  vtkSetMacro(MinLOD, float);
559  vtkGetMacro(MinLOD, float);
561 
563 
567  vtkSetMacro(MaxLOD, float);
568  vtkGetMacro(MaxLOD, float);
570 
572 
577  vtkSetMacro(BaseLevel, int);
578  vtkGetMacro(BaseLevel, int);
580 
582 
587  vtkSetMacro(MaxLevel, int);
588  vtkGetMacro(MaxLevel, int);
590 
592 
602  vtkGetMacro(DepthTextureCompare, bool);
603  vtkSetMacro(DepthTextureCompare, bool);
605 
607 
627  vtkGetMacro(DepthTextureCompareFunction, int);
628  vtkSetMacro(DepthTextureCompareFunction, int);
630 
632 
637  vtkGetMacro(GenerateMipmap, bool);
638  vtkSetMacro(GenerateMipmap, bool);
640 
650  static int GetMaximumTextureSize(vtkOpenGLRenderWindow* context);
651 
657  static bool IsSupported(
658  vtkOpenGLRenderWindow* renWin,
659  bool requireTexFloat,
660  bool requireDepthFloat,
661  bool requireTexInt);
662 
666  static bool IsSupported(vtkOpenGLRenderWindow* renWin)
667  { return vtkTextureObject::IsSupported(renWin, false, false, false); }
668 
670 
675  void CopyToFrameBuffer(vtkShaderProgram *program,
677  // part of a texture to part of a viewport, scaling as needed
678  void CopyToFrameBuffer(int srcXmin, int srcYmin,
679  int srcXmax, int srcYmax,
680  int dstXmin, int dstYmin,
681  int dstXmax, int dstYmax,
682  int dstSizeX, int dstSizeY,
683  vtkShaderProgram *program,
685  );
686  // copy part of a texure to part of a viewport, no scalaing
687  void CopyToFrameBuffer(int srcXmin, int srcYmin,
688  int srcXmax, int srcYmax,
689  int dstXmin, int dstYmin,
690  int dstSizeX, int dstSizeY,
691  vtkShaderProgram *program,
693  );
694  // copy a texture to a quad using the provided tcoords and verts
695  void CopyToFrameBuffer(float *tcoords, float *verts,
696  vtkShaderProgram *program,
698  );
700 
701 
713  void CopyFromFrameBuffer(int srcXmin,
714  int srcYmin,
715  int dstXmin,
716  int dstYmin,
717  int width,
718  int height);
719 
732  void GetShiftAndScale(float &shift, float &scale);
733 
734 protected:
736  ~vtkTextureObject();
737 
739 
743  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
744 
748  void CreateTexture();
749 
753  void DestroyTexture();
754 
755  int NumberOfDimensions;
756  unsigned int Width;
757  unsigned int Height;
758  unsigned int Depth;
759 
760  unsigned int Target; // GLenum
761  unsigned int Format; // GLenum
762  unsigned int InternalFormat; // GLenum
763  unsigned int Type; // GLenum
764  int Components;
765 
767  unsigned int Handle;
768  bool RequireTextureInteger;
769  bool SupportsTextureInteger;
770  bool RequireTextureFloat;
771  bool SupportsTextureFloat;
772  bool RequireDepthBufferFloat;
773  bool SupportsDepthBufferFloat;
774 
775  int WrapS;
776  int WrapT;
777  int WrapR;
778  int MinificationFilter;
779  int MagnificationFilter;
780 
781  float MinLOD;
782  float MaxLOD;
783  int BaseLevel;
784  int MaxLevel;
785  float BorderColor[4];
786 
787  bool DepthTextureCompare;
788  int DepthTextureCompareFunction;
789 
790  bool GenerateMipmap;
791 
792  int AutoParameters;
793  vtkTimeStamp SendParametersTime;
794 
795  // used for copying to framebuffer
797 
798  // for texturebuffers we hold on to the Buffer
800 
801 private:
802  vtkTextureObject(const vtkTextureObject&) VTK_DELETE_FUNCTION;
803  void operator=(const vtkTextureObject&) VTK_DELETE_FUNCTION;
804 };
805 
806 #endif
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Check for feature support, without any optional features.
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkOpenGLHelper * ShaderProgram
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
unsigned int GetTuples()
Get the texture dimensions.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
unsigned int InternalFormat
static bool IsSupported(vtkRenderWindow *renWin, bool requireTexFloat, bool requireDepthFloat, bool requireTexInt)
Returns if the context supports the required extensions.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkWeakPointer< vtkOpenGLRenderWindow > Context
void SetLinearMagnification(bool val)
Tells if the magnification mode is linear (true) or nearest (false).
abstracts an OpenGL pixel buffer object.
vtkOpenGLBufferObject * BufferObject
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
abstracts an OpenGL texture object.
OpenGL buffer object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
The ShaderProgram uses one or more Shader objects.