GL Studio C++ Runtime API
GlsGeometry_Generic Class Reference

#include <gls_geometry_resource.h>

Inheritance diagram for GlsGeometry_Generic:
GlsGeometryResource

Classes

struct  VertexSortData
 
struct  VertexStructureDefinition
 

Public Member Functions

virtual unsigned int StatsIndexBufferVertexCount (unsigned int bufferNumber)
 
virtual unsigned int StatsIndexBufferPolygonCount (unsigned int bufferNumber)
 
virtual unsigned int GetDataChangedCounter () const
 
virtual void GetExtents (Vector &min, Vector &max, const GlsMatrixType *matrix=NULL)
 
virtual void UpdateBoundingVolume (void)
 
virtual bool BoundingVolumeHit (const Vector &point, const Vector &direction)
 
virtual bool HitTest (unsigned char pickType, const Vector &pickLinePoint, const Vector &pickLineDirection, Vector &collisionPoint)
 
virtual void DrawSetup (VertexAttribIndexLookup *shaderProgram)
 
virtual void DrawIndexBuffer (unsigned int bufferNumber)
 
virtual void DrawCleanup (VertexAttribIndexLookup *shaderProgram)
 
virtual void FreeOpenGLBuffers ()
 
void CopyVertexAndIndexBuffers (GlsGeometry_Generic *rhs)
 
void ChangeType (const TypeDesc &type)
 
bool LockBuffers ()
 
void UnlockBuffers ()
 
unsigned int VertexCount () const
 
void VertexCount (unsigned int count)
 
void SetVertex (GLuint vertIndex, const float *value)
 
void SetVertices (const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=VERTEX_ATTRIBUTE_SIZE)
 
void SetVertex (GLuint vertIndex, float x, float y, float z)
 
const float * GetVertex (GLuint vertIndex)
 
void SetNormal (GLuint vertIndex, float x, float y, float z)
 
void SetNormals (const float *floatArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=NORMAL_ATTRIBUTE_SIZE)
 
const float * GetNormal (GLuint vertIndex)
 
