40 #ifndef GLS_GEOMETRY_RESOURCE_H_INCLUDED
41 #define GLS_GEOMETRY_RESOURCE_H_INCLUDED
63 #include "gls_resource_file_mgr.h"
67 #if( defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLSGEN_IMPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
68 && defined( _MSC_VER )
69 # if defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED )
70 # define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllexport )
72 # define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllimport )
75 # define GLSGEN_GlsGeometryResource_EXPORT
85 static const unsigned int MAX_TEXTURE_COORDS = 2;
86 static const unsigned int MAX_VERTEX_ATTRIBS = 16;
90 static const unsigned int NORMAL_ATTRIBUTE_SIZE = 3 *
sizeof( float );
92 static const unsigned int COLOR_ATTRIBUTE_SIZE = 4 *
sizeof(
unsigned char );
94 static const unsigned int COLOR_ATTRIBUTE_SIZE =
sizeof(
unsigned int );
96 static const unsigned int SECONDARY_COLOR_ATTRIBUTE_SIZE = 3 *
sizeof(
unsigned char );
97 static const unsigned int TEXTURE_COORDINATE_ATTRIBUTE_SIZE = 2 *
sizeof( float );
98 static const unsigned int TANGENT_ATTRIBUTE_SIZE = 3 *
sizeof( float );
99 static const unsigned int BINORMAL_ATTRIBUTE_SIZE = 3 *
sizeof( float );
105 bool hasSecondaryColor;
107 unsigned int normalType;
108 unsigned int texCoordType;
111 unsigned char numTextureCoords;
112 unsigned char texCoordDimension[ GlsGeometryResource::MAX_TEXTURE_COORDS ];
113 unsigned char numVertexAttribs;
114 GLint vertexAttribNumComponents[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
115 GLenum vertexAttribType[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
116 GLboolean vertexAttribNormalize[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
117 unsigned int vertexAttribSemantic[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
122 memset(
this, 0,
sizeof(
TypeDesc ) );
124 for( i = 0; i < GlsGeometryResource::MAX_TEXTURE_COORDS; i++ )
126 texCoordDimension[ i ] = 2;
128 for( i = 0; i < GlsGeometryResource::MAX_VERTEX_ATTRIBS; i++ )
130 vertexAttribNumComponents[ i ] = 4;
133 normalType = GL_FLOAT;
134 texCoordType = GL_FLOAT;
138 void HasNormal(
bool value ) { hasNormal = value; }
139 bool HasNormal(
void )
const {
return hasNormal; }
142 void NormalType(
unsigned int value )
147 unsigned int NormalType(
void )
const {
return normalType; }
149 void TexCoordType(
unsigned int value ) { texCoordType = value; }
150 unsigned int TexCoordType(
void )
const {
return texCoordType; }
153 void HasColor(
bool value )
157 bool HasColor(
void )
const {
return hasColor; }
159 void HasSecondaryColor(
bool value ) { hasSecondaryColor = value; }
160 bool HasSecondaryColor(
void )
const {
return hasSecondaryColor; }
162 void SetNumTextureCoords(
unsigned char value )
164 if( value <= GlsGeometryResource::MAX_TEXTURE_COORDS )
165 numTextureCoords = value;
167 unsigned char GetNumTextureCoords(
void )
const {
return numTextureCoords; }
169 void SetTexCoordDimension(
unsigned char which,
unsigned char value )
171 if( which < GlsGeometryResource::MAX_TEXTURE_COORDS && value > 0 && value < 5 )
172 texCoordDimension[ which ] = value;
174 unsigned char GetTexCoordDimension(
unsigned char which )
const {
return texCoordDimension[ which ]; }
185 if( value <= GlsGeometryResource::MAX_VERTEX_ATTRIBS )
186 numVertexAttribs = value;
188 unsigned char GetNumVertexAttribs(
void )
const {
return numVertexAttribs; }
194 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS && value > 0 && value < 5 )
195 vertexAttribNumComponents[ which ] = value;
197 GLint GetVertexAttribComponents(
unsigned char which )
const {
return vertexAttribNumComponents[ which ]; }
203 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
204 vertexAttribType[ which ] = value;
206 GLenum GetVertexAttribType(
unsigned char which )
const {
return vertexAttribType[ which ]; }
213 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
214 vertexAttribNormalize[ which ] = value;
216 GLboolean GetVertexAttribNormalize(
unsigned char which )
const {
return vertexAttribNormalize[ which ]; }
224 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
225 vertexAttribSemantic[ which ] = semanticEnum;
227 int GetVertexAttribSemantic(
unsigned char which )
const {
return vertexAttribSemantic[ which ]; }
238 virtual ~GlsGeometryResource() {}
244 virtual void OnGeometryResourceChanged() = 0;
253 void operator=(
const Observer& ) DISTI_SPECIAL_MEM_FUN_DELETE;
256 void AddObserver(
Observer* observer )
258 _observers.PushBack( observer );
261 void RemoveObserver( Observer* observer )
263 _observers.Erase( observer );
267 DynamicArray<Observer*> _observers;
269 void OnGeometryResourceChanged()
271 for(
unsigned int i = 0; i < _observers.Count(); ++i )
273 _observers[ i ]->OnGeometryResourceChanged();
290 Vector _boundingVolumeCenter;
291 float _boundingVolumeRadius;
294 static bool _enableVBO;
387 virtual bool HitTest(
unsigned char pickType,
const Vector& pickLinePoint,
const Vector& pickLineDirection,
Vector& collisionPoint ) = 0;
406 DistiAssert( _referenceCount > 0 );
410 if( _referenceCount == 0 )
434 assert( BAD_ID !=
id );
443 assert( BAD_ID != _resourceID );
449 class GlsGeometry_Generic_IndexBufferData;
487 virtual GLSGEN_GlsGeometryResource_EXPORT
bool HitTest(
unsigned char pickType,
const Vector& pickLinePoint,
const Vector& pickLineDirection,
Vector& collisionPoint );
493 virtual GLSGEN_GlsGeometryResource_EXPORT
void DrawIndexBuffer(
unsigned int bufferNumber );
536 GLSGEN_GlsGeometryResource_EXPORT
void ChangeType(
const TypeDesc& type );
541 GLSGEN_GlsGeometryResource_EXPORT
bool LockBuffers();
553 GLSGEN_GlsGeometryResource_EXPORT
unsigned int VertexCount()
const;
559 GLSGEN_GlsGeometryResource_EXPORT
void VertexCount(
unsigned int count );
566 GLSGEN_GlsGeometryResource_EXPORT
void SetVertex( GLuint vertIndex,
const float* value );
580 GLSGEN_GlsGeometryResource_EXPORT
void SetVertices(
const float* floatArray,
581 unsigned int numVertices,
582 unsigned int startVertIndex = 0,
583 unsigned int stride = VERTEX_ATTRIBUTE_SIZE );
592 GLSGEN_GlsGeometryResource_EXPORT
void SetVertex( GLuint vertIndex,
604 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetVertex( GLuint vertIndex );
614 GLSGEN_GlsGeometryResource_EXPORT
void SetNormal( GLuint vertIndex,
float x,
float y,
float z );
625 GLSGEN_GlsGeometryResource_EXPORT
void SetNormals(
const float* floatArray,
626 unsigned int numVertices,
627 unsigned int startVertIndex = 0,
628 unsigned int stride = NORMAL_ATTRIBUTE_SIZE );
637 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetNormal( GLuint vertIndex );
646 GLSGEN_GlsGeometryResource_EXPORT
void SetColor( GLuint vertIndex,
650 unsigned char alpha );
661 GLSGEN_GlsGeometryResource_EXPORT
void SetColors(
const unsigned int* rgbaArray,
662 unsigned int numVertices,
663 unsigned int startVertIndex = 0,
664 unsigned int stride = COLOR_ATTRIBUTE_SIZE );
670 GLSGEN_GlsGeometryResource_EXPORT
void SetColors(
const unsigned int* array );
677 GLSGEN_GlsGeometryResource_EXPORT
unsigned char*
GetColor( GLuint vertIndex );
689 unsigned char blue );
700 GLSGEN_GlsGeometryResource_EXPORT
void SetSecondaryColors(
const unsigned int* rgbArray,
701 unsigned int numVertices,
702 unsigned int startVertIndex = 0,
703 unsigned int stride = SECONDARY_COLOR_ATTRIBUTE_SIZE );
710 GLSGEN_GlsGeometryResource_EXPORT
unsigned char*
GetSecondaryColor( GLuint vertIndex );
720 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoord( GLuint vertIndex,
unsigned int whichTexture,
721 const float* textureCoord );
723 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoord( GLuint vertIndex,
unsigned int whichTexture,
725 float textureCoordV );
736 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoords(
unsigned int whichTexture,
737 const float* textureCoordArray,
738 unsigned int numVertices,
739 unsigned int startVertIndex = 0,
740 unsigned int stride = TEXTURE_COORDINATE_ATTRIBUTE_SIZE );
751 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetTextureCoord( GLuint vertIndex,
unsigned int whichTexture );
759 GLSGEN_GlsGeometryResource_EXPORT
void StoreVertexAttrib( GLuint vertIndex, GLuint attribIndex,
void* value, GLuint sizeBytes );
761 void SetVertexAttrib1fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 1 *
sizeof(
float ) ); }
762 void SetVertexAttrib2fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 2 *
sizeof(
float ) ); }
763 void SetVertexAttrib3fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 3 *
sizeof(
float ) ); }
764 void SetVertexAttrib4fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 4 *
sizeof(
float ) ); }
767 GLSGEN_GlsGeometryResource_EXPORT
void SetVertexAttribs(
const float* attribArray,
770 unsigned int numVertices,
771 unsigned int startVertIndex = 0,
772 unsigned int stride = TANGENT_ATTRIBUTE_SIZE );
781 GLSGEN_GlsGeometryResource_EXPORT
void*
GetVertexAttrib( GLuint vertIndex, GLuint attribIndex );
788 GLSGEN_GlsGeometryResource_EXPORT
void NumIndexBuffers(
unsigned int count );
794 GLSGEN_GlsGeometryResource_EXPORT
unsigned int GetIndexBufferSize(
unsigned int bufferNum )
const;
801 GLSGEN_GlsGeometryResource_EXPORT
void SetIndexBufferSize(
unsigned int bufferNum,
unsigned int newSize );
808 GLSGEN_GlsGeometryResource_EXPORT
void SetIndex(
unsigned int bufferNum,
unsigned int index,
unsigned int indexValue );
822 GLSGEN_GlsGeometryResource_EXPORT
void SetIndices(
unsigned int bufferNum,
823 const unsigned int* indexArray,
824 unsigned int numIndices,
825 unsigned int startIndex = 0,
826 unsigned int stride =
sizeof(
unsigned int ) );
834 GLSGEN_GlsGeometryResource_EXPORT
unsigned int GetIndex(
unsigned int bufferNum,
unsigned int index );
842 GLSGEN_GlsGeometryResource_EXPORT
void MergeIndexBuffers(
unsigned int dstBufferNum,
unsigned int srcBufferNum );
856 GLSGEN_GlsGeometryResource_EXPORT
void SetIndices(
unsigned int bufferNum,
857 const unsigned int* indexArray,
858 unsigned int numIndices,
859 unsigned int startIndex = 0,
860 unsigned int stride =
sizeof(
unsigned int ) );
868 GLSGEN_GlsGeometryResource_EXPORT
unsigned short GetIndex(
unsigned int bufferNum,
unsigned short index );
876 unsigned int _vertexTupleIndex;
903 GLSGEN_GlsGeometryResource_EXPORT
void DumpNormals();
907 GLSGEN_GlsGeometryResource_EXPORT
void DumpIndices();
918 static GLSGEN_GlsGeometryResource_EXPORT
unsigned int CopyVertexData(
921 unsigned int vertexCount );
930 static GLSGEN_GlsGeometryResource_EXPORT
unsigned int TransformVertexData(
933 unsigned int vertexOffset = 0,
934 unsigned int vertexCount = UINT_MAX );
938 static GLSGEN_GlsGeometryResource_EXPORT
bool GenerateTangentsAndBinormals(
GlsGeometry_Generic* geom );
947 unsigned int _texcoordStride;
948 unsigned int _texcoord2Stride;
949 unsigned int _colorStride;
950 unsigned int _secondaryColorStride;
951 unsigned int _numVertexAttribs;
952 unsigned int _vertexAttribStride[ MAX_VERTEX_ATTRIBS ];
953 unsigned int _vertexAttribSize[ MAX_VERTEX_ATTRIBS ];
962 unsigned int _vertexBufferCount;
963 GLuint _vertexBufferID;
964 bool _vertexBufferUpdated;
981 GLSGEN_GlsGeometryResource_EXPORT
bool BestHit(
const Vector& point,
const Vector& directionVector,
Vector& collisionPoint );
991 GLSGEN_GlsGeometryResource_EXPORT
bool FirstHit(
const Vector& point,
const Vector& directionVector,
Vector& collisionPoint );
993 void InitializeMembers();
997 unsigned int GetTexcoordByteOffset(
unsigned int whichTexture );
999 GLSGEN_GlsGeometryResource_EXPORT
void Destroy();
1003 unsigned int _dataChangedCounter;
1006 void IncDataChangedCounter()
1011 ++_dataChangedCounter;
1016 GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic();
1019 GLSGEN_GlsGeometryResource_EXPORT ~GlsGeometry_Generic();
1022 GlsGeometry_Generic(
const GlsGeometry_Generic& src );
1023 GlsGeometry_Generic& operator=(
const GlsGeometry_Generic& rhs );
void SetIndexBufferSize(unsigned int bufferNum, unsigned int newSize)
void SetColors(const unsigned int *rgbaArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=COLOR_ATTRIBUTE_SIZE)
virtual void DrawCleanup(VertexAttribIndexLookup *shaderProgram)
unsigned int VertexCount() const
void SetColor(GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
float BoundingVolumeRadius() const
Definition: gls_geometry_resource.h:426
TypeDesc _type
Definition: gls_geometry_resource.h:284
unsigned int GetIndexBufferSize(unsigned int bufferNum) const
Definition: gls_geometry_resource.h:101
virtual void DrawIndexBuffer(unsigned int bufferNumber)=0
static const unsigned int s_invalidDataChangedCounter
Definition: gls_geometry_resource.h:353
void SetTextureCoord(GLuint vertIndex, unsigned int whichTexture, const float *textureCoord)
void SetResourceId(unsigned int id)
Definition: gls_geometry_resource.h:432
void DecrementReference()
Definition: gls_geometry_resource.h:404
unsigned int _referenceCount
Definition: gls_geometry_resource.h:281
Definition: gls_geometry_resource.h:873
void SetNumVertexAttribs(unsigned char value)
Definition: gls_geometry_resource.h:183
virtual bool BoundingVolumeHit(const Vector &point, const Vector &direction)=0
The GlsMatrixAffine class.
void MergeIndexBuffers(unsigned int dstBufferNum, unsigned int srcBufferNum)
const Vector & BoundingVolumeCenter() const
Definition: gls_geometry_resource.h:423
void SetVertexAttribSemantic(unsigned char which, int semanticEnum)
Definition: gls_geometry_resource.h:222
unsigned char * GetColor(GLuint vertIndex)
bool BestHit(const Vector &point, const Vector &directionVector, Vector &collisionPoint)
const float * GetTextureCoord(GLuint vertIndex, unsigned int whichTexture)
void SetVertexAttribNormalize(unsigned char which, GLboolean value)
Definition: gls_geometry_resource.h:211
void SetNormals(const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=NORMAL_ATTRIBUTE_SIZE)
virtual bool BoundingVolumeHit(const Vector &point, const Vector &direction)
virtual unsigned int StatsIndexBufferPolygonCount(unsigned int bufferNumber)=0
Definition: gls_render_effect.h:81
void SetIndices(unsigned int bufferNum, const unsigned int *indexArray, unsigned int numIndices, unsigned int startIndex=0, unsigned int stride=sizeof(unsigned int))
virtual unsigned int StatsIndexBufferVertexCount(unsigned int bufferNumber)=0
virtual unsigned int GetDataChangedCounter() const
void SetVertexAttribType(unsigned char which, GLenum value)
Definition: gls_geometry_resource.h:201
Definition: gls_geometry_resource.h:241
void StoreVertexAttrib(GLuint vertIndex, GLuint attribIndex, void *value, GLuint sizeBytes)
static const unsigned int VERTEX_ATTRIBUTE_SIZE
Definition: gls_geometry_resource.h:89
void SetSecondaryColor(GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue)
void SetVertices(const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=VERTEX_ATTRIBUTE_SIZE)
bool FirstHit(const Vector &point, const Vector &directionVector, Vector &collisionPoint)
unsigned char * GetSecondaryColor(GLuint vertIndex)
Definition: gls_geometry_resource.h:82
void IncrementReference()
Definition: gls_geometry_resource.h:399
void SetSecondaryColors(const unsigned int *rgbArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=SECONDARY_COLOR_ATTRIBUTE_SIZE)
static void SetCreateInstanceMakesHalfFloat(bool value)
static GlsGeometryResource * CreateInstance(const TypeDesc &type=GlsGeometryResource::TypeDesc())
unsigned int _numIndexBuffers
Definition: gls_geometry_resource.h:287
void * GetVertexAttrib(GLuint vertIndex, GLuint attribIndex)
The disti::Vertex class. A class for manipulating 3D vertices.
virtual void DrawIndexBuffer(unsigned int bufferNumber)
virtual void UpdateBoundingVolume(void)
void SetIndex(unsigned int bufferNum, unsigned int index, unsigned int indexValue)
virtual void GetExtents(Vector &min, Vector &max, const GlsMatrixType *matrix=NULL)
virtual unsigned int StatsIndexBufferVertexCount(unsigned int bufferNumber)
Definition: gls_geometry_resource.h:463
const TypeDesc & Type()
Definition: gls_geometry_resource.h:396
static unsigned int CopyVertexData(GlsGeometry_Generic *dstGeom, unsigned int dstOffset, GlsGeometry_Generic *srcGeom, unsigned int srcOffset, unsigned int vertexCount)
virtual unsigned int GetDataChangedCounter() const =0
virtual void DrawSetup(VertexAttribIndexLookup *shaderProgram)
virtual bool HitTest(unsigned char pickType, const Vector &pickLinePoint, const Vector &pickLineDirection, Vector &collisionPoint)=0
static GlsGeometry_Generic * CreateEmptyInstance()
void VertexSort(VertexSortData *sortData)
unsigned int GetResourceId(void)
Definition: gls_geometry_resource.h:441
unsigned int GetIndex(unsigned int bufferNum, unsigned int index)
unsigned int _resourceID
Definition: gls_geometry_resource.h:278
virtual void FreeOpenGLBuffers()=0
void SetVertex(GLuint vertIndex, const float *value)
const float * GetVertex(GLuint vertIndex)
virtual void GetExtents(Vector &min, Vector &max, const GlsMatrixType *matrix=NULL)=0
void CopyVertexAndIndexBuffers(GlsGeometry_Generic *rhs)
void ChangeType(const TypeDesc &type)
void SetNormal(GLuint vertIndex, float x, float y, float z)
static GlsGeometry_Generic * CreateInstance(const TypeDesc &type)
static GlsGeometry_Generic * CreateFromBinaryResource(GlsResourceFileMgr::BinaryResource *data)
Definition: gls_geometry_resource.h:940
Contains the DistiAssert macro.
void SetVertexAttribComponents(unsigned char which, GLint value)
Definition: gls_geometry_resource.h:192
virtual void UpdateBoundingVolume()=0
Definition: gls_resource_file_mgr.h:38
Definition: gls_resource_file_mgr.h:60
unsigned int _normalStride
Definition: gls_geometry_resource.h:946
const float * GetNormal(GLuint vertIndex)
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:417
Definition: bmpimage.h:46
virtual void FreeOpenGLBuffers()
GlsGeometry_Generic_IndexBufferData * _indexBuffers
Definition: gls_geometry_resource.h:967
virtual void DrawSetup(VertexAttribIndexLookup *shaderProgram)=0
virtual unsigned int StatsIndexBufferPolygonCount(unsigned int bufferNumber)
Definition: gls_geometry_resource.h:469
virtual void DrawCleanup(VertexAttribIndexLookup *shaderProgram)=0
virtual bool HitTest(unsigned char pickType, const Vector &pickLinePoint, const Vector &pickLineDirection, Vector &collisionPoint)
Definition: gls_geometry_resource.h:453
The disti::GlsRenderEffect class.