00001
00002
00003
00004
00005
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
00017 class PBuffer;
00018
00019
00020 #ifdef WIN32
00021 typedef HGLRC PBuffRenCTX;
00022 typedef __int64 llong;
00023 #else
00024 typedef GLXContext PBuffRenCTX;
00025 #endif
00026
00027
00028 enum PbuffModes {
00029 PBUFF_NONE = 0,
00030 PBUFF_REND_TO_TEX = 1<<0,
00031 PBUFF_RECT = 1<<1,
00032 PBUFF_SHARE = 1<<2,
00033 PBUFF_SINGLE = 1<<3,
00034 PBUFF_DOUBLE = 1<<4,
00035 PBUFF_DEPTH16 = 1<<5,
00036 PBUFF_DEPTH24 = 1<<6,
00037 PBUFF_STENCIL = 1<<7,
00038 PBUFF_ACCUM = 1<<8,
00039 PBUFF_MIPMAP = 1<<9,
00040 PBUFF_CUBE = 1<<10,
00041 PBUFF_FIXED16 = 1<<11,
00042 PBUFF_FLOAT16 = 1<<12,
00043 PBUFF_FLOAT32 = 1<<13,
00044 PBUFF_AUX1 = 1<<14,
00045 PBUFF_AUX2 = 1<<15,
00046 PBUFF_AUX3 = 1<<16,
00047 PBUFF_AUX4 = 1<<17,
00048 PBUFF_AUX5 = 1<<18,
00049 PBUFF_AUX6 = 1<<19,
00050 PBUFF_AUX7 = 1<<20,
00051 PBUFF_AUX8 = 1<<21,
00052 PBUFF_PBUFF_LAST = 1<<22 };
00053
00054
00055
00056
00057 class PBuffer
00058 {
00059 public:
00060 PBuffer( int xDim, int yDim, unsigned int mode, PBuffRenCTX renderCTX=NULL );
00061
00062
00063 virtual ~PBuffer();
00064
00065
00066
00067 void enable(bool saveState=false);
00068 void disable();
00069
00070
00071 static void clearCache() { m_curPbuff = NULL;}
00072
00073
00074 static int numSurfaces( unsigned int mode );
00075
00076
00077 void bind();
00078 void release();
00079
00080
00081 void setSurface( GLenum surface );
00082
00083
00084 void setMipLevel( int level );
00085
00086
00087 void setCubeFace( GLenum cubeFace );
00088
00089
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
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
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;
00109 unsigned int m_mode;
00110 int m_numSurfaces;
00111 static PBuffer* m_curPbuff;
00112 GLenum m_surface;
00113 GLenum m_curBoundSurface;
00114
00115 #ifdef WIN32
00116 static llong m_totEnableTime;
00117 unsigned int m_format;
00118 HPBUFFERARB m_buffer;
00119 HDC m_devCTX;
00120 HGLRC m_renCTX;
00121 HDC m_saveDevCTX;
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
00130
00131
00132 #endif
00133
00134 int m_saveViewPort[4];
00135 int m_saveDrawBuff;
00136 int m_saveReadBuff;
00137
00138
00139 void initMembers( const int xDim, const int yDim, unsigned int mode, PBuffRenCTX);
00140 void create();
00141 void handleModeSwitch();
00142 };
00143
00144 #endif