void SetColor (GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
 
void SetColors (const unsigned int *rgbaArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=COLOR_ATTRIBUTE_SIZE)
 
void SetColors (const unsigned int *array)
 
unsigned char * GetColor (GLuint vertIndex)
 
void SetSecondaryColor (GLuint vertIndex, unsigned char red, unsigned char green, unsigned char blue)
 
void SetSecondaryColors (const unsigned int *rgbArray, unsigned int numVertices, unsigned int startVertIndex=0, unsigned int stride=SECONDARY_COLOR_ATTRIBUTE_SIZE)
 
unsigned char * GetSecondaryColor (GLuint vertIndex)
 
void SetTextureCoord (GLuint vertIndex, unsigned int whichTexture, const float *textureCoord)
 
const float * GetTextureCoord (GLuint vertIndex, unsigned int whichTexture)
 
void StoreVertexAttrib (GLuint vertIndex, GLuint attribIndex, void *value, GLuint sizeBytes)
 
void * GetVertexAttrib (GLuint vertIndex, GLuint attribIndex)
 
void NumIndexBuffers (unsigned int count)
 
unsigned int GetIndexBufferSize (unsigned int bufferNum) const
 
void SetIndexBufferSize (unsigned int bufferNum, unsigned int newSize)
 
void SetIndex (unsigned int bufferNum, unsigned int index, unsigned int indexValue)
 
void SetIndices (unsigned int bufferNum, const unsigned int *indexArray, unsigned int numIndices, unsigned int startIndex=0, unsigned int stride=sizeof(unsigned int))
 
unsigned int GetIndex (unsigned int bufferNum, unsigned int index)
 
void MergeIndexBuffers (unsigned int dstBufferNum, unsigned int srcBufferNum)
 
void VertexSort (VertexSortData *sortData)
 
void DumpVertices ()
 
void DumpNormals ()
 
void DumpIndices ()
 
- Public Member Functions inherited from GlsGeometryResource
const TypeDescType ()
 
void IncrementReference ()
 
void DecrementReference ()
 
unsigned int NumIndexBuffers () const
 
const VectorBoundingVolumeCenter () const
 
float BoundingVolumeRadius () const
 
void SetResourceId (unsigned int id)
 
unsigned int GetResourceId (void)
 

Static Public Member Functions

static GlsGeometry_GenericCreateInstance (const TypeDesc &type)
 
static GlsGeometry_GenericCreateInstance (GlsResourceFileMgr::ResourceRef *resource)
 
static GlsGeometry_GenericCreateFromBinaryResource (GlsResourceFileMgr::BinaryResource *data)
 
static GlsGeometry_GenericCreateEmptyInstance ()
 
static unsigned int CopyVertexData (GlsGeometry_Generic *dstGeom, unsigned int dstOffset, GlsGeometry_Generic *srcGeom, unsigned int srcOffset, unsigned int vertexCount)
 
- Static Public Member Functions inherited from GlsGeometryResource
static void SetCreateInstanceMakesHalfFloat (bool value)
 
static GlsGeometryResourceCreateInstance (const TypeDesc &type=GlsGeometryResource::TypeDesc())
 
static GlsGeometryResourceCreateInstance (GlsResourceFileMgr::ResourceRef *resource)
 

Protected Member Functions

bool BestHit (const Vector &point, const Vector &directionVector, Vector &collisionPoint)
 
bool FirstHit (const Vector &point, const Vector &directionVector, Vector &collisionPoint)
 
void Destroy ()
 

Protected Attributes

GlsGeometry_Generic_IndexBufferData * _indexBuffers
 
- Protected Attributes inherited from GlsGeometryResource
unsigned int _resourceID
 
unsigned int _referenceCount
 
TypeDesc _type
 
unsigned int _numIndexBuffers
 

Additional Inherited Members

- Static Public Attributes inherited from GlsGeometryResource
static const unsigned int VERTEX_ATTRIBUTE_SIZE = 3 * sizeof( float )
 
static const unsigned int s_invalidDataChangedCounter = 0
 

Detailed Description

Flexible implementation of GlsGeometryResource that can store any type of geometry This resource is used in the editor and may be used at runtime if there is not a more efficient implementation for the desired TypeDesc.

Member Function Documentation

bool BestHit ( const Vector point,
const Vector directionVector,
Vector collisionPoint 
)
protected

Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object and guarantees that the collision point returned by Hit is the closest collision point to the observer.

Parameters
pointThe geometry coordinate of the click, relative to the object
directionVectorThe direction of the pick vector
collisionPointSet to the point on the object hit by directionVector
Returns
booleanean indicating if the object was hit by the mouse
virtual bool BoundingVolumeHit ( const Vector point,
const Vector direction 
)
virtual

Determines if the given ray hits the geometry bounding volume. Note: All parameters should be in this object's coordinates.

Parameters
pointThe starting point of the ray.
directionThe direction vector of the ray.
Returns
True if this bounding volume is hit by the ray.

Implements GlsGeometryResource.

void ChangeType ( const TypeDesc type)

Changes the Type of this geometry resource. This is a slow operation; it creates new storage according to the typeDesc and copys the existing vertex data. If a vertex attribute does not map to the new type it will be lost. Any new attributes will be uninitialized. Requires that the OpenGL context is current if this GlsGeometryResource has been previously drawn.

Parameters
typeThe TypeDesc to use for the new structure
void CopyVertexAndIndexBuffers ( GlsGeometry_Generic rhs)

Copy the geometry from another resource into this one. Does not change the Type of this resource: only vertex attributes that both resources have in common will be copied.

Parameters
rhsthe resource to copy from
static unsigned int CopyVertexData ( GlsGeometry_Generic dstGeom,
unsigned int  dstOffset,
GlsGeometry_Generic srcGeom,
unsigned int  srcOffset,
unsigned int  vertexCount 
)
static

Copy vertex attributes from srcGeom to dstGeom Does not change the Type of the resource: only vertex attributes that both resources have in common will be copied.

Parameters
dstGeomthe resource to copy to
dstOffsetvertex offset to start copying at
srcGeomthe resource to copy from
srcOffsetvertex offset to start copying from
vertexCountnumber of vertices to copy
Returns
the number of vertices that were copied
static GlsGeometry_Generic* CreateEmptyInstance ( )
static

Create an empty GlsGeometry_Generic with default TypeDesc

static GlsGeometry_Generic* CreateFromBinaryResource ( GlsResourceFileMgr::BinaryResource data)
static

Create GlsGeometry_Generic from binary resource

static GlsGeometry_Generic* CreateInstance ( const TypeDesc type)
static

Create GlsGeometry_Generic from TypeDesc

static GlsGeometry_Generic* CreateInstance ( GlsResourceFileMgr::ResourceRef resource)
static

Construct a GlsGeometryResource from a binary resource The initial reference count is 1. Call DecrementReference to free the GlsGeometryResource when you are done with it.

Parameters
resourcepointer to a ResourceRef containing geometry data
void Destroy ( )
protectedvirtual

Deletes this object from the heap that it was allocated on

Implements GlsGeometryResource.

virtual void DrawCleanup ( VertexAttribIndexLookup shaderProgram)
virtual

Restore the OpenGL state after rendering.

Parameters
shaderProgramMust be the same value that was passed to DrawSetup
Precondition
DrawSetup was called
Postcondition
The OpenGL state will be restored

Implements GlsGeometryResource.

virtual void DrawIndexBuffer ( unsigned int  bufferNumber)
virtual

Draw the geometry specified by the given index buffer This method should only be called between calls to DrawSetup and DrawCleanup.

Precondition
DrawSetup has been called.
Parameters
bufferNumberWhich index buffer to draw

Implements GlsGeometryResource.

virtual void DrawSetup ( VertexAttribIndexLookup shaderProgram)
virtual

Setup the OpenGL state for rendering this geometry. To draw, call DrawIndexBuffer for each index buffer in the resource. After drawing, call DrawCleanup to restore the OpenGL state.

Parameters
shaderPrograminterface to the shader program, used to lookup correct VertexAttrib index values (may be NULL)
Postcondition
The OpenGL state is configured for rendering from the index buffers.

Implements GlsGeometryResource.

void DumpIndices ( )

Dump all the Indices to the terminal

void DumpNormals ( )

Dump all the Normals to the terminal

void DumpVertices ( )

Dump all the vertices to the terminal

bool FirstHit ( const Vector point,
const Vector directionVector,
Vector collisionPoint 
)
protected

Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object but does not guarantee that the collision point returned by Hit is the closest collision point to the observer

Parameters
pointThe logical coordinate of the click, relative to the object
directionVectorThe direction of the pick vector
collisionPointSet to the point on the object hit by directionVector
Returns
boolean indicating if the object was hit
virtual void FreeOpenGLBuffers ( )
virtual

Force the GlsGeometryResource to free any buffers it has allocated in the current OpenGL context.

Implements GlsGeometryResource.

unsigned char* GetColor ( GLuint  vertIndex)

Gets the color value of the given vertex index

Parameters
vertIndexThe index of the color value to get, 0 to VertexCount() - 1
Returns
a pointer to a color array in rgba order
Precondition
vertIndex must be less than VertexCount(),
virtual unsigned int GetDataChangedCounter ( ) const
virtual

Since calculating metrics like the extents can be an expensive operation, the user can call this function to see if the geometry resource has changed. Caching the expensive-to-calculate values is the responsibility of the caller.

Returns
The current extents ID. Never equal to s_invalidDataChangedCounter.
See also
s_invalidDataChangedCounter

Implements GlsGeometryResource.

virtual void GetExtents ( Vector min,
Vector max,
const GlsMatrixType matrix = NULL 
)
virtual

Calculate and return the geometry extents

Parameters
minReturns the minimum x,y,z values
maxReturns the maximum x,y,z values
matrix(Optional) matrix to transform the vertices into the desired coordinate system
Note
This can be an expensive operation. GetDataChangedCounter() can be used to minimize this expense.
See also
GetDataChangedCounter()

Implements GlsGeometryResource.

unsigned int GetIndex ( unsigned int  bufferNum,
unsigned int  index 
)

Gets an index from an index buffer

Parameters
bufferNumWhich index buffer to read from
indexThe index of the Index to get, 0 to GetIndexBufferSize(bufferNum) - 1
Returns
an Index value
Precondition
index must be less than GetIndexBufferSize(bufferNum)
unsigned int GetIndexBufferSize ( unsigned int  bufferNum) const

Gets the size of an index buffer

Parameters
bufferNumWhich index buffer to return the size of
Returns
The number of items that the given index buffer can hold
const float* GetNormal ( GLuint  vertIndex)

Get a pointer to the Normal for a given Vertex index. Do not change the Normal, change it through the Set function!

Parameters
vertIndexThe index of the Normal to get, 0 to VertexCount() - 1
Returns
a pointer to an array of 3 floats.
Precondition
vertIndex must be less than VertexCount() NORMAL must be part of the Type
unsigned char* GetSecondaryColor ( GLuint  vertIndex)

Get the secondary color of the vertex at the given index.

Parameters
vertIndexThe index of the secondary color value to get, 0 to VertexCount() - 1
Returns
a pointer to a secondary color value in RGB order
Precondition
vertIndex must be less than VertexCount()
const float* GetTextureCoord ( GLuint  vertIndex,
unsigned int  whichTexture 
)

Get a TextureCoord

Parameters
vertIndexThe index of the TextureCoord value to change, 0 to VertexCount() - 1
whichTextureWhich set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
Returns
Return a pointer to the Texture Coordinates ask for
Precondition
vertIndex must be less than VertexCount() TEXCOORD must be part of the Type textureCount must be 1 to 8
const float* GetVertex ( GLuint  vertIndex)

Return a pointer to an array of 3 or 4 floats which is the vertex for the given index.

Parameters
vertIndexThe index of the vertex to get, 0 to VertexCount() - 1
Returns
a pointer to a 3 or 4 float vertex
Precondition
vertIndex must be less than VertexCount()
void* GetVertexAttrib ( GLuint  vertIndex,
GLuint  attribIndex 
)

Get pointer to the raw vertex attribute data Be careful with this!

Note
This method may be removed in the future
Parameters
vertIndexThe index of the vertex
attribIndexThe index of the generic vertex attribute
virtual bool HitTest ( unsigned char  pickType,
const Vector pickLinePoint,
const Vector pickLineDirection,
Vector collisionPoint 
)
virtual

Hit test the geometry against a picking line. All values are in geometry space.

Parameters
pickTypeThe type of picking (see PickableType_e), must be PICK_FIRST or PICK_BEST
pickLinePointA point on the pick line.
pickLineDirectionThe direction of the pick line.
collisionPointIf the method returns true, this contains the point that was hit.
Returns
true if the object was hit by the pick.

Implements GlsGeometryResource.

bool LockBuffers ( )

Attempt to Lock the Buffers, Non-Blocking

Returns
True if a lock is posible
void MergeIndexBuffers ( unsigned int  dstBufferNum,
unsigned int  srcBufferNum 
)

Merge two index buffers by adding the indexes from the source buffer to the dest buffer, then deleting the source buffer.

Parameters
dstBufferNumWhich index buffer to add to
srcBufferNumWhich index buffer to delete
Returns
true on success, false if there was an error
void NumIndexBuffers ( unsigned int  count)

Get the number of available index buffers

Parameters
countSet the number of index buffers in this geometry resource.
void SetColor ( GLuint  vertIndex,
unsigned char  red,
unsigned char  green,
unsigned char  blue,
unsigned char  alpha 
)

Set a color value

Parameters
vertIndexThe index of the color value to change, 0 to VertexCount() - 1
redRed
greenGreen
blueBlue
alphaAlpha
void SetColors ( const unsigned int *  rgbaArray,
unsigned int  numVertices,
unsigned int  startVertIndex = 0,
unsigned int  stride = COLOR_ATTRIBUTE_SIZE 
)

Initialize the vertex colors from an array of unsigned int containing rgba color data.

Steps through the array reading the color data for each vertex. The method will read 1 integer for each color.

Parameters
rgbaArraypointer to the array to read from. The array must be at least (numVertices * stride) bytes.
numVerticesNumber of vertices to read from of the array
startVertIndex(optional) The vertex buffer index to start copying into
stride(optional) The distance between each color in the rgbaArray (in bytes)
void SetColors ( const unsigned int *  array)

Initialize Color from an array

Parameters
arrayan array of color values in RGBA order of size VertexCount()
Precondition
The array must be of size VertexCount()
void SetIndex ( unsigned int  bufferNum,
unsigned int  index,
unsigned int  indexValue 
)

Change the Vertex index

Parameters
bufferNumWhich index buffer to modify
indexThe index of the Index to change, 0 to GetIndexBufferSize(bufferNum)) - 1
indexValueIndex must be less than GetIndexBufferSize(bufferNum)
void SetIndexBufferSize ( unsigned int  bufferNum,
unsigned int  newSize 
)

