VTK
dox/Rendering/OpenGL/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 "vtkRenderingOpenGLModule.h" // For export macro
00029 #include "vtkObject.h"
00030 #include "vtkWeakPointer.h" // for render context
00031 
00032 class vtkFloatArray;
00033 class vtkTextureObject;
00034 class vtkRenderWindow;
00035 class vtkOpenGLRenderWindow;
00036 class vtkOpenGLExtensionManager;
00037 class vtkPixelBufferObject;
00038 
00039 class VTKRENDERINGOPENGL_EXPORT vtkTextureObject : public vtkObject
00040 {
00041 public:
00042 
00043   //BTX
00044   // DepthTextureCompareFunction values.
00045   enum
00046   {
00047     Lequal=0, // r=R<=Dt ? 1.0 : 0.0
00048     Gequal, // r=R>=Dt ? 1.0 : 0.0
00049     Less, // r=R<D_t ? 1.0 : 0.0
00050     Greater, // r=R>Dt ? 1.0 : 0.0
00051     Equal, // r=R==Dt ? 1.0 : 0.0
00052     NotEqual, // r=R!=Dt ? 1.0 : 0.0
00053     AlwaysTrue, //  r=1.0 // WARNING "Always" is macro defined in X11/X.h...
00054     Never, // r=0.0
00055     NumberOfDepthTextureCompareFunctions
00056   };
00057 
00058   // DepthTextureMode values.
00059   enum
00060   {
00061     Luminance=0, // (R,G,B,A)=(r,r,r,1)
00062     Intensity, // (R,G,B,A)=(r,r,r,r)
00063     Alpha, // (R.G.B.A)=(0,0,0,r)
00064     NumberOfDepthTextureModes
00065   };
00066 
00067   // Wrap values.
00068   enum
00069   {
00070     Clamp=0,
00071     ClampToEdge,
00072     Repeat,
00073     ClampToBorder,
00074     MirroredRepeat,
00075     NumberOfWrapModes
00076   };
00077 
00078   // MinificationFilter values.
00079   enum
00080   {
00081     Nearest=0,
00082     Linear,
00083     NearestMipmapNearest,
00084     NearestMipmapLinear,
00085     LinearMipmapNearest,
00086     LinearMipmapLinear,
00087     NumberOfMinificationModes
00088   };
00089 
00090   // Internal depth format
00091   enum
00092   {
00093     Native=0, // will try to match with the depth buffer format.
00094     Fixed16,
00095     Fixed24,
00096     Fixed32,
00097     Float32,
00098     NumberOfDepthFormats
00099   };
00100 
00101   //ETX
00102 
00103   static vtkTextureObject* New();
00104   vtkTypeMacro(vtkTextureObject, vtkObject);
00105   void PrintSelf(ostream& os, vtkIndent indent);
00106 
00108 
00112   void SetContext(vtkRenderWindow*);
00113   vtkRenderWindow* GetContext();
00115 
00117 
00119   vtkGetMacro(Width, unsigned int);
00120   vtkGetMacro(Height, unsigned int);
00121   vtkGetMacro(Depth, unsigned int);
00122   vtkGetMacro(Components, int);
00123   unsigned int GetTuples()
00124   { return this->Width*this->Height*this->Depth; }
00126 
00127   vtkGetMacro(NumberOfDimensions, int);
00128 
00130 
00131   vtkGetMacro(Target, unsigned int);
00133 
00135 
00136   vtkGetMacro(Handle, unsigned int);
00138 
00140 
00143   void Bind();
00144   void UnBind();
00146 
00148 
00149   void Activate(unsigned int texUnit);
00150   void Deactivate(unsigned int texUnit);
00152 
00153 
00156   bool IsBound();
00157 
00159 
00162   void SendParameters();
00163   vtkSetMacro(AutoParameters, int);
00164   vtkGetMacro(AutoParameters, int);
00166 
00168 
00175   bool Create1D(int numComps,
00176                 vtkPixelBufferObject *pbo,
00177                 bool shaderSupportsTextureInt);
00179 
00181 
00184   bool Create2D(unsigned int width, unsigned int height, int numComps,
00185                 vtkPixelBufferObject *pbo,
00186                 bool shaderSupportsTextureInt);
00188 
00190 
00192   bool CreateDepth(unsigned int width,
00193                    unsigned int height,
00194                    int internalFormat,
00195                    vtkPixelBufferObject *pbo);
00197 
00199 
00201   bool CreateDepthFromRaw(unsigned int width,
00202                           unsigned int height,
00203                           int internalFormat,
00204                           int rawType,
00205                           void *raw);
00207 
00209 
00210   bool AllocateDepth(unsigned int width,unsigned int height,
00211                      int internalFormat);
00213 
00216   bool Allocate1D(unsigned int width, int numComps,int vtkType);
00217 
00219 
00221   bool Allocate2D(unsigned int width,unsigned int height, int numComps,
00222                   int vtkType);
00224 
00226 
00228   bool Allocate3D(unsigned int width,unsigned int height,
00229                   unsigned int depth, int numComps,
00230                   int vtkType);
00232 
00233 
00235 
00238   bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
00239                 int numComps, vtkPixelBufferObject *pbo,
00240                 bool shaderSupportsTextureInt);
00242 
00243 
00245 
00248   bool Create2D(unsigned int width, unsigned int height, int numComps,
00249                 int vtktype,
00250                 bool shaderSupportsTextureInt);
00251   bool Create3D(unsigned int width, unsigned int height, unsigned int depth,
00252                 int numComps, int vtktype,
00253                 bool shaderSupportsTextureInt);
00255 
00260   vtkPixelBufferObject* Download();
00261 
00263   int GetDataType();
00264 
00265   unsigned int GetInternalFormat(int vtktype, int numComps,
00266                                  bool shaderSupportsTextureInt);
00267   unsigned int GetFormat(int vtktype, int numComps,
00268                          bool shaderSupportsTextureInt);
00269 
00271 
00274   vtkSetMacro(RequireDepthBufferFloat, bool);
00275   vtkGetMacro(RequireDepthBufferFloat, bool);
00276   vtkGetMacro(SupportsDepthBufferFloat, bool);
00278 
00280 
00283   vtkSetMacro(RequireTextureFloat,bool);
00284   vtkGetMacro(RequireTextureFloat,bool);
00285   vtkGetMacro(SupportsTextureFloat,bool);
00287 
00289 
00292   vtkSetMacro(RequireTextureInteger,bool);
00293   vtkGetMacro(RequireTextureInteger,bool);
00294   vtkGetMacro(SupportsTextureInteger,bool);
00296 
00298 
00301   vtkGetMacro(WrapS,int);
00302   vtkSetMacro(WrapS,int);
00304 
00306 
00309   vtkGetMacro(WrapT,int);
00310   vtkSetMacro(WrapT,int);
00312 
00314 
00317   vtkGetMacro(WrapR,int);
00318   vtkSetMacro(WrapR,int);
00320 
00322 
00327   vtkGetMacro(MinificationFilter,int);
00328   vtkSetMacro(MinificationFilter,int);
00330 
00332 
00334   vtkGetMacro(MagnificationFilter,int);
00335   vtkSetMacro(MagnificationFilter,int);
00337 
00339 
00341   void SetLinearMagnification(bool val)
00342   { this->SetMagnificationFilter(val?Linear:Nearest); }
00344 
00345   bool GetLinearMagnification()
00346   { return this->MagnificationFilter==Linear; }
00347 
00349 
00352   vtkSetVector4Macro(BorderColor,float);
00353   vtkGetVector4Macro(BorderColor,float);
00355 
00357 
00360   vtkSetMacro(Priority,float);
00361   vtkGetMacro(Priority,float);
00363 
00365 
00367   vtkSetMacro(MinLOD,float);
00368   vtkGetMacro(MinLOD,float);
00370 
00372 
00374   vtkSetMacro(MaxLOD,float);
00375   vtkGetMacro(MaxLOD,float);
00377 
00379 
00382   vtkSetMacro(BaseLevel,int);
00383   vtkGetMacro(BaseLevel,int);
00385 
00387 
00390   vtkSetMacro(MaxLevel,int);
00391   vtkGetMacro(MaxLevel,int);
00393 
00395 
00401   vtkGetMacro(DepthTextureCompare,bool);
00402   vtkSetMacro(DepthTextureCompare,bool);
00404 
00406 
00416   vtkGetMacro(DepthTextureCompareFunction,int);
00417   vtkSetMacro(DepthTextureCompareFunction,int);
00419 
00421 
00426   vtkGetMacro(DepthTextureMode,int);
00427   vtkSetMacro(DepthTextureMode,int);
00429 
00431 
00433   vtkGetMacro(GenerateMipmap,bool);
00434   vtkSetMacro(GenerateMipmap,bool);
00436 
00438 
00441   static bool IsSupported(
00442         vtkRenderWindow* renWin,
00443         bool requireTexFloat,
00444         bool requireDepthFloat,
00445         bool requireTexInt);
00447 
00449 
00450   static bool IsSupported(vtkRenderWindow* renWin)
00451     { return vtkTextureObject::IsSupported(renWin, false, false, false); }
00453 
00455 
00474   void CopyToFrameBuffer(int srcXmin,
00475                          int srcYmin,
00476                          int srcXmax,
00477                          int srcYmax,
00478                          int dstXmin,
00479                          int dstYmin,
00480                          int width,
00481                          int height);
00483 
00484 
00486 
00494   void CopyFromFrameBuffer(int srcXmin,
00495                            int srcYmin,
00496                            int dstXmin,
00497                            int dstYmin,
00498                            int width,
00499                            int height);
00501 
00502 
00503 
00504 //BTX
00505 protected:
00506   vtkTextureObject();
00507   ~vtkTextureObject();
00508 
00510   bool LoadRequiredExtensions(vtkRenderWindow *renWin);
00511 
00513   void CreateTexture();
00514 
00516   void DestroyTexture();
00517 
00518   int NumberOfDimensions;
00519   unsigned int Width;
00520   unsigned int Height;
00521   unsigned int Depth;
00522 
00523   unsigned int Target; // GLenum
00524   unsigned int Format; // GLenum
00525   unsigned int Type; // GLenum
00526   int Components;
00527 
00528   vtkWeakPointer<vtkRenderWindow> Context;
00529   unsigned int Handle;
00530   bool RequireTextureInteger;
00531   bool SupportsTextureInteger;
00532   bool RequireTextureFloat;
00533   bool SupportsTextureFloat;
00534   bool RequireDepthBufferFloat;
00535   bool SupportsDepthBufferFloat;
00536 
00537   int WrapS;
00538   int WrapT;
00539   int WrapR;
00540   int MinificationFilter;
00541   int MagnificationFilter;
00542   bool LinearMagnification;
00543   float BorderColor[4];
00544 
00545   float Priority;
00546   float MinLOD;
00547   float MaxLOD;
00548   int BaseLevel;
00549   int MaxLevel;
00550 
00551 
00552   bool DepthTextureCompare;
00553   int DepthTextureCompareFunction;
00554   int DepthTextureMode;
00555 
00556   bool GenerateMipmap;
00557 
00558   int AutoParameters;
00559   vtkTimeStamp SendParametersTime;
00560 
00561 private:
00562   vtkTextureObject(const vtkTextureObject&); // Not implemented.
00563   void operator=(const vtkTextureObject&); // Not implemented.
00564 //ETX
00565 };
00566 
00567 #endif