Cleaned up some index buffer code.

This commit is contained in:
Alex Szpakowski
2015-06-16 21:27:19 -03:00
parent 073570b7af
commit 2dc8a8ea45
10 changed files with 121 additions and 166 deletions
+16 -38
View File
@@ -266,7 +266,7 @@ private:
/**
* VertexIndex manages one shared GLBuffer that stores the indices for an
* QuadIndices manages one shared GLBuffer that stores the indices for an
* element array. Vertex arrays using the vertex structure (or anything else
* that can use the pattern below) can request a size and use it for the
* drawElements call.
@@ -280,14 +280,14 @@ private:
* indices[i*6 + 5] = i*4 + 3;
*
* There will always be a large enough GLBuffer around until all
* VertexIndex instances have been deleted.
* QuadIndices instances have been deleted.
*
* Q: Why have something like VertexIndex?
* Q: Why have something like QuadIndices?
* A: The indices for the SpriteBatch do not change, only the array size
* varies. Using one GLBuffer for all element arrays removes this
* duplicated data and saves some memory.
*/
class VertexIndex
class QuadIndices
{
public:
/**
@@ -297,16 +297,16 @@ public:
*
* @param size The requested size in groups of 6 indices.
*/
VertexIndex(size_t size);
QuadIndices(size_t size);
VertexIndex(const VertexIndex &other);
VertexIndex &operator = (const VertexIndex &other);
QuadIndices(const QuadIndices &other);
QuadIndices &operator = (const QuadIndices &other);
/**
* Removes an entry from the list of sizes and resizes the GLBuffer
* if needed.
*/
~VertexIndex();
~QuadIndices();
/**
* Returns the number of index groups.
@@ -318,8 +318,8 @@ public:
/**
* Returns the number of indices that the passed element count will have.
* Use VertexIndex::getSize to get the full index count for that
* VertexIndex instance.
* Use QuadIndices::getSize to get the full index count for that
* QuadIndices instance.
*
* @param elements The number of elements to calculate the index count for.
* @return The index count.
@@ -369,30 +369,6 @@ public:
private:
/**
* Adds a new size to the size list, then sorts and resizes it if needed.
*
* @param newSize The new size to be added.
*/
void addSize(size_t newSize);
/**
* Removes a size from the size list, then sorts and resizes it if needed.
*
* @param oldSize The old size to be removed.
*/
void removeSize(size_t oldSize);
/**
* Resizes the GLBuffer to the requested size.
* This function takes care of choosing the correct integer type and
* allocating and deleting the GLBuffer instance. It also has some
* fallback logic in case the memory ran out.
*
* @param size The requested GLBuffer size. Passing 0 deletes the GLBuffer without allocating a new one.
*/
void resize(size_t size);
/**
* Adds all indices to the array with the type T.
* There are no checks for the correct types or overflows. The calling
@@ -405,12 +381,14 @@ private:
// The size in bytes of an element in the element array.
static size_t elementSize;
// The current GLBuffer size. 0 means no GLBuffer.
static size_t maxSize;
// The list of sizes. Needs to be kept sorted in ascending order.
static std::list<size_t> sizeRefs;
// The GLBuffer for the element array. Can be NULL.
static GLBuffer *element_array;
static size_t objectCount;
// The GLBuffer for the element array. Can be null.
static GLBuffer *indexBuffer;
};
} // opengl