Set the size of the specified index buffer

Parameters
bufferNumWhich index buffer to set the size of
newSizeHow many items the Index Buffer can hold.
Precondition
newSize must be greater than zero
void SetIndices ( unsigned int  bufferNum,
const unsigned int *  indexArray,
unsigned int  numIndices,
unsigned int  startIndex = 0,
unsigned int  stride = sizeof(unsigned int) 
)

Initialize the Index buffer from an array of index values

Steps through the array reading the color data for each vertex. The method will read 3 bytes for each color.

Parameters
bufferNumWhich index buffer to modify
indexArraypointer to the array to read from. The array must be at least (numIndices * stride) bytes.
numIndicesNumber of indices to read from of the array
startIndex(optional) The index buffer element to start copying into
stride(optional) The distance between each index in the array (in bytes)
void SetNormal ( GLuint  vertIndex,
float  x,
float  y,
float  z 
)

Set a Normal

Parameters
vertIndexThe index of the vertex to change, 0 to VertexCount() - 1
xX Normal value to assign
yY Normal value to assign
zZ Normal value to assign
Precondition
normal must be a valid Vector, vertIndex must be less than VertexCount() NORMAL must be part of the Type
void SetNormals ( const float *  floatArray,
unsigned int  numVertices,
unsigned int  startVertIndex = 0,
unsigned int  stride = NORMAL_ATTRIBUTE_SIZE 
)

