Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

drawcontext.h

Go to the documentation of this file.
00001 /*        Copyright (C) 2000,2001,2002  Sony Computer Entertainment America
00002           
00003           This file is subject to the terms and conditions of the GNU Lesser
00004           General Public License Version 2.1. See the file "COPYING" in the
00005           main directory of this archive for more details.                             */
00006 
00007 #ifndef ps2gl_drawcontext_h
00008 #define ps2gl_drawcontext_h
00009 
00010 /********************************************
00011  * includes
00012  */
00013 
00014 #include "ps2s/cpu_matrix.h"
00015 
00016 #include "ps2gl/glcontext.h"
00017 #include "ps2gl/immgmanager.h"
00018 
00019 namespace GS {
00020    class CDrawEnv;
00021    class CMemArea;
00022 }
00023 
00024 /********************************************
00025  * CDrawContext
00026  */
00027 
00028 class CDrawContext {
00029    protected:
00030       CGLContext        &GLContext;
00031 
00032    public:
00033       inline CDrawContext( CGLContext &context ) : GLContext(context) {}
00034 
00035       virtual void SetDoSmoothShading( bool yesNo ) = 0;
00036       virtual void SetDoClipping( bool clip ) = 0;
00037       virtual void SetDoCullFace( bool cull ) = 0;
00038       virtual void SetCullFaceDir( int direction ) = 0;
00039       virtual void SetRescaleNormals( bool rescale ) = 0;
00040       virtual void SetBlendEnabled( bool enabled ) = 0;
00041       virtual void SetDepthWriteEnabled( bool enabled ) = 0;
00042       virtual void SetFrameBufferDrawMask(unsigned int mask)=0;
00043       virtual void SetAlphaTestEnabled( bool enabled ) = 0;
00044       virtual void SetInterlacingOffset( float yPixels ) = 0;
00045       virtual void SetPolygonMode( GLenum mode ) = 0;
00046 
00047       virtual void SetBlendMode( GLenum source, GLenum dest ) = 0;
00048       virtual void SetAlphaFunc( GLenum func, GLclampf ref ) = 0;
00049 
00050       virtual void SetDrawBuffers( bool interlaced,
00051                                    GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00052                                    GS::CMemArea *depthMem ) = 0;
00053 };
00054 
00055 /********************************************
00056  * CImmDrawContext
00057  */
00058 
00059 class CClearEnv;
00060 
00061 class CImmDrawContext : public CDrawContext {
00062    public:
00063       GS::CDrawEnv      *DrawEnv;
00064 
00065       GS::CMemArea      *Frame0Mem, *Frame1Mem, *ZBufMem;
00066       GS::CMemArea      *CurFrameMem, *LastFrameMem;
00067 
00068       CClearEnv         *ClearEnv;
00069 
00070       bool              FrameIsDblBuffered;
00071 
00072       // gl state
00073       bool              DoSmoothShading;
00074       bool              DoClipping;
00075       bool              DoCullFace;
00076       int               CullFaceDir; // 1 or -1
00077       bool              RescaleNormals;
00078       bool              BlendIsEnabled;
00079       bool              AlphaTestIsEnabled;
00080       bool              DrawInterlaced;
00081       GLenum            PolyMode;
00082       int               DepthBits;
00083 
00084       // current vertex xform
00085       cpu_mat_44        VertexXform;
00086       cpu_mat_44        GSScale;
00087       bool              IsVertexXformValid;
00088 
00089       int               Width, Height;
00090 
00091    public:
00092       CImmDrawContext( CGLContext &context );
00093       virtual ~CImmDrawContext();
00094 
00095       GS::CDrawEnv& GetDrawEnv() { return *DrawEnv; }
00096       void SwapBuffers( bool fieldIsEven );
00097 
00098       inline CClearEnv& GetClearEnv() { return *ClearEnv; }
00099 
00100       const cpu_mat_44& GetVertexXform();
00101       inline void SetVertexXformValid( bool valid ) {
00102          IsVertexXformValid = valid;
00103          if ( ! valid ) GLContext.XformChanged();
00104       }
00105 
00106       int GetFBWidth() const { return Width; }
00107       int GetFBHeight() const { return Height; }
00108 
00109       int GetDepthBits() const { return DepthBits; }
00110       void SetDepthBits( int depth ) { DepthBits = depth; }
00111 
00112       // virtuals
00113 
00114       void SetBlendMode( GLenum source, GLenum dest );
00115       void SetAlphaFunc( GLenum func, GLclampf ref );
00116       
00117       inline bool GetDoSmoothShading() const { return DoSmoothShading; }
00118       void SetDoSmoothShading( bool yesNo );
00119 
00120       inline bool GetDoClipping() const { return DoClipping; }
00121       void SetDoClipping( bool clip );
00122 
00123       inline bool GetDoCullFace() const { return DoCullFace; }
00124       void SetDoCullFace( bool cull );
00125 
00126       inline int GetCullFaceDir() const { return CullFaceDir; }
00127       void SetCullFaceDir( int direction );
00128 
00129       inline bool GetBlendEnabled() const { return BlendIsEnabled; }
00130       void SetBlendEnabled( bool enabled );
00131 
00132       inline bool GetAlphaTestEnabled() const { return AlphaTestIsEnabled; }
00133       void SetAlphaTestEnabled( bool enabled );
00134 
00135       void SetInterlacingOffset( float yPixels );
00136       
00137       void SetDepthWriteEnabled( bool enabled );
00138       void SetFrameBufferDrawMask(unsigned int mask);
00139 
00140       inline GLenum GetPolygonMode() const { return PolyMode; }
00141       void SetPolygonMode( GLenum mode );
00142 
00143       inline bool GetRescaleNormals() const { return RescaleNormals; }
00144       void SetRescaleNormals( bool rescale );
00145 
00146       void SetDrawBuffers( bool interlaced,
00147                            GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00148                            GS::CMemArea *depthMem );
00149 };
00150 
00151 /********************************************
00152  * CDListDrawContext
00153  */
00154 
00155 class CDListDrawContext : public CDrawContext {
00156    public:
00157       CDListDrawContext( CGLContext &context ) : CDrawContext(context) {}
00158 
00159       void SetBlendMode( GLenum source, GLenum dest );
00160       void SetAlphaFunc( GLenum func, GLclampf ref );
00161 
00162       void SetDoSmoothShading( bool yesNo );
00163       void SetDoClipping( bool clip );
00164       void SetDoCullFace( bool cull );
00165       void SetCullFaceDir( int direction );
00166       void SetRescaleNormals( bool rescale );
00167       void SetBlendEnabled( bool enabled );
00168       void SetAlphaTestEnabled( bool enabled );
00169       void SetInterlacingOffset( float yPixels );
00170       void SetDepthWriteEnabled( bool enabled );
00171       void SetFrameBufferDrawMask(unsigned int mask);
00172       void SetPolygonMode( GLenum mode ) { assert(false); }
00173 
00174 
00175       void SetDrawBuffers( bool interlaced,
00176                            GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00177                            GS::CMemArea *depthMem );
00178 };
00179 
00180 #endif // ps2gl_drawcontext_h

ps2gl version cvs