VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/OpenGL2/vtkTextureObject.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTextureObject.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00023 #ifndef vtkTextureObject_h
00024 #define vtkTextureObject_h
00025 
00026 #include "vtkRenderingOpenGL2Module.h" // For export macro
00027 #include "vtkObject.h"
00028 #include "vtkWeakPointer.h" // for render context
00029 
00030 class vtkWindow;
00031 class vtkShaderProgram;
00032 class vtkOpenGLRenderWindow;
00033 namespace vtkgl
00034 {
00035 class VertexArrayObject;
00036 class CellBO;
00037 }
00038 
00039 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
00040 class vtkPixelBufferObject;
00041 #endif
00042 
00043 class VTKRENDERINGOPENGL2_EXPORT vtkTextureObject : public vtkObject
00044 {
00045 public:
00046 
00047   // DepthTextureCompareFunction values.
00048   enum
00049   {
00050     Lequal=0, // r=R<=Dt ? 1.0 : 0.0
00051     Gequal, // r=R>=Dt ? 1.0 : 0.0
00052     Less, // r=R<D_t ? 1.0 : 0.0
00053     Greater, // r=R>Dt ? 1.0 : 0.0
00054     Equal, // r=R==Dt ? 1.0 : 0.0
00055     NotEqual, // r=R!=Dt ? 1.0 : 0.0
00056     AlwaysTrue, //  r=1.0 // WARNING "Always" is macro defined in X11/X.h...
00057     Never, // r=0.0
00058     NumberOfDepthTextureCompareFunctions
00059   };
00060 
00061 // ClampToBorder is not supported in ES 2.0
00062 // Wrap values.
00063 #if GL_ES_VERSION_2_0 != 1
00064   enum
00065   {
00066     ClampToEdge=0,
00067     Repeat,
00068     MirroredRepeat,
00069     ClampToBorder,
00070     NumberOfWrapModes
00071   };
00072 #else
00073   enum
00074   {
00075     ClampToEdge=0,
00076     Repeat,
00077     MirroredRepeat,
00078     NumberOfWrapModes
00079   };
00080 #endif
00081 
00082   // MinificationFilter values.
00083   enum
00084   {
00085     Nearest=0,
00086     Linear,
00087     NearestMipmapNearest,
00088     NearestMipmapLinear,
00089     LinearMipmapNearest,
00090     LinearMipmapLinear,
00091     NumberOfMinificationModes
00092   };
00093 
00094   // Internal depth format
00095   enum
00096   {
00097     Native=0, // will try to match with the depth buffer format.
00098     Fixed16,
00099     Fixed24,
00100     Fixed32,
00101     Float32,
00102     NumberOfDepthFormats
00103   };
00104 
00105   // Internal alpha format
00106   enum
00107   {
00108     alpha=0,
00109     alpha4,
00110     alpha8,
00111     alpha12,
00112     alpha16,
00113     NumberOfAlphaFormats
00114   };
00115 
00116   // Depth mode formats
00117   enum
00118   {
00119     DepthAlpha=0,
00120     DepthLuminance,
00121     DepthIntensity,
00122     NumberOfDepthModeFormats
00123   };
00124 
00125   static vtkTextureObject* New();
00126   vtkTypeMacro(vtkTextureObject, vtkObject);
00127   void PrintSelf(ostream& os, vtkIndent indent);
00128 
00130 
00134   void SetContext(vtkOpenGLRenderWindow*);
00135   vtkOpenGLRenderWindow* GetContext();
00137 
00139 
00141   vtkGetMacro(Width, unsigned int);
00142   vtkGetMacro(Height, unsigned int);
00143   vtkGetMacro(Depth, unsigned int);
00144   vtkGetMacro(Components, int);
00145   unsigned int GetTuples()
00146   { return this->Width*this->Height*this->Depth; }
00148 
00149   vtkGetMacro(NumberOfDimensions, int);
00150 
00152 
00153   vtkGetMacro(Target, unsigned int);
00155 
00157 
00158   vtkGetMacro(Handle, unsigned int);
00160 
00162   int GetTextureUnit();
00163 
00165 
00168   void Bind();
00169   void UnBind();
00171 
00173   void Activate();
00174 
00176   void Deactivate();
00177 
00179   void ReleaseGraphicsResources(vtkWindow *win);
00180 
00183   bool IsBound();
00184 
00186 
00189   void SendParameters();
00190   vtkSetMacro(AutoParameters, int);
00191   vtkGetMacro(AutoParameters, int);
00193 
00195 
00196   bool Create2DFromRaw(unsigned int width, unsigned int height,
00197                        int numComps,  int dataType, void *data);
00199 
00201 
00203   bool CreateDepthFromRaw(unsigned int width, unsigned int height,
00204                           int internalFormat, int rawType,
00205                           void *raw);
00207 
00208 // 1D  textures are not supported in ES 2.0 or 3.0
00209 #if GL_ES_VERSION_2_0 != 1
00210 
00212 
00219   bool Create1D(int numComps,
00220                 vtkPixelBufferObject *pbo,
00221                 bool shaderSupportsTextureInt);
00223 
00225 
00226   bool Create1DFromRaw(unsigned int width, int numComps,
00227                        int dataType, void *data);
00229 
00230 
00232   bool CreateAlphaFromRaw(unsigned int width,
00233                           int internalFormat,
00234                           int rawType,
00235                           void *raw);
00236 #endif
00237 
00238 
00239 // PBO's, and 3D textures are not supported in ES 2.0
00240 #if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
00241 
00243 
00246   bool Create2D(unsigned int width, unsigned int height, int numComps,
00247                 vtkPixelBufferObject *pbo,
00248                 bool shaderSupportsTextureInt);
00250 
00252 
00255   bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
00256                 int numComps, vtkPixelBufferObject *pbo,
00257                 bool shaderSupportsTextureInt);
00259 
00261 
00262   bool Create3DFromRaw(unsigned int width, unsigned int height,
00263                        unsigned int depth, int numComps,
00264                        int dataType, void *data);
00266 
00271   vtkPixelBufferObject* Download();
00272 
00274 
00276   bool CreateDepth(unsigned int width,
00277                    unsigned int height,
00278                    int internalFormat,
00279                    vtkPixelBufferObject *pbo);
00281 
00282 #endif
00283 
00285 
00286   bool AllocateDepth(unsigned int width,unsigned int height,
00287                      int internalFormat);
00289 
00292   bool Allocate1D(unsigned int width, int numComps,int vtkType);
00293 
00295 
00297   bool Allocate2D(unsigned int width,unsigned int height, int numComps,
00298                   int vtkType);
00300 
00302 
00304   bool Allocate3D(unsigned int width,unsigned int height,
00305                   unsigned int depth, int numComps,
00306                   int vtkType);
00308 
00309 
00311 
00312   bool Create2D(unsigned int width, unsigned int height, int numComps,
00313                 int vtktype, bool shaderSupportsTextureInt);
00314   bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
00315                 int numComps, int vtktype, bool shaderSupportsTextureInt);
00317 
00319 
00320   int GetDataType(int vtk_scalar_type);
00321   void SetDataType(unsigned int glType);
00323 
00325 
00327   unsigned int GetInternalFormat(int vtktype, int numComps,
00328                                  bool shaderSupportsTextureInt);
00329   void SetInternalFormat(unsigned int glInternalFormat);
00331 
00333 
00335   unsigned int GetFormat(int vtktype, int numComps,
00336                          bool shaderSupportsTextureInt);
00337   void SetFormat(unsigned int glFormat);
00339 
00344   void ResetFormatAndType();
00345 
00346   unsigned int GetDepthTextureModeFormat(int vtktype);
00347   unsigned int GetMinificationFilterMode(int vtktype);
00348   unsigned int GetMagnificationFilterMode(int vtktype);
00349   unsigned int GetWrapSMode(int vtktype);
00350   unsigned int GetWrapTMode(int vtktype);
00351   unsigned int GetWrapRMode(int vtktype);
00352 
00354 
00357   vtkSetMacro(RequireDepthBufferFloat, bool);
00358   vtkGetMacro(RequireDepthBufferFloat, bool);
00359   vtkGetMacro(SupportsDepthBufferFloat, bool);
00361 
00363 
00366   vtkSetMacro(RequireTextureFloat,bool);
00367   vtkGetMacro(RequireTextureFloat,bool);
00368   vtkGetMacro(SupportsTextureFloat,bool);
00370 
00372 
00375   vtkSetMacro(RequireTextureInteger,bool);
00376   vtkGetMacro(RequireTextureInteger,bool);
00377   vtkGetMacro(SupportsTextureInteger,bool);
00379 
00381 
00384   vtkGetMacro(WrapS,int);
00385   vtkSetMacro(WrapS,int);
00387 
00389 
00392   vtkGetMacro(WrapT,int);
00393   vtkSetMacro(WrapT,int);
00395 
00397 
00400   vtkGetMacro(WrapR,int);
00401   vtkSetMacro(WrapR,int);
00403 
00405 
00410   vtkGetMacro(MinificationFilter,int);
00411   vtkSetMacro(MinificationFilter,int);
00413 
00415 
00417   vtkGetMacro(MagnificationFilter,int);
00418   vtkSetMacro(MagnificationFilter,int);
00420 
00422 
00424   void SetLinearMagnification(bool val)
00425   { this->SetMagnificationFilter(val?Linear:Nearest); }
00427 
00428   bool GetLinearMagnification()
00429   { return this->MagnificationFilter==Linear; }
00430 
00432 
00435   vtkSetVector4Macro(BorderColor,float);
00436   vtkGetVector4Macro(BorderColor,float);
00438 
00440 
00442   vtkSetMacro(MinLOD,float);
00443   vtkGetMacro(MinLOD,float);
00445 
00447 
00449   vtkSetMacro(MaxLOD,float);
00450   vtkGetMacro(MaxLOD,float);
00452 
00454 
00457   vtkSetMacro(BaseLevel,int);
00458   vtkGetMacro(BaseLevel,int);
00460 
00462 
00465   vtkSetMacro(MaxLevel,int);
00466   vtkGetMacro(MaxLevel,int);
00468 
00470 
00476   vtkGetMacro(DepthTextureCompare,bool);
00477   vtkSetMacro(DepthTextureCompare,bool);
00479 
00481 
00491   vtkGetMacro(DepthTextureCompareFunction,int);
00492   vtkSetMacro(DepthTextureCompareFunction,int);
00494 
00496 
00498   vtkGetMacro(GenerateMipmap,bool);
00499   vtkSetMacro(GenerateMipmap,bool);
00501 
00503 
00506   static bool IsSupported(
00507         vtkOpenGLRenderWindow* renWin,
00508         bool requireTexFloat,
00509         bool requireDepthFloat,
00510         bool requireTexInt);
00512 
00514 
00515   static bool IsSupported(vtkOpenGLRenderWindow* renWin)
00516     { return vtkTextureObject::IsSupported(renWin, false, false, false); }
00518 
00520 
00523   void CopyToFrameBuffer(vtkShaderProgram *program,
00524                          vtkgl::VertexArrayObject *vao);
00525   // part of a texture to part of a viewport, scaling as needed
00526   void CopyToFrameBuffer(int srcXmin, int srcYmin,
00527                          int srcXmax, int srcYmax,
00528                          int dstXmin, int dstYmin,
00529                          int dstXmax, int dstYmax,
00530                          int dstSizeX, int dstSizeY,
00531                          vtkShaderProgram *program,
00532                          vtkgl::VertexArrayObject *vao
00533                          );
00534   // copy part of a texure to part of a viewport, no scalaing
00535   void CopyToFrameBuffer(int srcXmin, int srcYmin,
00536                          int srcXmax, int srcYmax,
00537                          int dstXmin, int dstYmin,
00538                          int dstSizeX, int dstSizeY,
00539                          vtkShaderProgram *program,
00540                          vtkgl::VertexArrayObject *vao
00541                          );
00542   // copy a texture to a quad using the provided tcoords and verts
00543   void CopyToFrameBuffer(float *tcoords, float *verts,
00544                          vtkShaderProgram *program,
00545                          vtkgl::VertexArrayObject *vao
00546                          );
00548 
00549 
00551 
00559   void CopyFromFrameBuffer(int srcXmin,
00560                            int srcYmin,
00561                            int dstXmin,
00562                            int dstYmin,
00563                            int width,
00564                            int height);
00566 
00567 
00568 
00569 protected:
00570   vtkTextureObject();
00571   ~vtkTextureObject();
00572 
00574   bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
00575 
00577   void CreateTexture();
00578 
00580   void DestroyTexture();
00581 
00582   int NumberOfDimensions;
00583   unsigned int Width;
00584   unsigned int Height;
00585   unsigned int Depth;
00586 
00587   unsigned int Target; // GLenum
00588   unsigned int Format; // GLenum
00589   unsigned int InternalFormat; // GLenum
00590   unsigned int Type; // GLenum
00591   int Components;
00592 
00593   vtkWeakPointer<vtkOpenGLRenderWindow> Context;
00594   unsigned int Handle;
00595   bool RequireTextureInteger;
00596   bool SupportsTextureInteger;
00597   bool RequireTextureFloat;
00598   bool SupportsTextureFloat;
00599   bool RequireDepthBufferFloat;
00600   bool SupportsDepthBufferFloat;
00601 
00602   int WrapS;
00603   int WrapT;
00604   int WrapR;
00605   int MinificationFilter;
00606   int MagnificationFilter;
00607   bool LinearMagnification;
00608 
00609   float MinLOD;
00610   float MaxLOD;
00611   int BaseLevel;
00612   int MaxLevel;
00613   float BorderColor[4];
00614 
00615   bool DepthTextureCompare;
00616   int DepthTextureCompareFunction;
00617 
00618   bool GenerateMipmap;
00619 
00620   int AutoParameters;
00621   vtkTimeStamp SendParametersTime;
00622 
00623   // used for copying to framebuffer
00624   vtkgl::CellBO *ShaderProgram;
00625 
00626 private:
00627   vtkTextureObject(const vtkTextureObject&); // Not implemented.
00628   void operator=(const vtkTextureObject&); // Not implemented.
00629 };
00630 
00631 #endif