|
@@ -64,6 +64,7 @@ Mesh::Mesh(const std::vector<AttribFormat> &vertexformat, const void *data, size
|
|
|
, vertexCount(0)
|
|
|
, vertexStride(0)
|
|
|
, ibo(nullptr)
|
|
|
+ , useIndexBuffer(false)
|
|
|
, elementCount(0)
|
|
|
, elementDataType(0)
|
|
|
, drawMode(drawmode)
|
|
@@ -90,6 +91,7 @@ Mesh::Mesh(const std::vector<AttribFormat> &vertexformat, int vertexcount, DrawM
|
|
|
, vertexCount((size_t) vertexcount)
|
|
|
, vertexStride(0)
|
|
|
, ibo(nullptr)
|
|
|
+ , useIndexBuffer(false)
|
|
|
, elementCount(0)
|
|
|
, elementDataType(getGLDataTypeFromMax(vertexcount))
|
|
|
, drawMode(drawmode)
|
|
@@ -414,6 +416,7 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
|
|
|
if (!ibo && size > 0)
|
|
|
ibo = new GLBuffer(size, nullptr, GL_ELEMENT_ARRAY_BUFFER, vbo->getUsage());
|
|
|
|
|
|
+ useIndexBuffer = true;
|
|
|
elementCount = map.size();
|
|
|
|
|
|
if (!ibo || elementCount == 0)
|
|
@@ -437,6 +440,11 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
|
|
|
elementDataType = datatype;
|
|
|
}
|
|
|
|
|
|
+void Mesh::setVertexMap()
|
|
|
+{
|
|
|
+ useIndexBuffer = false;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Copies index data from a mapped buffer to a vector.
|
|
|
**/
|
|
@@ -448,14 +456,17 @@ static void copyFromIndexBuffer(void *buffer, size_t count, std::vector<uint32>
|
|
|
indices.push_back((uint32) elems[i]);
|
|
|
}
|
|
|
|
|
|
-void Mesh::getVertexMap(std::vector<uint32> &map) const
|
|
|
+bool Mesh::getVertexMap(std::vector<uint32> &map) const
|
|
|
{
|
|
|
- if (!ibo || elementCount == 0)
|
|
|
- return;
|
|
|
+ if (!useIndexBuffer)
|
|
|
+ return false;
|
|
|
|
|
|
map.clear();
|
|
|
map.reserve(elementCount);
|
|
|
|
|
|
+ if (!ibo || elementCount == 0)
|
|
|
+ return true;
|
|
|
+
|
|
|
GLBuffer::Bind ibobind(*ibo);
|
|
|
|
|
|
// We unmap the buffer in Mesh::draw, Mesh::setVertexMap, and Mesh::flush.
|
|
@@ -472,6 +483,8 @@ void Mesh::getVertexMap(std::vector<uint32> &map) const
|
|
|
copyFromIndexBuffer<uint32>(buffer, elementCount, map);
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
size_t Mesh::getVertexMapCount() const
|
|
@@ -588,7 +601,7 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
|
|
|
|
|
|
gl.prepareDraw();
|
|
|
|
|
|
- if (ibo && elementCount > 0)
|
|
|
+ if (useIndexBuffer && ibo && elementCount > 0)
|
|
|
{
|
|
|
// Use the custom vertex map (index buffer) to draw the vertices.
|
|
|
GLBuffer::Bind ibo_bind(*ibo);
|