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)
{