Initialize the vertex normals from an array of floats.

Steps through the array reading the normal data for each vertex. The method will read 3 floats for each normal.

Parameters
floatArrayPointer to the array to read from. The array must be at least (numVertices * stride) bytes.
numVerticesNumber of vertices to read from of the array
startVertIndex(optional) The vertex buffer index to start copying into
stride(optional) The distance between each normal in the floatArray (in bytes)
void SetSecondaryColor ( GLuint  vertIndex,
unsigned char  red,
unsigned char  green,
unsigned char  blue 
)

Set a secondary color value (specular)

Parameters
redRed
greenGreen
blueBlue
vertIndexThe index of the secondary color value to change, 0 to VertexCount() - 1
Precondition
vertIndex must be less than VertexCount()
void SetSecondaryColors ( const unsigned int *  rgbArray,
unsigned int  numVertices,
unsigned int  startVertIndex = 0,
unsigned int  stride = SECONDARY_COLOR_ATTRIBUTE_SIZE 
)

Initialize the vertex secondary colors from an array of unsigned int containing rgb color data. (Secondary colors do not include alpha)

Steps through the array reading the color data for each vertex. The method will read 3 bytes for each color.

Parameters
rgbArraypointer to the array to read from. The array must be at least (numVertices * stride) bytes.
numVerticesNumber of vertices to read from of the array
startVertIndex(optional) The vertex buffer index to start copying into
stride(optional) The distance between each color in the array (in bytes)
void SetTextureCoord ( GLuint  vertIndex,
unsigned int  whichTexture,
const float *  textureCoord 
)

