arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

pbuffer.h

Go to the documentation of this file.
00001 /// 10/02/02    Aaron Lefohn    Scientific Computing and Imaging Institute      
00002 /// School of Computing                 University of Utah
00003 /// - Pbuffer class. 
00004 /// - This has only been tested on ATI Radeon 8500 (5/31/02)
00005 /// - This code based on a combination of code from ATI, Nvidia, Joe Kniss, and Milan Ikits
00006 
00007 #ifndef CHIMERA_PBUFFERS_H
00008 #define CHIMERA_PBUFFERS_H
00009 
00010 #include <GL/glew.h>
00011 #include <GL/wglew.h>
00012 #ifndef WIN32
00013 #include <GL/glx.h>
00014 #endif
00015 
00016 // Forward Decls
00017 class PBuffer;
00018 
00019 //we have different context types for win & linux
00020 #ifdef WIN32
00021 typedef HGLRC PBuffRenCTX;
00022 typedef __int64 llong;
00023 #else
00024 typedef GLXContext PBuffRenCTX;
00025 #endif
00026 
00027 // PBuffer Modes
00028 enum PbuffModes { 
00029    PBUFF_NONE             = 0,
00030    PBUFF_REND_TO_TEX = 1<<0, // Render-to-texture buffer
00031    PBUFF_RECT      = 1<<1,   // Rectangle (default is 2D)
00032    PBUFF_SHARE            = 1<<2,   // Share textures, display lists, vertex/frag programs, etc.
00033    PBUFF_SINGLE   = 1<<3,
00034    PBUFF_DOUBLE   = 1<<4,
00035    PBUFF_DEPTH16   = 1<<5,
00036    PBUFF_DEPTH24          = 1<<6, // Default is Depth16
00037    PBUFF_STENCIL          = 1<<7,
00038    PBUFF_ACCUM            = 1<<8, 
00039    PBUFF_MIPMAP   = 1<<9, // Mipmapped buffer
00040    PBUFF_CUBE             = 1<<10, // Cube map buffer
00041    PBUFF_FIXED16          = 1<<11, // 16-bit-per-channel Fixed-point buffer
00042    PBUFF_FLOAT16          = 1<<12, // 16-bit-per-channel Float buffer
00043    PBUFF_FLOAT32          = 1<<13,// 32-bit-per-channel Float buffer
00044    PBUFF_AUX1             = 1<<14,// 1 AUX buffer
00045    PBUFF_AUX2             = 1<<15,// 2 AUX buffers
00046    PBUFF_AUX3             = 1<<16,// 3 AUX buffers
00047    PBUFF_AUX4             = 1<<17,// 4 AUX buffers
00048    PBUFF_AUX5             = 1<<18,// 5 AUX buffers
00049    PBUFF_AUX6             = 1<<19,// 6  "   "
00050    PBUFF_AUX7             = 1<<20,// 7  "   "
00051    PBUFF_AUX8             = 1<<21,// 8  "   "
00052    PBUFF_PBUFF_LAST  = 1<<22 };
00053 
00054    ///////////////////////////////
00055    ///  PBuffer class
00056    ///////////////////////////////
00057    class PBuffer
00058    {
00059    public:
00060       PBuffer( int xDim, int yDim, unsigned int mode, PBuffRenCTX renderCTX=NULL ); 
00061       // Using default copy constructor and assignment operator
00062 
00063       virtual   ~PBuffer();
00064 
00065       // Enable/Disable pbuffer as a draw target
00066       // Disable will restore previous state if enable(true) was called.
00067       void enable(bool saveState=false);
00068       void disable();
00069 
00070       // Clear pbuffer caching
00071       static void clearCache() {        m_curPbuff = NULL;} 
00072 
00073       // How many surfaces are defined in 'mode'?
00074       static int  numSurfaces( unsigned int mode ); 
00075 
00076       // Bind/Release pbuffer as a texture
00077       void bind();
00078       void release();// WARNING: 'setSurface()' MUST be set to the correct surface!!!
00079 
00080       // Set WGL_FRONT_LEFT_ARB,        WGL_AUX0_ARB, etc.
00081       void setSurface( GLenum surface );
00082 
00083       // Set mip level that is rendered to. Default = 0
00084       void setMipLevel( int level );
00085 
00086       // Set    WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, etc. : Default = POSITIVE_X
00087       void setCubeFace( GLenum cubeFace );
00088 
00089       // Accessors
00090       void               dimen( int& xDim, int& yDim ) const {xDim=m_xDim; yDim=m_yDim;}
00091       unsigned int mode() const                                          {return m_mode;}
00092       PBuffRenCTX        renderCTX() const                                       {return m_renCTX;}
00093 
00094       // Convenience mode accessors
00095       bool              hasRendToTex()  const {return (m_mode & PBUFF_REND_TO_TEX) && true;     }
00096       bool              hasMipMap()             const {return (m_mode & PBUFF_MIPMAP) && true;          }
00097       bool              hasCube()               const {return (m_mode & PBUFF_CUBE) && true;            }
00098       int                       numSurfaces() const                              {return m_numSurfaces;}
00099 
00100       // Timer Calls
00101 #ifdef WIN32
00102       static void        resetTimer() {m_totEnableTime = 0; }
00103       static llong getTotEnableTime() {return m_totEnableTime;}
00104 #endif
00105    private:
00106       int                               m_xDim;
00107       int                               m_yDim;
00108       bool                      m_stateSaved; /// Has a state been saved?
00109       unsigned int      m_mode;           /// Flags indicating the type of pbuffer.
00110       int                               m_numSurfaces;/// Number of render surfaces in this pbuffer
00111       static PBuffer* m_curPbuff;   /// Used to avoid unneccesary ctxt switches
00112       GLenum                    m_surface;
00113       GLenum                    m_curBoundSurface;
00114 
00115 #ifdef WIN32
00116       static llong m_totEnableTime;
00117       unsigned int m_format;    /// The number of the visual used for the buffer
00118       HPBUFFERARB  m_buffer;    /// Handle to this pbuffer.
00119       HDC          m_devCTX;  /// Handle to this pbuff's device context.
00120       HGLRC        m_renCTX;  /// Handle to this pbuff's GL, render context.
00121       HDC                        m_saveDevCTX;  /// Saved state
00122       HGLRC              m_saveRenCTX;
00123       int setPixelFormat( HDC curDevCTX );
00124       int setPixelFormatNV_HACK( HDC curDevCTX );
00125 #else //linux & unix
00126       GLXPbuffer         m_buffer;
00127       Drawable   m_window;
00128       GLXContext   m_renCTX;
00129       //GLXFBConfig* mFBConfig;
00130       //GLXFBConfig* ChooseFBConfig (GLXFBConfig* config, int n,
00131       ///                             GLXFBConfig* config0, bool dbuff);
00132 #endif
00133 
00134       int       m_saveViewPort[4];
00135       int                       m_saveDrawBuff;
00136       int                       m_saveReadBuff;
00137 
00138       // Extract the number of render surfaces from the 'mode'
00139       void initMembers( const int xDim, const int yDim, unsigned int mode, PBuffRenCTX);
00140       void create();
00141       void handleModeSwitch(); /// Recover the pbuffer if it is killed by a mode change
00142    };
00143 
00144 #endif

Send questions, comments, and bug reports to:
jmk