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) 2001 Sony Computer Entertainment America
00002                               All Rights Reserved
00003                                SCEA Confidential                                */
00004 
00005 #ifndef ps2gl_drawcontext_h
00006 #define ps2gl_drawcontext_h
00007 
00008 /********************************************
00009  * includes
00010  */
00011 
00012 #include "ps2s/cpu_matrix.h"
00013 
00014 #include "ps2gl/glcontext.h"
00015 #include "ps2gl/immgmanager.h"
00016 
00017 namespace GS {
00018    class CDrawEnv;
00019    class CMemArea;
00020 }
00021 
00022 /********************************************
00023  * CDrawContext
00024  */
00025 
00026 class CDrawContext {
00027    protected:
00028       CGLContext        &GLContext;
00029 
00030    public:
00031       inline CDrawContext( CGLContext &context ) : GLContext(context) {}
00032 
00033       virtual void SetDoSmoothShading( bool yesNo ) = 0;
00034       virtual void SetDoCullFace( bool cull ) = 0;
00035       virtual void SetCullFaceDir( int direction ) = 0;
00036       virtual void SetRescaleNormals( bool rescale ) = 0;
00037       virtual void SetBlendEnabled( bool enabled ) = 0;
00038       virtual void SetDepthWriteEnabled( bool enabled ) = 0;
00039       virtual void SetAlphaTestEnabled( bool enabled ) = 0;
00040 
00041       virtual void SetBlendMode( GLenum source, GLenum dest ) = 0;
00042       virtual void SetAlphaFunc( GLenum func, GLclampf ref ) = 0;
00043 
00044       virtual void SetDrawBuffers( GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00045                                    GS::CMemArea *depthMem ) = 0;
00046 };
00047 
00048 /********************************************
00049  * CImmDrawContext
00050  */
00051 
00052 class CClearEnv;
00053 
00054 class CImmDrawContext : public CDrawContext {
00055       GS::CDrawEnv      *DrawEnv;
00056 
00057       GS::CMemArea      *Frame0Mem, *Frame1Mem, *ZBufMem;
00058       GS::CMemArea      *CurFrameMem, *LastFrameMem;
00059 
00060       CClearEnv         *ClearEnv;
00061 
00062       bool              FrameIsDblBuffered;
00063 
00064       // gl state
00065       bool              DoSmoothShading;
00066       bool              DoCullFace;
00067       int               CullFaceDir; // 1 or -1
00068       bool              RescaleNormals;
00069       bool              BlendIsEnabled;
00070       bool              AlphaTestIsEnabled;
00071 
00072       // current vertex xform
00073       cpu_mat_44        VertexXform;
00074       cpu_mat_44        GSScale;
00075       bool              IsVertexXformValid;
00076 
00077    public:
00078       CImmDrawContext( CGLContext &context );
00079       virtual ~CImmDrawContext();
00080 
00081       GS::CDrawEnv& GetDrawEnv() { return *DrawEnv; }
00082       void SwapBuffers( bool fieldIsEven );
00083 
00084       inline CClearEnv& GetClearEnv() { return *ClearEnv; }
00085 
00086       const cpu_mat_44& GetVertexXform();
00087       inline void SetVertexXformValid( bool valid ) {
00088          IsVertexXformValid = valid;
00089          if ( ! valid ) GLContext.XformChanged();
00090       }
00091 
00092       // virtuals
00093 
00094       void SetBlendMode( GLenum source, GLenum dest );
00095       void SetAlphaFunc( GLenum func, GLclampf ref );
00096       
00097       inline bool GetDoSmoothShading() const { return DoSmoothShading; }
00098       void SetDoSmoothShading( bool yesNo );
00099 
00100       inline bool GetDoCullFace() const { return DoCullFace; }
00101       void SetDoCullFace( bool cull );
00102 
00103       inline int GetCullFaceDir() const { return CullFaceDir; }
00104       void SetCullFaceDir( int direction );
00105 
00106       inline bool GetBlendEnabled() const { return BlendIsEnabled; }
00107       void SetBlendEnabled( bool enabled );
00108 
00109       inline bool GetAlphaTestEnabled() const { return AlphaTestIsEnabled; }
00110       void SetAlphaTestEnabled( bool enabled );
00111       
00112       void SetDepthWriteEnabled( bool enabled );
00113 
00114       inline bool GetRescaleNormals() const { return RescaleNormals; }
00115       void SetRescaleNormals( bool rescale );
00116 
00117       void SetDrawBuffers( GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00118                            GS::CMemArea *depthMem );
00119 };
00120 
00121 /********************************************
00122  * CDListDrawContext
00123  */
00124 
00125 class CDListDrawContext : public CDrawContext {
00126    public:
00127       CDListDrawContext( CGLContext &context ) : CDrawContext(context) {}
00128 
00129       void SetBlendMode( GLenum source, GLenum dest );
00130       void SetAlphaFunc( GLenum func, GLclampf ref );
00131 
00132       void SetDoSmoothShading( bool yesNo );
00133       void SetDoCullFace( bool cull );
00134       void SetCullFaceDir( int direction );
00135       void SetRescaleNormals( bool rescale );
00136       void SetBlendEnabled( bool enabled );
00137       void SetAlphaTestEnabled( bool enabled );
00138       void SetDepthWriteEnabled( bool enabled );
00139 
00140 
00141       void SetDrawBuffers( GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00142                            GS::CMemArea *depthMem );
00143 };
00144 
00145 #endif // ps2gl_drawcontext_h

ps2gl version 0.2