GL Studio API
|
#include <gls_geometry_resource.h>
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 TypeDesc & | Type () |
void | IncrementReference () |
void | DecrementReference () |
unsigned int | NumIndexBuffers () const |
const Vector & | BoundingVolumeCenter () const |
float | BoundingVolumeRadius () const |
void | SetResourceId (unsigned int id) |
unsigned int | GetResourceId (void) |
Static Public Member Functions | |
static GlsGeometry_Generic * | CreateInstance (const TypeDesc &type) |
static GlsGeometry_Generic * | CreateInstance (GlsResourceFileMgr::ResourceRef *resource) |
static GlsGeometry_Generic * | CreateFromBinaryResource (GlsResourceFileMgr::BinaryResource *data) |
static GlsGeometry_Generic * | CreateEmptyInstance () |
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 GlsGeometryResource * | CreateInstance (const TypeDesc &type=GlsGeometryResource::TypeDesc()) |
static GlsGeometryResource * | CreateInstance (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 |
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.
|
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.
point | The geometry coordinate of the click, relative to the object |
directionVector | The direction of the pick vector |
collisionPoint | Set to the point on the object hit by directionVector |
Determines if the given ray hits the geometry bounding volume. Note: All parameters should be in this object's coordinates.
point | The starting point of the ray. |
direction | The direction vector of 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.
type | The 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.
rhs | the resource to copy from |
|
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.
dstGeom | the resource to copy to |
dstOffset | vertex offset to start copying at |
srcGeom | the resource to copy from |
srcOffset | vertex offset to start copying from |
vertexCount | number of vertices to copy |
|
static |
Create an empty GlsGeometry_Generic with default TypeDesc
|
static |
Create GlsGeometry_Generic from binary resource
|
static |
Create GlsGeometry_Generic from TypeDesc
|
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.
resource | pointer to a ResourceRef containing geometry data |
|
protectedvirtual |
Deletes this object from the heap that it was allocated on
Implements GlsGeometryResource.
|
virtual |
Restore the OpenGL state after rendering.
shaderProgram | Must be the same value that was passed to DrawSetup |
Implements GlsGeometryResource.
|
virtual |
Draw the geometry specified by the given index buffer This method should only be called between calls to DrawSetup and DrawCleanup.
bufferNumber | Which index buffer to draw |
Implements GlsGeometryResource.
|
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.
shaderProgram | interface to the shader program, used to lookup correct VertexAttrib index values (may be NULL) |
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
|
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
point | The logical coordinate of the click, relative to the object |
directionVector | The direction of the pick vector |
collisionPoint | Set to the point on the object hit by directionVector |
|
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
vertIndex | The index of the color value to get, 0 to VertexCount() - 1 |
|
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.
Implements GlsGeometryResource.
|
virtual |
Calculate and return the geometry extents
min | Returns the minimum x,y,z values |
max | Returns the maximum x,y,z values |
matrix | (Optional) matrix to transform the vertices into the desired coordinate system |
Implements GlsGeometryResource.
unsigned int GetIndex | ( | unsigned int | bufferNum, |
unsigned int | index | ||
) |
Gets an index from an index buffer
bufferNum | Which index buffer to read from |
index | The index of the Index to get, 0 to GetIndexBufferSize(bufferNum) - 1 |
unsigned int GetIndexBufferSize | ( | unsigned int | bufferNum | ) | const |
Gets the size of an index buffer
bufferNum | Which index buffer to return the size of |
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!
vertIndex | The index of the Normal to get, 0 to VertexCount() - 1 |
unsigned char* GetSecondaryColor | ( | GLuint | vertIndex | ) |
Get the secondary color of the vertex at the given index.
vertIndex | The index of the secondary color value to get, 0 to VertexCount() - 1 |
const float* GetTextureCoord | ( | GLuint | vertIndex, |
unsigned int | whichTexture | ||
) |
Get a TextureCoord
vertIndex | The index of the TextureCoord value to change, 0 to VertexCount() - 1 |
whichTexture | Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1. |
const float* GetVertex | ( | GLuint | vertIndex | ) |
Return a pointer to an array of 3 or 4 floats which is the vertex for the given index.
vertIndex | The index of the vertex to get, 0 to VertexCount() - 1 |
void* GetVertexAttrib | ( | GLuint | vertIndex, |
GLuint | attribIndex | ||
) |
Get pointer to the raw vertex attribute data Be careful with this!
vertIndex | The index of the vertex |
attribIndex | The index of the generic vertex attribute |
|
virtual |
Hit test the geometry against a picking line. All values are in geometry space.
pickType | The type of picking (see PickableType_e), must be PICK_FIRST or PICK_BEST |
pickLinePoint | A point on the pick line. |
pickLineDirection | The direction of the pick line. |
collisionPoint | If the method returns true, this contains the point that was hit. |
Implements GlsGeometryResource.
bool LockBuffers | ( | ) |
Attempt to Lock the Buffers, Non-Blocking
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.
dstBufferNum | Which index buffer to add to |
srcBufferNum | Which index buffer to delete |
void NumIndexBuffers | ( | unsigned int | count | ) |
Get the number of available index buffers
count | Set 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
vertIndex | The index of the color value to change, 0 to VertexCount() - 1 |
red | Red |
green | Green |
blue | Blue |
alpha | Alpha |
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.
rgbaArray | pointer to the array to read from. The array must be at least (numVertices * stride) bytes. |
numVertices | Number 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
array | an array of color values in RGBA order of size VertexCount() |
void SetIndex | ( | unsigned int | bufferNum, |
unsigned int | index, | ||
unsigned int | indexValue | ||
) |
Change the Vertex index
bufferNum | Which index buffer to modify |
index | The index of the Index to change, 0 to GetIndexBufferSize(bufferNum)) - 1 |
indexValue | Index must be less than GetIndexBufferSize(bufferNum) |
void SetIndexBufferSize | ( | unsigned int | bufferNum, |
unsigned int | newSize | ||
) |
Set the size of the specified index buffer
bufferNum | Which index buffer to set the size of |
newSize | How many items the Index Buffer can hold. |
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.
bufferNum | Which index buffer to modify |
indexArray | pointer to the array to read from. The array must be at least (numIndices * stride) bytes. |
numIndices | Number 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
vertIndex | The index of the vertex to change, 0 to VertexCount() - 1 |
x | X Normal value to assign |
y | Y Normal value to assign |
z | Z Normal value to assign |
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.
floatArray | Pointer to the array to read from. The array must be at least (numVertices * stride) bytes. |
numVertices | Number 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)
red | Red |
green | Green |
blue | Blue |
vertIndex | The index of the secondary color value to change, 0 to VertexCount() - 1 |
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.
rgbArray | pointer to the array to read from. The array must be at least (numVertices * stride) bytes. |
numVertices | Number 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
textureCoord | TextureCoord value to assign. Must point to a float array containing TextureCoordinateDepth() elements |
vertIndex | The index of the TextureCoord value to change, 0 to VertexCount() - 1 |
whichTexture | Which set of texture coordinates to change, 0 to NumTextureCoordinateArrays() - 1. |
void SetVertex | ( | GLuint | vertIndex, |
const float * | value | ||
) |
Set a vertex
vertIndex | The index of the vertex to change, 0 to VertexCount() - 1 |
*value | Vertex can either be 3 or 4 floats depending on the type |
void SetVertex | ( | GLuint | vertIndex, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Set the vertex at a given index to a coordinate
vertIndex | The index of the vertex to change, 0 to VertexCount() - 1 |
x | The x-coord |
y | The y-coord |
z | The z-coord |
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.
floatArray | Pointer to the array to read from. The array must be at least (numVertices * stride) bytes. |
numVertices | Number 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) |
|
inlinevirtual |
Returns polygon count for use in editor statistics
Implements GlsGeometryResource.
|
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
vertIndex | The index of the vertex |
attribIndex | The index of the generic vertex attribute to be modified |
value | void pointer to the value |
sizeBytes | size 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.
|
virtual |
Updates the bounding volume of this object This method should be called if the vertices change for picking and culling to work correctly.
Implements GlsGeometryResource.
unsigned int VertexCount | ( | ) | const |
Get the size of the vertex buffer
void VertexCount | ( | unsigned int | count | ) |
Set the size of the vertex buffer
count | How many items the Vertex Buffer contains. |
void VertexSort | ( | VertexSortData * | sortData | ) |
Sort the vertices, based on the input data
*sortData | An 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 |
|
protected |
Index buffers array