Set a TextureCoord

Parameters
textureCoordTextureCoord value to assign. Must point to a float array containing TextureCoordinateDepth() elements
vertIndexThe index of the TextureCoord value to change, 0 to VertexCount() - 1
whichTextureWhich set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1.
Precondition
vertIndex must be less than VertexCount() TEXCOORD must be part of the Type whichTexture must be 0 to 7
void SetVertex ( GLuint  vertIndex,
const float *  value 
)

Set a vertex

Parameters
vertIndexThe index of the vertex to change, 0 to VertexCount() - 1
*valueVertex can either be 3 or 4 floats depending on the type
Precondition
vertex must be a pointer to 3 or 4 floats, vertIndex must be less than VertexCount()
void SetVertex ( GLuint  vertIndex,
float  x,
float  y,
float  z 
)

Set the vertex at a given index to a coordinate

Parameters
vertIndexThe index of the vertex to change, 0 to VertexCount() - 1
xThe x-coord
yThe y-coord
zThe z-coord
Precondition
vertex must be a pointer to 3 or 4 floats, vertIndex must be less than VertexCount()
void SetVertices ( const float *  floatArray,
unsigned int  numVertices,
unsigned int  startVertIndex = 0,
unsigned int  stride = VERTEX_ATTRIBUTE_SIZE 
)

