Added a method to VertexIndex to determine the size in bytes of an element in the index array

This commit is contained in:
Alex Szpakowski
2013-01-30 17:50:32 -04:00
parent a9211a1389
commit de959b7275
2 changed files with 23 additions and 5 deletions
+11 -1
View File
@@ -253,6 +253,7 @@ VertexBuffer *VertexIndex::element_array = NULL;
VertexIndex::VertexIndex(size_t size)
: size(size)
, elementSize(0)
{
// The upper limit is the maximum of GLuint divided by six (the number
// of indices per size) and divided by the size of GLuint. This guarantees
@@ -287,6 +288,11 @@ GLenum VertexIndex::getType(size_t s) const
// if buffer-size > max(GLushort) then GL_UNSIGNED_INT else GL_UNSIGNED_SHORT
}
size_t VertexIndex::getElementSize()
{
return elementSize;
}
VertexBuffer *VertexIndex::getVertexBuffer() const
{
return element_array;
@@ -342,9 +348,12 @@ void VertexIndex::resize(size_t size)
}
VertexBuffer *new_element_array;
// Depending on the size, a switch to int and more memory is needed.
GLenum target_type = getType(size);
size_t array_size = (target_type == GL_UNSIGNED_SHORT ? sizeof(GLushort) : sizeof(GLuint)) * 6 * size;
size_t elem_size = (target_type == GL_UNSIGNED_SHORT) ? sizeof(GLushort) : sizeof(GLuint);
size_t array_size = elem_size * 6 * size;
// Create may throw out-of-memory exceptions.
// VertexIndex will propagate the exception and keep the old VertexBuffer.
@@ -362,6 +371,7 @@ void VertexIndex::resize(size_t size)
delete element_array;
element_array = new_element_array;
maxSize = size;
elementSize = elem_size;
switch (target_type)
{
+12 -4
View File
@@ -331,10 +331,6 @@ private:
// Set if the buffer was modified while operating on gpu memory
// and needs to be synchronized.
bool is_dirty;
// Usage hint for map()/unmap() pair. Same as `access' parameter in
// glBufferData or 0 if not mapped.
GLenum mapped_access;
};
/**
@@ -409,6 +405,15 @@ public:
return getType(maxSize);
}
/**
* Returns the size in bytes of an element in the element array.
* Can be used with getPointer to calculate an offset into the array based
* on a number of elements.
*
* @return The size of an element in bytes.
**/
size_t getElementSize();
/**
* Returns the pointer to the VertexBuffer.
* The pointer will change if a new size request or removal causes
@@ -463,6 +468,9 @@ private:
// The size of the array requested by this instance.
size_t size;
// The size in bytes of an element in the element array.
size_t elementSize;
// The current VertexBuffer size. 0 means no VertexBuffer.
static size_t maxSize;
// The list of sizes. Needs to be kept sorted in ascending order.