|
@@ -253,6 +253,7 @@ VertexBuffer *VertexIndex::element_array = NULL;
|
|
|
|
|
|
VertexIndex::VertexIndex(size_t size)
|
|
VertexIndex::VertexIndex(size_t size)
|
|
: size(size)
|
|
: size(size)
|
|
|
|
+ , elementSize(0)
|
|
{
|
|
{
|
|
// The upper limit is the maximum of GLuint divided by six (the number
|
|
// 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
|
|
// 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
|
|
// if buffer-size > max(GLushort) then GL_UNSIGNED_INT else GL_UNSIGNED_SHORT
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+size_t VertexIndex::getElementSize()
|
|
|
|
+{
|
|
|
|
+ return elementSize;
|
|
|
|
+}
|
|
|
|
+
|
|
VertexBuffer *VertexIndex::getVertexBuffer() const
|
|
VertexBuffer *VertexIndex::getVertexBuffer() const
|
|
{
|
|
{
|
|
return element_array;
|
|
return element_array;
|
|
@@ -342,9 +348,12 @@ void VertexIndex::resize(size_t size)
|
|
}
|
|
}
|
|
|
|
|
|
VertexBuffer *new_element_array;
|
|
VertexBuffer *new_element_array;
|
|
|
|
+
|
|
// Depending on the size, a switch to int and more memory is needed.
|
|
// Depending on the size, a switch to int and more memory is needed.
|
|
GLenum target_type = getType(size);
|
|
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.
|
|
// Create may throw out-of-memory exceptions.
|
|
// VertexIndex will propagate the exception and keep the old VertexBuffer.
|
|
// VertexIndex will propagate the exception and keep the old VertexBuffer.
|
|
@@ -362,6 +371,7 @@ void VertexIndex::resize(size_t size)
|
|
delete element_array;
|
|
delete element_array;
|
|
element_array = new_element_array;
|
|
element_array = new_element_array;
|
|
maxSize = size;
|
|
maxSize = size;
|
|
|
|
+ elementSize = elem_size;
|
|
|
|
|
|
switch (target_type)
|
|
switch (target_type)
|
|
{
|
|
{
|