00001
00002
00003
00004
00005
00006 #include <state/subPBuff.h>
00007 #include <iostream>
00008
00009 using namespace gutz;
00010 using namespace std;
00011
00012 namespace glift {
00013
00014 #ifndef NDEBUG
00015
00016 #endif
00017
00018 SubPBuff::SubPBuff( PBuffGlift* pbuff, GLenum surface )
00019 : PBuffGlift( pbuff->pbuff() ),
00020 m_origin( vec2i() ),
00021 m_dimen( pbuff->dimen() ),
00022 m_glSurface(surface ),
00023 m_wglSurface( getWglSurface(surface) )
00024 {}
00025
00026
00027 SubPBuff::SubPBuff( PBuffGlift* pbuff, const vec2i& origin, const vec2i& dimen, GLenum surface )
00028 : PBuffGlift( pbuff->pbuff() ),
00029 m_origin( origin ),
00030 m_dimen( dimen ),
00031 m_glSurface(surface),
00032 m_wglSurface( getWglSurface(surface) )
00033 {}
00034
00035 SubPBuff::~SubPBuff()
00036 {}
00037
00038
00039 GLenum SubPBuff::getWglSurface( GLenum glSurf )
00040 {
00041 GLenum wglSurf = 0;
00042 switch(glSurf) {
00043 case GL_FRONT_LEFT: wglSurf = WGL_FRONT_LEFT_ARB; break;
00044 case GL_FRONT_RIGHT:wglSurf = WGL_FRONT_RIGHT_ARB; break;
00045 case GL_BACK_LEFT: wglSurf = WGL_BACK_LEFT_ARB; break;
00046 case GL_BACK_RIGHT: wglSurf = WGL_BACK_RIGHT_ARB; break;
00047 case GL_AUX0: wglSurf = WGL_AUX0_ARB; break;
00048 case GL_AUX1: wglSurf = WGL_AUX1_ARB; break;
00049 case GL_AUX2: wglSurf = WGL_AUX2_ARB; break;
00050 case GL_AUX3: wglSurf = WGL_AUX3_ARB; break;
00051 case GL_FRONT:
00052 case GL_BACK:
00053 case GL_LEFT:
00054 case GL_RIGHT:
00055 case GL_FRONT_AND_BACK:
00056 err() << "getWglSurface(...) Error:\n\tCannot use multi-buffer surfaces(" << glSurf << ")\n";
00057 exit(1);
00058 default:
00059 err() << "getWglSurface(...) Error:\n\tUnrecognized GL surface (" << glSurf << ")\n";
00060 exit(1);
00061 };
00062
00063 return wglSurf;
00064 }
00065
00066 void SubPBuff::enable( bool saveState )
00067 {
00068 PBuffGlift::enable(saveState);
00069 glReadBuffer( m_glSurface );
00070 glDrawBuffer( m_glSurface );
00071 glViewport( m_origin.x, m_origin.y, m_dimen.x, m_dimen.y );
00072
00073 #ifndef NDEBUG
00074 #ifdef SPEW
00075 err << "enable(...) Info: orig = " << m_origin.x << ", " << m_origin.y
00076 << ", dim = " << m_dimen.x << ", " << m_dimen.y << endl;
00077 #endif
00078 #endif
00079 }
00080
00081 void SubPBuff::bindDef()
00082 {
00083 setSurface( m_wglSurface );
00084 PBuffGlift::bindDef();
00085 }
00086
00087 void SubPBuff::releaseDef()
00088 {
00089 setSurface( m_wglSurface );
00090 PBuffGlift::releaseDef();
00091 setSurface( WGL_FRONT_LEFT_ARB );
00092 }
00093
00094
00095 }