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) 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_gblock_h
00008 #define ps2gl_gblock_h
00009 
00010 #include <stdio.h>
00011 #include "ps2s/types.h"
00012 
00013 #include "ps2gl/debug.h"
00014 #include "GL/gl.h"
00015 
00016 /********************************************
00017  * CGeometryBlock
00018  *
00019  * This classes purpose in life is to accumulate similar, contiguous geometry, where 'similar'
00020  * means same prim type, same number of words per vertex/normal/etc.
00021  */
00022 
00023 namespace ArrayType {
00024    typedef enum { kLinear, kIndexed, kInvalidArray } tArrayType;
00025 }
00026 
00027 class CGeometryBlock {
00028    private:
00029       int               TotalVertices;
00030       char              WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
00031       char              NumVertsToRestartStrip, NumVertsPerPrim;
00032       bool              StripsCanBeMerged;
00033       bool              AreVerticesValid, AreNormalsValid, AreTexCoordsValid, AreColorsValid;
00034 
00035       GLenum            PrimType;
00036       ArrayType::tArrayType     ArrayType;
00037 
00038       static const int  kMaxNumStrips = 40;
00039       static const unsigned int kContinueFlag = 0x80000000;
00040       char              NumStrips;
00041       unsigned int      StripLengths[kMaxNumStrips];
00042       const void        *IStripLengths[kMaxNumStrips];
00043       const void        *Indices[kMaxNumStrips];
00044       const void        *Vertices[kMaxNumStrips];
00045       const void        *Normals[kMaxNumStrips];
00046       const void        *TexCoords[kMaxNumStrips];
00047       const void        *Colors[kMaxNumStrips];
00048       unsigned char     NumIndices[kMaxNumStrips];
00049 
00050       // new geometry we are trying to add to the block
00051 
00052       GLenum            NewPrimType;
00053       ArrayType::tArrayType     NewArrayType;
00054 
00055       const void        *NewVertices, *NewNormals, *NewTexCoords, *NewColors;
00056       const void        *NewIndices, *NewIStripLengths;
00057       int               NumNewVertices, NumNewNormals, NumNewTexCoords, NumNewColors, NumNewIndices;
00058       char              WordsPerNewVertex, WordsPerNewNormal;
00059       char              WordsPerNewTexCoord, WordsPerNewColor;
00060       bool              AreNewVerticesValid, AreNewNormalsValid;
00061       bool              AreNewTexCoordsValid, AreNewColorsValid;
00062 
00063       void CommitPrimType();
00064       bool SameDataFormat();
00065 
00066       bool MergeNewLinear();
00067       bool MergeNewIndexed();
00068 
00069    public:
00070 
00071       CGeometryBlock() { Reset(); }
00072 
00073       // get/set info about geometry
00074 
00075       inline void SetVerticesAreValid( bool valid ) { AreNewVerticesValid = valid; }
00076       inline void SetNormalsAreValid( bool valid ) { AreNewNormalsValid = valid; }
00077       inline void SetTexCoordsAreValid( bool valid ) { AreNewTexCoordsValid = valid; }
00078       inline void SetColorsAreValid( bool valid ) { AreNewColorsValid = valid; }
00079 
00080       inline bool GetVerticesAreValid() const { return AreVerticesValid; }
00081       inline bool GetNormalsAreValid() const { return AreNormalsValid; }
00082       inline bool GetTexCoordsAreValid() const { return AreTexCoordsValid; }
00083       inline bool GetColorsAreValid() const { return AreColorsValid; }
00084 
00085 
00086       inline int GetWordsPerVertex() const { return WordsPerVertex; }
00087       inline int GetWordsPerNormal() const { return WordsPerNormal; }
00088       inline int GetWordsPerTexCoord() const { return WordsPerTexCoord; }
00089       inline int GetWordsPerColor() const { return WordsPerColor; }
00090 
00091       inline void SetWordsPerVertex( char num ) { WordsPerNewVertex = num; }
00092       inline void SetWordsPerNormal( char num ) { WordsPerNewNormal = num; }
00093       inline void SetWordsPerTexCoord( char num ) { WordsPerNewTexCoord = num; }
00094       inline void SetWordsPerColor( char num ) { WordsPerNewColor = num; }
00095 
00096       inline void SetArrayType( ArrayType::tArrayType type ) { NewArrayType = type; }
00097       inline ArrayType::tArrayType GetNewArrayType() const { return NewArrayType; }
00098       inline ArrayType::tArrayType GetArrayType() const { return ArrayType; }
00099 
00100       inline void SetNumIndices( unsigned int num ) { NumNewIndices = num; }
00101       inline void SetIndices( const void *indices ) { NewIndices = indices; }
00102       inline void SetIStripLengths( const void *strips ) { NewIStripLengths = strips; }
00103 
00104       inline const void* GetVertices(int strip = 0) {
00105          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00106          return Vertices[strip];
00107       }
00108       inline const void* GetNormals(int strip = 0) {
00109          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00110          return Normals[strip];
00111       }
00112       inline const void* GetTexCoords(int strip = 0) {
00113          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00114          return TexCoords[strip];
00115       }
00116       inline const void* GetColors(int strip = 0) {
00117          mErrorIf( strip >= NumStrips, "Strip num is out of bounds" );
00118          return Colors[strip];
00119       }
00120       inline const void* GetIndices(int array) {
00121          mErrorIf( array >= NumStrips, "Strip num is out of bounds" );
00122          return Indices[array];
00123       }
00124       inline const void* GetIStripLengths(int array) {
00125          mErrorIf( array >= NumStrips, "Strip num is out of bounds" );
00126          return IStripLengths[array];
00127       }
00128 
00129       inline void SetVertices( const void *verts ) { NewVertices = verts; }
00130       inline void SetNormals( const void *norms ) { NewNormals = norms; }
00131       inline void SetTexCoords( const void *texcoords ) { NewTexCoords = texcoords; }
00132       inline void SetColors( const void *colors ) { NewColors = colors; }
00133 
00134 
00135       GLenum GetPrimType() const { return PrimType; }
00136       void SetPrimType( GLenum type ) { NewPrimType = type; }
00137 
00138 
00139       inline int GetNumNewVertices() const { return NumNewVertices; }
00140       inline int GetNumNewNormals() const { return NumNewNormals; }
00141       inline int GetNumNewTexCoords() const { return NumNewTexCoords; }
00142       inline int GetNumNewColors() const { return NumNewColors; }
00143 
00144       inline int GetTotalVertices() const { return TotalVertices; }
00145 
00146       // adding geometry
00147 
00148       inline void AddVertices( int num = 1 ) { NumNewVertices += num; }
00149       inline void AddNormals( int num = 1 ) { NumNewNormals += num; }
00150       inline void AddTexCoords( int num = 1 ) { NumNewTexCoords += num; }
00151       inline void AddColors( int num = 1 ) { NumNewColors += num; }
00152 
00153       // prim
00154 
00155       // this is here for custom renderers/prim types.. use with caution!!
00156       inline void SetNumVertsPerPrim( int num ) { NumVertsPerPrim = num; }
00157       inline int GetNumVertsPerPrim() { return NumVertsPerPrim; }
00158 
00159       // strip related
00160 
00161       // this is here for custom renderers/prim types.. use with caution!!
00162       inline void SetNumVertsToRestartStrip( int num ) { NumVertsToRestartStrip = num; }
00163       inline void SetStripsCanBeMerged( bool merge ) { StripsCanBeMerged = merge; }
00164 
00165       inline int GetNumStrips() const { return NumStrips; }
00169       inline int GetNumVertsToRestartStrip() { return NumVertsToRestartStrip; }
00170       inline bool GetStripsCanBeMerged() const { return StripsCanBeMerged; }
00171       inline int GetStripLength(int num) const {
00172          mErrorIf( num >= NumStrips, "Strip num is out of bounds" );
00173          return (int)(StripLengths[num] & ~kContinueFlag);
00174       }
00175       inline bool StripIsContinued( int num ) const {
00176          mErrorIf( num >= NumStrips, "Strip num is out of bounds" );
00177          return StripLengths[num] & kContinueFlag;
00178       }
00179 
00180       // "array" related (for indexed arrays)
00181 
00182       inline int GetNumArrays() const { return NumStrips; }
00183       inline int GetArrayLength(int array) const {
00184          return GetStripLength(array);
00185       }
00186       inline int GetNumIndices(int array) const {
00187          mErrorIf( array >= NumStrips, "Strip num is out of bounds" );
00188          return NumIndices[array];
00189       }
00190 
00191       // reset
00192 
00193       void ResetCurStrip();
00194       void ResetNew();
00195       void Reset();
00196 
00197       // merge / commit related
00198 
00199       bool IsPending() const { return (PrimType != GL_INVALID_VALUE); }
00200       bool MergeNew();
00201       void MakeNewValuesCurrent();
00202       void AdjustNewGeomPtrs( int offset ) {
00203          if ( AreNewVerticesValid )
00204             NewVertices = (float*)NewVertices + offset * WordsPerNewVertex;
00205          if ( AreNewNormalsValid )
00206             NewNormals = (float*)NewNormals + offset * WordsPerNewNormal;
00207          if ( AreNewTexCoordsValid )
00208             NewTexCoords = (float*)NewTexCoords + offset * WordsPerNewTexCoord;
00209          if ( AreNewColorsValid )
00210             NewColors = (float*)NewColors + offset * WordsPerNewColor;
00211       }
00212 };
00213 
00214 #endif // ps2gl_gblock_h
00215 

ps2gl version cvs