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

gmanager.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_gmanager_h
00008 #define ps2gl_gmanager_h
00009 
00010 #include "GL/gl.h"
00011 #include "ps2s/packet.h"
00012 #include "ps2s/gs.h"
00013 #include "ps2s/cpu_vector.h"
00014 #include "ps2s/cpu_matrix.h"
00015 
00016 #include "ps2gl/renderermanager.h"
00017 #include "ps2gl/gblock.h"
00018 
00019 /********************************************
00020  * constants
00021  */
00022 
00023 /********************************************
00024  * CVertArray
00025  */
00026 
00027 class CVertArray {
00028       void              *Vertices, *Normals, *TexCoords, *Colors;
00029       bool              VerticesAreValid, NormalsAreValid, TexCoordsAreValid, ColorsAreValid;
00030       char              WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
00031 
00032    public:
00033       CVertArray();
00034 
00035       inline bool GetVerticesAreValid() const { return VerticesAreValid; }
00036       inline bool GetNormalsAreValid() const { return NormalsAreValid; }
00037       inline bool GetTexCoordsAreValid() const { return TexCoordsAreValid; }
00038       inline bool GetColorsAreValid() const { return ColorsAreValid; }
00039 
00040       inline void SetVerticesValid( bool valid ) { VerticesAreValid = valid; }
00041       inline void SetNormalsValid( bool valid ) { NormalsAreValid = valid; }
00042       inline void SetTexCoordsValid( bool valid ) { TexCoordsAreValid = valid; }
00043       inline void SetColorsValid( bool valid ) { ColorsAreValid = valid; }
00044 
00045 
00046       inline void* GetVertices() const { return Vertices; }
00047       inline void* GetNormals() const { return Normals; }
00048       inline void* GetTexCoords() const { return TexCoords; }
00049       inline void* GetColors() const { return Colors; }
00050 
00051       inline void SetVertices( void *newPtr ) { Vertices = newPtr; }
00052       inline void SetNormals( void *newPtr ) { Normals = newPtr; }
00053       inline void SetTexCoords( void *newPtr ) { TexCoords = newPtr; }
00054       inline void SetColors( void *newPtr ) { Colors = newPtr; }
00055 
00056 
00057       inline int GetWordsPerVertex() const { return WordsPerVertex; }
00058       inline int GetWordsPerNormal() const { return WordsPerNormal; }
00059       inline int GetWordsPerTexCoord() const { return WordsPerTexCoord; }
00060       inline int GetWordsPerColor() const { return WordsPerColor; }
00061 
00062       inline void SetWordsPerVertex( int numWords ) { WordsPerVertex = numWords; }
00063       inline void SetWordsPerNormal( int numWords ) { WordsPerNormal = numWords; }
00064       inline void SetWordsPerTexCoord( int numWords ) { WordsPerTexCoord = numWords; }
00065       inline void SetWordsPerColor( int numWords ) { WordsPerColor = numWords; }
00066 
00067 //        // for indexed arrays only
00068 
00069 //        inline void SetIndices( void *newPtr ) { Indices = newPtr; }
00070 //        inline void SetStripLengths( void *newPtr ) { StripLengths = newPtr; }
00071 //        inline void SetNumIndices( int num ) { NumIndices = num; }
00072 //        inline void SetNumStrips( int num ) { NumStrips = num; }
00073 
00074 //        inline void* GetIndices() { return Indices; }
00075 //        inline void* GetStripLengths() { return StripLengths; }
00076 //        inline int GetNumIndices() { return NumIndices; }
00077 //        inline int GetNumStrips() { return NumStrips; }
00078 };
00079 
00080 /********************************************
00081  * types
00082  */
00083 
00084 typedef struct {
00085       tU64      requirements;
00086       tU64      rendererReqMask;
00087       bool      mergeContiguous;
00088 } tUserPrimEntry;
00089 
00090 /********************************************
00091  * CGeomManager - contains code common to the display list and immediate renderers
00092  */
00093 
00094 class CVifSCDmaPacket;
00095 class CGLContext;
00096 class CDList;
00097 
00098 class CGeomManager {
00099    protected:
00100       CGLContext                &GLContext;
00101 
00102       // vertex array geometry
00103       static CVertArray         *VertArray;
00104 
00105       static const unsigned int kMaxUserPrimTypes = PGL_MAX_CUSTOM_PRIM_TYPES;
00106       static tUserPrimEntry     UserPrimTypes[kMaxUserPrimTypes];
00107 
00108       // GL state
00109       cpu_vec_xyz               CurNormal;
00110       float                     CurTexCoord[2];
00111       static bool               DoNormalize;
00112 
00113       GLenum                    Prim;
00114 
00115       bool                      InsideBeginEnd;
00116 
00117       bool                      LastArrayAccessWasIndexed, LastArrayAccessIsValid;
00118 
00119       bool                      UserRenderContextChanged;
00120 
00121       static inline void CheckPrimAccess( GLenum prim ) {
00122          prim &= 0x7fffffff;
00123          mErrorIf( prim >= kMaxUserPrimTypes,
00124                    "trying to access prim %d; max number of custom prim types is %d\n",
00125                    prim, kMaxUserPrimTypes );
00126       }
00127 
00128    public:
00129       CGeomManager( CGLContext &context );
00130 
00131       // user prim types
00132 
00133       static inline bool IsUserPrimType( unsigned int prim ) { return (prim & 0x80000000); }
00134 
00135       static inline void RegisterUserPrimType( GLenum prim,
00136                                                tU64 requirements,
00137                                                tU64 rendererReqMask,
00138                                                bool mergeContiguous ) {
00139          CheckPrimAccess(prim);
00140          prim &= 0x7fffffff;
00141          UserPrimTypes[prim].requirements = requirements;
00142          UserPrimTypes[prim].rendererReqMask = rendererReqMask;
00143          UserPrimTypes[prim].mergeContiguous = mergeContiguous;
00144       }
00145 
00146       static inline tU64 GetUserPrimRequirements( GLenum prim ) {
00147          CheckPrimAccess(prim);
00148          prim &= 0x7fffffff;
00149          return UserPrimTypes[prim].requirements;
00150       }
00151 
00152       static inline bool GetUserPrimMerge( GLenum prim ) {
00153          CheckPrimAccess(prim);
00154          prim &= 0x7fffffff;
00155          return UserPrimTypes[prim].mergeContiguous;
00156       }
00157 
00158       static inline tU64 GetUserPrimReqMask( GLenum prim ) {
00159          CheckPrimAccess(prim);
00160          prim &= 0x7fffffff;
00161          return UserPrimTypes[prim].rendererReqMask;
00162       }
00163 
00164       void SetUserRenderContextChanged() { UserRenderContextChanged = true; }
00165 
00166       // GL state
00167 
00168       inline cpu_vec_xyz GetCurNormal() const { return CurNormal; }
00169       inline void SetCurNormal( cpu_vec_xyz normal ) { CurNormal = normal; }
00170 
00171       inline const float* GetCurTexCoord() const { return CurTexCoord; }
00172       inline void SetCurTexCoord( float u, float v ) {
00173          CurTexCoord[0] = u; CurTexCoord[1] = v;
00174       }
00175 
00176       // we're not really supporting this
00177       void SetDoNormalize( bool normalize ) { DoNormalize = normalize; }
00178 
00179       inline CVertArray& GetVertArray() { return *VertArray; }
00180 
00181       // user state
00182 
00183       virtual void EnableCustom( tU64 flag ) = 0;
00184       virtual void DisableCustom( tU64 flag ) = 0;
00185 
00186       // rendering interface
00187 
00188       virtual void BeginGeom( GLenum mode ) = 0;
00189       virtual void Vertex( cpu_vec_xyzw newVert ) = 0;
00190       virtual void Normal( cpu_vec_xyz normal ) = 0;
00191       virtual void TexCoord( float u, float v ) = 0;
00192       virtual void Color( cpu_vec_xyzw color ) = 0;
00193       virtual void EndGeom() = 0;
00194       virtual void DrawArrays( GLenum mode, int first, int count ) = 0;
00195       virtual void DrawIndexedArrays( GLenum primType,
00196                                       int numIndices, const unsigned char* indices,
00197                                       int numVertices ) = 0;
00198       virtual void Flush() = 0;
00199 };
00200 
00201 #endif // ps2gl_gmanager_h

ps2gl version cvs