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

gblock.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_gblock_h
00006 #define ps2gl_gblock_h
00007 
00008 #include <stdio.h>
00009 #include "ps2s/types.h"
00010 
00011 #include "ps2gl/debug.h"
00012 #include "GL/gl.h"
00013 
00014 /********************************************
00015  * CGeometryBlock
00016  *
00017  * This classes purpose in life is to accumulate similar, contiguous geometry, where 'similar'
00018  * means same prim type, same number of words per vertex/normal/etc.
00019  */
00020 
00021 class CGeometryBlock {
00022    private:
00023       int               TotalVertices;
00024       char              WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
00025       char              NumVertsToRestartStrip, NumVertsPerPrim;
00026       bool              AreVerticesValid, AreNormalsValid, AreTexCoordsValid, AreColorsValid;
00027 
00028       GLenum            PrimType;
00029 
00030       static const int  kMaxNumStrips = 40;
00031       static const unsigned int kContinueFlag = 0x80000000;
00032       char              NumStrips;
00033       unsigned int      StripLengths[kMaxNumStrips];
00034       void              *Vertices[kMaxNumStrips];
00035       void              *Normals[kMaxNumStrips];
00036       void              *TexCoords[kMaxNumStrips];
00037       void              *Colors[kMaxNumStrips];
00038 
00039       // new geometry we are trying to add to the block
00040       GLenum            NewPrimType;
00041       void              *NewVertices, *NewNormals, *NewTexCoords, *NewColors;
00042       int               NumNewVertices, NumNewNormals, NumNewTexCoords, NumNewColors;
00043       char              WordsPerNewVertex, WordsPerNewNormal;
00044       char              WordsPerNewTexCoord, WordsPerNewColor;
00045       bool              AreNewVerticesValid, AreNewNormalsValid;
00046       bool              AreNewTexCoordsValid, AreNewColorsValid;
00047 
00048       void CommitPrimType();
00049       bool SameDataFormat();
00050 
00051    public:
00052 
00053       CGeometryBlock() { Reset(); }
00054 
00055       // get/set info about geometry
00056 
00057       inline void SetVerticesAreValid( bool valid ) { AreNewVerticesValid = valid; }
00058       inline void SetNormalsAreValid( bool valid ) { AreNewNormalsValid = valid; }
00059       inline void SetTexCoordsAreValid( bool valid ) { AreNewTexCoordsValid = valid; }
00060       inline void SetColorsAreValid( bool valid ) { AreNewColorsValid = valid; }
00061 
00062       inline bool GetVerticesAreValid() const { return AreVerticesValid; }
00063       inline bool GetNormalsAreValid() const { return AreNormalsValid; }
00064       inline bool GetTexCoordsAreValid() const { return AreTexCoordsValid; }
00065       inline bool GetColorsAreValid() const { return AreColorsValid; }
00066 
00067 
00068       inline int GetWordsPerVertex() const { return WordsPerVertex; }
00069       inline int GetWordsPerNormal() const { return WordsPerNormal; }
00070       inline int GetWordsPerTexCoord() const { return WordsPerTexCoord; }
00071       inline int GetWordsPerColor() const { return WordsPerColor; }
00072 
00073       inline void SetWordsPerVertex( char num ) { WordsPerNewVertex = num; }
00074       inline void SetWordsPerNormal( char num ) { WordsPerNewNormal = num; }
00075       inline void SetWordsPerTexCoord( char num ) { WordsPerNewTexCoord = num; }
00076       inline void SetWordsPerColor( char num ) { WordsPerNewColor = num; }
00077 
00078 
00079       inline void* GetVertices(int strip = 0) {
00080          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00081          return Vertices[strip];
00082       }
00083       inline void* GetNormals(int strip = 0) {
00084          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00085          return Normals[strip];
00086       }
00087       inline void* GetTexCoords(int strip = 0) {
00088          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00089          return TexCoords[strip];
00090       }
00091       inline void* GetColors(int strip = 0) {
00092          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00093          return Colors[strip];
00094       }
00095 
00096       inline void SetVertices( void *verts ) { NewVertices = verts; }
00097       inline void SetNormals( void *norms ) { NewNormals = norms; }
00098       inline void SetTexCoords( void *texcoords ) { NewTexCoords = texcoords; }
00099       inline void SetColors( void *colors ) { NewColors = colors; }
00100 
00101 
00102       GLenum GetPrimType() const { return PrimType; }
00103       void SetPrimType( GLenum type ) { NewPrimType = type; }
00104 
00105 
00106       inline int GetNumNewVertices() const { return NumNewVertices; }
00107       inline int GetNumNewNormals() const { return NumNewNormals; }
00108       inline int GetNumNewTexCoords() const { return NumNewTexCoords; }
00109       inline int GetNumNewColors() const { return NumNewColors; }
00110 
00111       inline int GetTotalVertices() const { return TotalVertices; }
00112 
00113       // adding geometry
00114 
00115       inline void AddVertices( int num = 1 ) { NumNewVertices += num; }
00116       inline void AddNormals( int num = 1 ) { NumNewNormals += num; }
00117       inline void AddTexCoords( int num = 1 ) { NumNewTexCoords += num; }
00118       inline void AddColors( int num = 1 ) { NumNewColors += num; }
00119 
00120       // prim
00121 
00122       inline int GetNumVertsPerPrim() { return NumVertsPerPrim; }
00123 
00124       // strip related
00125 
00126       inline int GetNumStrips() const { return NumStrips; }
00127       inline int GetNumVertsToRestartStrip() { return NumVertsToRestartStrip; }
00128       inline int GetStripLength(int num) const {
00129          mErrorIf( num >= NumStrips, "Strip num is out of bounds" );
00130          return (int)(StripLengths[num] & ~kContinueFlag);
00131       }
00132       inline bool StripIsContinued( int num ) const {
00133          mErrorIf( num >= NumStrips, "Strip num is out of bounds" );
00134          return StripLengths[num] & kContinueFlag;
00135       }
00136 
00137       // reset
00138 
00139       void ResetCurStrip();
00140       void ResetNew();
00141       void Reset();
00142 
00143       // merge / commit related
00144 
00145       bool IsPending() const { return (PrimType != GL_INVALID_VALUE); }
00146       bool MergeNew();
00147       void MakeNewValuesCurrent();
00148       void AdjustNewGeomPtrs( int offset ) {
00149          if ( AreNewVerticesValid )
00150             NewVertices = (float*)NewVertices + offset * WordsPerNewVertex;
00151          if ( AreNewNormalsValid )
00152             NewNormals = (float*)NewNormals + offset * WordsPerNewNormal;
00153          if ( AreNewTexCoordsValid )
00154             NewTexCoords = (float*)NewTexCoords + offset * WordsPerNewTexCoord;
00155          if ( AreNewColorsValid )
00156             NewColors = (float*)NewColors + offset * WordsPerNewColor;
00157       }
00158 };
00159 
00160 #endif // ps2gl_gblock_h
00161 

ps2gl version 0.2