40 #ifndef GLS_GEOMETRY_RESOURCE_H_INCLUDED
41 #define GLS_GEOMETRY_RESOURCE_H_INCLUDED
58 # include <OpenGL/gl.h>
67 #include "gls_resource_file_mgr.h"
71 #if( defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLSGEN_IMPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
72 && defined( _MSC_VER )
73 # if defined( GLSGEN_EXPORT_GLSGEOMETRYRESOURCE ) || defined( GLS_EXPORT_GENERATED )
74 # define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllexport )
76 # define GLSGEN_GlsGeometryResource_EXPORT __declspec( dllimport )
79 # define GLSGEN_GlsGeometryResource_EXPORT
89 static const unsigned int MAX_TEXTURE_COORDS = 2;
90 static const unsigned int MAX_VERTEX_ATTRIBS = 16;
94 static const unsigned int NORMAL_ATTRIBUTE_SIZE = 3 *
sizeof( float );
96 static const unsigned int COLOR_ATTRIBUTE_SIZE = 4 *
sizeof(
unsigned char );
98 static const unsigned int COLOR_ATTRIBUTE_SIZE =
sizeof(
unsigned int );
100 static const unsigned int SECONDARY_COLOR_ATTRIBUTE_SIZE = 3 *
sizeof(
unsigned char );
101 static const unsigned int TEXTURE_COORDINATE_ATTRIBUTE_SIZE = 2 *
sizeof( float );
102 static const unsigned int TANGENT_ATTRIBUTE_SIZE = 3 *
sizeof( float );
103 static const unsigned int BINORMAL_ATTRIBUTE_SIZE = 3 *
sizeof( float );
109 bool hasSecondaryColor;
111 unsigned int normalType;
112 unsigned int texCoordType;
115 unsigned char numTextureCoords;
116 unsigned char texCoordDimension[ GlsGeometryResource::MAX_TEXTURE_COORDS ];
117 unsigned char numVertexAttribs;
118 GLint vertexAttribNumComponents[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
119 GLenum vertexAttribType[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
120 GLboolean vertexAttribNormalize[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
121 unsigned int vertexAttribSemantic[ GlsGeometryResource::MAX_VERTEX_ATTRIBS ];
126 memset(
this, 0,
sizeof(
TypeDesc ) );
128 for( i = 0; i < GlsGeometryResource::MAX_TEXTURE_COORDS; i++ )
130 texCoordDimension[ i ] = 2;
132 for( i = 0; i < GlsGeometryResource::MAX_VERTEX_ATTRIBS; i++ )
134 vertexAttribNumComponents[ i ] = 4;
137 normalType = GL_FLOAT;
138 texCoordType = GL_FLOAT;
142 void HasNormal(
bool value ) { hasNormal = value; }
143 bool HasNormal(
void )
const {
return hasNormal; }
146 void NormalType(
unsigned int value )
151 unsigned int NormalType(
void )
const {
return normalType; }
153 void TexCoordType(
unsigned int value ) { texCoordType = value; }
154 unsigned int TexCoordType(
void )
const {
return texCoordType; }
157 void HasColor(
bool value )
161 bool HasColor(
void )
const {
return hasColor; }
163 void HasSecondaryColor(
bool value ) { hasSecondaryColor = value; }
164 bool HasSecondaryColor(
void )
const {
return hasSecondaryColor; }
166 void SetNumTextureCoords(
unsigned char value )
168 if( value <= GlsGeometryResource::MAX_TEXTURE_COORDS )
169 numTextureCoords = value;
171 unsigned char GetNumTextureCoords(
void )
const {
return numTextureCoords; }
173 void SetTexCoordDimension(
unsigned char which,
unsigned char value )
175 if( which < GlsGeometryResource::MAX_TEXTURE_COORDS && value > 0 && value < 5 )
176 texCoordDimension[ which ] = value;
178 unsigned char GetTexCoordDimension(
unsigned char which )
const {
return texCoordDimension[ which ]; }
189 if( value <= GlsGeometryResource::MAX_VERTEX_ATTRIBS )
190 numVertexAttribs = value;
192 unsigned char GetNumVertexAttribs(
void )
const {
return numVertexAttribs; }
198 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS && value > 0 && value < 5 )
199 vertexAttribNumComponents[ which ] = value;
201 GLint GetVertexAttribComponents(
unsigned char which )
const {
return vertexAttribNumComponents[ which ]; }
207 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
208 vertexAttribType[ which ] = value;
210 GLenum GetVertexAttribType(
unsigned char which )
const {
return vertexAttribType[ which ]; }
217 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
218 vertexAttribNormalize[ which ] = value;
220 GLboolean GetVertexAttribNormalize(
unsigned char which )
const {
return vertexAttribNormalize[ which ]; }
228 if( which < GlsGeometryResource::MAX_VERTEX_ATTRIBS )
229 vertexAttribSemantic[ which ] = semanticEnum;
231 int GetVertexAttribSemantic(
unsigned char which )
const {
return vertexAttribSemantic[ which ]; }
242 virtual ~GlsGeometryResource() {}
248 virtual void OnGeometryResourceChanged() = 0;
257 void operator=(
const Observer& ) DISTI_SPECIAL_MEM_FUN_DELETE;
260 void AddObserver(
Observer* observer )
262 _observers.PushBack( observer );
265 void RemoveObserver( Observer* observer )
267 _observers.Erase( observer );
271 DynamicArray<Observer*> _observers;
273 void OnGeometryResourceChanged()
275 for(
unsigned int i = 0; i < _observers.Count(); ++i )
277 _observers[ i ]->OnGeometryResourceChanged();
294 Vector _boundingVolumeCenter;
295 float _boundingVolumeRadius;
298 static bool _enableVBO;
391 virtual bool HitTest(
unsigned char pickType,
const Vector& pickLinePoint,
const Vector& pickLineDirection,
Vector& collisionPoint ) = 0;
414 if( _referenceCount == 0 )
438 assert( BAD_ID !=
id );
447 assert( BAD_ID != _resourceID );
453 class GlsGeometry_Generic_IndexBufferData;
491 virtual GLSGEN_GlsGeometryResource_EXPORT
bool HitTest(
unsigned char pickType,
const Vector& pickLinePoint,
const Vector& pickLineDirection,
Vector& collisionPoint );
497 virtual GLSGEN_GlsGeometryResource_EXPORT
void DrawIndexBuffer(
unsigned int bufferNumber );
540 GLSGEN_GlsGeometryResource_EXPORT
void ChangeType(
const TypeDesc& type );
545 GLSGEN_GlsGeometryResource_EXPORT
bool LockBuffers();
557 GLSGEN_GlsGeometryResource_EXPORT
unsigned int VertexCount()
const;
563 GLSGEN_GlsGeometryResource_EXPORT
void VertexCount(
unsigned int count );
570 GLSGEN_GlsGeometryResource_EXPORT
void SetVertex( GLuint vertIndex,
const float* value );
584 GLSGEN_GlsGeometryResource_EXPORT
void SetVertices(
const float* floatArray,
585 unsigned int numVertices,
586 unsigned int startVertIndex = 0,
587 unsigned int stride = VERTEX_ATTRIBUTE_SIZE );
596 GLSGEN_GlsGeometryResource_EXPORT
void SetVertex( GLuint vertIndex,
608 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetVertex( GLuint vertIndex );
618 GLSGEN_GlsGeometryResource_EXPORT
void SetNormal( GLuint vertIndex,
float x,
float y,
float z );
629 GLSGEN_GlsGeometryResource_EXPORT
void SetNormals(
const float* floatArray,
630 unsigned int numVertices,
631 unsigned int startVertIndex = 0,
632 unsigned int stride = NORMAL_ATTRIBUTE_SIZE );
641 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetNormal( GLuint vertIndex );
650 GLSGEN_GlsGeometryResource_EXPORT
void SetColor( GLuint vertIndex,
654 unsigned char alpha );
665 GLSGEN_GlsGeometryResource_EXPORT
void SetColors(
const unsigned int* rgbaArray,
666 unsigned int numVertices,
667 unsigned int startVertIndex = 0,
668 unsigned int stride = COLOR_ATTRIBUTE_SIZE );
674 GLSGEN_GlsGeometryResource_EXPORT
void SetColors(
const unsigned int* array );
681 GLSGEN_GlsGeometryResource_EXPORT
unsigned char*
GetColor( GLuint vertIndex );
693 unsigned char blue );
704 GLSGEN_GlsGeometryResource_EXPORT
void SetSecondaryColors(
const unsigned int* rgbArray,
705 unsigned int numVertices,
706 unsigned int startVertIndex = 0,
707 unsigned int stride = SECONDARY_COLOR_ATTRIBUTE_SIZE );
714 GLSGEN_GlsGeometryResource_EXPORT
unsigned char*
GetSecondaryColor( GLuint vertIndex );
724 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoord( GLuint vertIndex,
unsigned int whichTexture,
725 const float* textureCoord );
727 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoord( GLuint vertIndex,
unsigned int whichTexture,
729 float textureCoordV );
740 GLSGEN_GlsGeometryResource_EXPORT
void SetTextureCoords(
unsigned int whichTexture,
741 const float* textureCoordArray,
742 unsigned int numVertices,
743 unsigned int startVertIndex = 0,
744 unsigned int stride = TEXTURE_COORDINATE_ATTRIBUTE_SIZE );
755 GLSGEN_GlsGeometryResource_EXPORT
const float*
GetTextureCoord( GLuint vertIndex,
unsigned int whichTexture );
763 GLSGEN_GlsGeometryResource_EXPORT
void StoreVertexAttrib( GLuint vertIndex, GLuint attribIndex,
void* value, GLuint sizeBytes );
765 void SetVertexAttrib1fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 1 *
sizeof(
float ) ); }
766 void SetVertexAttrib2fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 2 *
sizeof(
float ) ); }
767 void SetVertexAttrib3fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 3 *
sizeof(
float ) ); }
768 void SetVertexAttrib4fv( GLuint vertIndex, GLuint attribIndex,
const GLfloat* v ) {
StoreVertexAttrib( vertIndex, attribIndex, (
void*)v, 4 *
sizeof(
float ) ); }
771 GLSGEN_GlsGeometryResource_EXPORT
void SetVertexAttribs(
const float* attribArray,
774 unsigned int numVertices,
775 unsigned int startVertIndex = 0,
776 unsigned int stride = TANGENT_ATTRIBUTE_SIZE );
785 GLSGEN_GlsGeometryResource_EXPORT
void*
GetVertexAttrib( GLuint vertIndex, GLuint attribIndex );
792 GLSGEN_GlsGeometryResource_EXPORT
void NumIndexBuffers(
unsigned int count );
798 GLSGEN_GlsGeometryResource_EXPORT
unsigned int GetIndexBufferSize(
unsigned int bufferNum )
const;
805 GLSGEN_GlsGeometryResource_EXPORT
void SetIndexBufferSize(
unsigned int bufferNum,
unsigned int newSize );
812 GLSGEN_GlsGeometryResource_EXPORT
void SetIndex(
unsigned int bufferNum,
unsigned int index,
unsigned int indexValue );
826 GLSGEN_GlsGeometryResource_EXPORT
void SetIndices(
unsigned int bufferNum,
827 const unsigned int* indexArray,
828 unsigned int numIndices,
829 unsigned int startIndex = 0,
830 unsigned int stride =
sizeof(
unsigned int ) );
838 GLSGEN_GlsGeometryResource_EXPORT
unsigned int GetIndex(
unsigned int bufferNum,
unsigned int index );
846 GLSGEN_GlsGeometryResource_EXPORT
void MergeIndexBuffers(
unsigned int dstBufferNum,
unsigned int srcBufferNum );
860 GLSGEN_GlsGeometryResource_EXPORT
void SetIndices(
unsigned int bufferNum,
861 const unsigned int* indexArray,
862 unsigned int numIndices,
863 unsigned int startIndex = 0,
864 unsigned int stride =
sizeof(
unsigned int ) );
872 GLSGEN_GlsGeometryResource_EXPORT
unsigned short GetIndex(
unsigned int bufferNum,
unsigned short index );
880 unsigned int _vertexTupleIndex;
907 GLSGEN_GlsGeometryResource_EXPORT
void DumpNormals();
911 GLSGEN_GlsGeometryResource_EXPORT
void DumpIndices();
922 static GLSGEN_GlsGeometryResource_EXPORT
unsigned int CopyVertexData(
925 unsigned int vertexCount );
934 static GLSGEN_GlsGeometryResource_EXPORT
unsigned int TransformVertexData(
937 unsigned int vertexOffset = 0,
938 unsigned int vertexCount = UINT_MAX );
942 static GLSGEN_GlsGeometryResource_EXPORT
bool GenerateTangentsAndBinormals(
GlsGeometry_Generic* geom );
951 unsigned int _texcoordStride;
952 unsigned int _texcoord2Stride;
953 unsigned int _colorStride;
954 unsigned int _secondaryColorStride;
955 unsigned int _numVertexAttribs;
956 unsigned int _vertexAttribStride[ MAX_VERTEX_ATTRIBS ];
957 unsigned int _vertexAttribSize[ MAX_VERTEX_ATTRIBS ];
966 unsigned int _vertexBufferCount;
967 GLuint _vertexBufferID;
968 bool _vertexBufferUpdated;
985 GLSGEN_GlsGeometryResource_EXPORT
bool BestHit(
const Vector& point,
const Vector& directionVector,
Vector& collisionPoint );
995 GLSGEN_GlsGeometryResource_EXPORT
bool FirstHit(
const Vector& point,
const Vector& directionVector,
Vector& collisionPoint );
997 void InitializeMembers();
1001 unsigned int GetTexcoordByteOffset(
unsigned int whichTexture );
1003 GLSGEN_GlsGeometryResource_EXPORT
void Destroy();
1007 unsigned int _dataChangedCounter;
1010 void IncDataChangedCounter()
1015 ++_dataChangedCounter;
1020 GLSGEN_GlsGeometryResource_EXPORT GlsGeometry_Generic();
1023 GLSGEN_GlsGeometryResource_EXPORT ~GlsGeometry_Generic();
1026 GlsGeometry_Generic(
const GlsGeometry_Generic& src );
1027 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:430
TypeDesc _type
Definition: gls_geometry_resource.h:288
unsigned int GetIndexBufferSize(unsigned int bufferNum) const
Definition: gls_geometry_resource.h:105
virtual void DrawIndexBuffer(unsigned int bufferNumber)=0
static const unsigned int s_invalidDataChangedCounter
Definition: gls_geometry_resource.h:357
void SetTextureCoord(GLuint vertIndex, unsigned int whichTexture, const float *textureCoord)
void SetResourceId(unsigned int id)
Definition: gls_geometry_resource.h:436
void DecrementReference()
Definition: gls_geometry_resource.h:408
unsigned int _referenceCount
Definition: gls_geometry_resource.h:285
Definition: gls_geometry_resource.h:877
void SetNumVertexAttribs(unsigned char value)
Definition: gls_geometry_resource.h:187
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:427
void SetVertexAttribSemantic(unsigned char which, int semanticEnum)
Definition: gls_geometry_resource.h:226
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:215
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:205
Definition: gls_geometry_resource.h:245
void StoreVertexAttrib(GLuint vertIndex, GLuint attribIndex, void *value, GLuint sizeBytes)
static const unsigned int VERTEX_ATTRIBUTE_SIZE
Definition: gls_geometry_resource.h:93
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:86
void IncrementReference()
Definition: gls_geometry_resource.h:403
void SetSecondaryColors(const unsigned int *rgbArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=SECONDARY_COLOR_ATTRIBUTE_SIZE)
#define GLS_ASSERT(exp)
Definition: disti_assert.h:135
static void SetCreateInstanceMakesHalfFloat(bool value)
static GlsGeometryResource * CreateInstance(const TypeDesc &type=GlsGeometryResource::TypeDesc())
unsigned int _numIndexBuffers
Definition: gls_geometry_resource.h:291
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:467
const TypeDesc & Type()
Definition: gls_geometry_resource.h:400
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:445
unsigned int GetIndex(unsigned int bufferNum, unsigned int index)
unsigned int _resourceID
Definition: gls_geometry_resource.h:282
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:944
Contains the DistiAssert macro.
void SetVertexAttribComponents(unsigned char which, GLint value)
Definition: gls_geometry_resource.h:196
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:950
const float * GetNormal(GLuint vertIndex)
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:421
Definition: bmpimage.h:46
virtual void FreeOpenGLBuffers()
GlsGeometry_Generic_IndexBufferData * _indexBuffers
Definition: gls_geometry_resource.h:971
virtual void DrawSetup(VertexAttribIndexLookup *shaderProgram)=0
virtual unsigned int StatsIndexBufferPolygonCount(unsigned int bufferNumber)
Definition: gls_geometry_resource.h:473
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:457
The disti::GlsRenderEffect class.