Alex Szpakowski committed 1b457f4

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

Comments (0)

Files changed (2)


 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
 	// 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;
 	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.
 	delete element_array;
 	element_array = new_element_array;
 	maxSize = size;
+	elementSize = elem_size;
 	switch (target_type)


 	// 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;
+	 * 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
 	 * a VertexBuffer resize. It is recommended to retrieve the pointer
 	// 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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.