VTK
dox/Rendering/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 =========================================================================*/
00025 #ifndef __vtkTextureObject_h
00026 #define __vtkTextureObject_h
00027 
00028 #include "vtkObject.h"
00029 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00030 
00031 class vtkRenderWindow;
00032 class vtkOpenGLExtensionManager;
00033 class vtkPixelBufferObject;
00034 
00035 class VTK_RENDERING_EXPORT vtkTextureObject : public vtkObject
00036 {
00037 public:
00038 
00039   //BTX
00040   // DepthTextureCompareFunction values.
00041   enum 
00042   {
00043     Lequal=0, // r=R<=Dt ? 1.0 : 0.0
00044     Gequal, // r=R>=Dt ? 1.0 : 0.0
00045     Less, // r=R<D_t ? 1.0 : 0.0
00046     Greater, // r=R>Dt ? 1.0 : 0.0
00047     Equal, // r=R==Dt ? 1.0 : 0.0
00048     NotEqual, // r=R!=Dt ? 1.0 : 0.0
00049     AlwaysTrue, //  r=1.0 // WARNING "Always" is macro defined in X11/X.h...
00050     Never, // r=0.0
00051     NumberOfDepthTextureCompareFunctions
00052   };
00053   
00054   // DepthTextureMode values.
00055   enum
00056   {
00057     Luminance=0, // (R,G,B,A)=(r,r,r,1)
00058     Intensity, // (R,G,B,A)=(r,r,r,r)
00059     Alpha, // (R.G.B.A)=(0,0,0,r)
00060     NumberOfDepthTextureModes
00061   };
00062   
00063   // Wrap values.
00064   enum
00065   {
00066     Clamp=0,
00067     ClampToEdge,
00068     Repeat,
00069     ClampToBorder,
00070     MirroredRepeat,
00071     NumberOfWrapModes
00072   };
00073   
00074   // MinificationFilter values.
00075   enum
00076   {
00077     Nearest=0,
00078     Linear,
00079     NearestMipmapNearest,
00080     NearestMipmapLinear,
00081     LinearMipmapNearest,
00082     LinearMipmapLinear,
00083     NumberOfMinificationModes
00084   };
00085   
00086   // Internal depth format
00087   enum
00088   {
00089     Native=0, // will try to match with the depth buffer format.
00090     Fixed16,
00091     Fixed24,
00092     Fixed32,
00093     Float32,
00094     NumberOfDepthFormats
00095   };
00096   
00097   //ETX
00098   
00099   static vtkTextureObject* New();
00100   vtkTypeMacro(vtkTextureObject, vtkObject);
00101   void PrintSelf(ostream& os, vtkIndent indent);
00102 
00104 
00108   void SetContext(vtkRenderWindow*);
00109   vtkRenderWindow* GetContext();
00111 
00113 
00115   vtkGetMacro(Width, unsigned int);
00116   vtkGetMacro(Height, unsigned int);
00117   vtkGetMacro(Depth, unsigned int);
00118   vtkGetMacro(Components, int);
00120 
00121   vtkGetMacro(NumberOfDimensions, int);
00122 
00124 
00125   vtkGetMacro(Target, unsigned int);
00127 
00129 
00130   vtkGetMacro(Handle, unsigned int);
00132 
00134 
00136   void Bind();
00137   void UnBind();
00139 
00142   bool IsBound();
00143   
00146   void SendParameters();
00147   
00149 
00156   bool Create1D(int numComps,
00157                 vtkPixelBufferObject *pbo,
00158                 bool shaderSupportsTextureInt);
00160 
00162 
00165   bool Create2D(unsigned int width, unsigned int height, int numComps,
00166                 vtkPixelBufferObject *pbo,
00167                 bool shaderSupportsTextureInt);
00169 
00171 
00173   bool CreateDepth(unsigned int width,
00174                    unsigned int height,
00175                    int internalFormat,
00176                    vtkPixelBufferObject *pbo);
00178   
00180 
00182   bool CreateDepthFromRaw(unsigned int width,
00183                           unsigned int height,
00184                           int internalFormat,
00185                           int rawType,
00186                           void *raw);
00188   
00190 
00191   bool AllocateDepth(unsigned int width,unsigned int height,
00192                      int internalFormat);
00194   
00197   bool Allocate1D(unsigned int width, int numComps,int vtkType);
00198   
00200 
00202   bool Allocate2D(unsigned int width,unsigned int height, int numComps,
00203                   int vtkType);
00205   
00207 
00209   bool Allocate3D(unsigned int width,unsigned int height,
00210                   unsigned int depth, int numComps,
00211                   int vtkType);
00213   
00214   
00216 
00219   bool Create3D(unsigned int width, unsigned int height, unsigned int depth, 
00220                 int numComps, vtkPixelBufferObject *pbo,
00221                 bool shaderSupportsTextureInt);
00223 
00224 
00226 
00229   bool Create2D(unsigned int width, unsigned int height, int numComps,
00230                 int vtktype,
00231                 bool shaderSupportsTextureInt);
00232   bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
00233                 int numComps, int vtktype,
00234                 bool shaderSupportsTextureInt);
00236 
00241   vtkPixelBufferObject* Download();
00242 
00244   int GetDataType();
00245 
00246   unsigned int GetInternalFormat(int vtktype, int numComps,
00247                                  bool shaderSupportsTextureInt);
00248   unsigned int GetFormat(int vtktype, int numComps,
00249                          bool shaderSupportsTextureInt);
00250   
00252 
00255   vtkGetMacro(WrapS,int);
00256   vtkSetMacro(WrapS,int);
00258   
00260 
00263   vtkGetMacro(WrapT,int);
00264   vtkSetMacro(WrapT,int);
00266   
00268 
00271   vtkGetMacro(WrapR,int);
00272   vtkSetMacro(WrapR,int);
00274   
00276 
00281   vtkGetMacro(MinificationFilter,int);
00282   vtkSetMacro(MinificationFilter,int);
00284   
00286 
00288   vtkGetMacro(LinearMagnification,bool);
00289   vtkSetMacro(LinearMagnification,bool);
00291   
00293 
00295   vtkSetVector4Macro(BorderColor,float);
00296   vtkGetVector4Macro(BorderColor,float);
00298   
00300 
00303   vtkSetMacro(Priority,float);
00304   vtkGetMacro(Priority,float);
00306   
00308 
00310   vtkSetMacro(MinLOD,float);
00311   vtkGetMacro(MinLOD,float);
00313   
00315 
00317   vtkSetMacro(MaxLOD,float);
00318   vtkGetMacro(MaxLOD,float);
00320   
00322 
00325   vtkSetMacro(BaseLevel,int);
00326   vtkGetMacro(BaseLevel,int);
00328   
00330 
00333   vtkSetMacro(MaxLevel,int);
00334   vtkGetMacro(MaxLevel,int);
00336   
00338 
00344   vtkGetMacro(DepthTextureCompare,bool);
00345   vtkSetMacro(DepthTextureCompare,bool);
00347   
00349 
00359   vtkGetMacro(DepthTextureCompareFunction,int);
00360   vtkSetMacro(DepthTextureCompareFunction,int);
00362   
00364 
00369   vtkGetMacro(DepthTextureMode,int);
00370   vtkSetMacro(DepthTextureMode,int);
00372   
00374 
00376   vtkGetMacro(GenerateMipmap,bool);
00377   vtkSetMacro(GenerateMipmap,bool);
00379   
00381   static bool IsSupported(vtkRenderWindow* renWin);
00382   
00384 
00403   void CopyToFrameBuffer(int srcXmin,
00404                          int srcYmin,
00405                          int srcXmax,
00406                          int srcYmax,
00407                          int dstXmin,
00408                          int dstYmin,
00409                          int width,
00410                          int height);
00412   
00413   
00415 
00423   void CopyFromFrameBuffer(int srcXmin,
00424                            int srcYmin,
00425                            int dstXmin,
00426                            int dstYmin,
00427                            int width,
00428                            int height);
00430   
00431   
00432 //BTX
00433 protected:
00434   vtkTextureObject();
00435   ~vtkTextureObject();
00436 
00438   bool LoadRequiredExtensions(vtkOpenGLExtensionManager*);
00439 
00441   void CreateTexture();
00442 
00444   void DestroyTexture();
00445   
00446   int NumberOfDimensions;
00447   unsigned int Width;
00448   unsigned int Height;
00449   unsigned int Depth;
00450 
00451   unsigned int Target; // GLenum
00452   unsigned int Format; // GLenum
00453   unsigned int Type; // GLenum
00454   int Components;
00455 
00456   vtkWeakPointer<vtkRenderWindow> Context;
00457   unsigned int Handle;
00458   bool SupportsTextureInteger;
00459   bool SupportsTextureFloat;
00460 
00461   int WrapS;
00462   int WrapT;
00463   int WrapR;
00464   int MinificationFilter;
00465   bool LinearMagnification;
00466   float BorderColor[4];
00467   
00468   float Priority;
00469   float MinLOD;
00470   float MaxLOD;
00471   int BaseLevel;
00472   int MaxLevel;
00473   
00474   
00475   bool DepthTextureCompare;
00476   int DepthTextureCompareFunction;
00477   int DepthTextureMode;
00478   
00479   bool GenerateMipmap;
00480   
00481   vtkTimeStamp SendParametersTime;
00482   
00483 private:
00484   vtkTextureObject(const vtkTextureObject&); // Not implemented.
00485   void operator=(const vtkTextureObject&); // Not implemented.
00486 //ETX
00487 };
00488 
00489 #endif
00490 
00491