Initialize the vertex data from an array of floats.

Steps through the array reading the data for each vertex. If Type() is POSITION_XYZ, the method will read 3 floats per vertex. If Type() is POSITION_XYZW, the method will read 4 floats per vertex.

Parameters
floatArrayPointer to the array to read from. The array must be at least (numVertices * stride) bytes.
numVerticesNumber of vertices to read from of the array
startVertIndex(optional) The vertex buffer index to start copying into
stride(optional) The distance between each vertex in the floatArray (in bytes)
virtual unsigned int StatsIndexBufferPolygonCount ( unsigned int  bufferNumber)
inlinevirtual

Returns polygon count for use in editor statistics

Implements GlsGeometryResource.

virtual unsigned int StatsIndexBufferVertexCount ( unsigned int  bufferNumber)
inlinevirtual

Returns vertex count for use in editor statistics

Implements GlsGeometryResource.

void StoreVertexAttrib ( GLuint  vertIndex,
GLuint  attribIndex,
void *  value,
GLuint  sizeBytes 
)

Store a generic vertex attribute value

Parameters
vertIndexThe index of the vertex
attribIndexThe index of the generic vertex attribute to be modified
valuevoid pointer to the value
sizeBytessize of the value in bytes
void UnlockBuffers ( )

Release the lock on the buffers. Note: If the Vertex data was changed, you should typically call UpdateBoundingVolume() before unlocking.

See also
UpdateBoundingVolume
Postcondition
If the buffer is not locked a debug message is sent to the terminal
virtual void UpdateBoundingVolume ( void  )
virtual

Updates the bounding volume of this object This method should be called if the vertices change for picking and culling to work correctly.

Note
This can be an expensive operation. GetDataChangedCounter() can be used to minimize this expense.
See also
GetDataChangedCounter()

Implements GlsGeometryResource.

unsigned int VertexCount ( ) const

Get the size of the vertex buffer

Returns
The number of items in the vertex buffer
void VertexCount ( unsigned int  count)

Set the size of the vertex buffer

Parameters
countHow many items the Vertex Buffer contains.
Precondition
size must be greater than zero
void VertexSort ( VertexSortData sortData)

Sort the vertices, based on the input data

Parameters
*sortDataAn array of VertexSortData structures, one for each primitive (set of three vertices). The data in this is array is used to reorder the primitives. e.g.: Input: order 0,1,0,5,2 index 0,1,2,3,4 Sorted: order 0,0,1,2,5 index 0,2,1,4,3
Precondition
sortData must be an array of VertexSortData VertexCount()/3 in size
Postcondition
The sortData array will be sorted based on _order. The vertex buffer will be sorted based on the new order from the sortData.

Member Data Documentation

GlsGeometry_Generic_IndexBufferData* _indexBuffers
protected

Index buffers array


The documentation for this class was generated from the following file: