Clean up some Mesh code

This commit is contained in:
Alex Szpakowski
2020-02-01 15:59:38 -04:00
parent 2572f0c7a1
commit c9809d8d82
4 changed files with 11 additions and 35 deletions
+4 -16
View File
@@ -158,23 +158,11 @@ public:
{
public:
Mapper(Buffer &buffer)
: buf(buffer)
{
elems = buf.map();
}
Mapper(Buffer &buffer) : buffer(buffer) { data = buffer.map(); }
~Mapper() { buffer.unmap(); }
~Mapper()
{
buf.unmap();
}
void *get() { return elems; }
private:
Buffer &buf;
void *elems;
Buffer &buffer;
void *data;
}; // Mapper
+1 -1
View File
@@ -176,7 +176,7 @@ void Graphics::createQuadIndexBuffer()
quadIndexBuffer = newIndexBuffer(INDEX_UINT16, nullptr, size, BUFFERUSAGE_STATIC, 0);
Buffer::Mapper map(*quadIndexBuffer);
fillIndices(TRIANGLEINDEX_QUADS, 0, LOVE_UINT16_MAX, (uint16 *) map.get());
fillIndices(TRIANGLEINDEX_QUADS, 0, LOVE_UINT16_MAX, (uint16 *) map.data);
}
Quad *Graphics::newQuad(Quad::Viewport v, double sw, double sh)
+5 -17
View File
@@ -118,12 +118,6 @@ Mesh::Mesh(graphics::Graphics *gfx, const std::vector<Buffer::DataDeclaration> &
Mesh::~Mesh()
{
delete vertexScratchBuffer;
for (const auto &attrib : attachedAttributes)
{
if (attrib.second.buffer != nullptr && attrib.second.buffer != vertexBuffer.get())
attrib.second.buffer->release();
}
}
void Mesh::setupAttachedAttributes()
@@ -282,28 +276,22 @@ void Mesh::attachAttribute(const std::string &name, Buffer *buffer, const std::s
throw love::Exception("A maximum of %d attributes can be attached at once.", VertexAttributes::MAX);
newattrib.buffer = buffer;
newattrib.enabled = oldattrib.buffer ? oldattrib.enabled : true;
newattrib.enabled = oldattrib.buffer.get() ? oldattrib.enabled : true;
newattrib.index = buffer->getDataMemberIndex(attachname);
newattrib.step = step;
if (newattrib.index < 0)
throw love::Exception("The specified vertex buffer does not have a vertex attribute named '%s'", attachname.c_str());
newattrib.buffer->retain();
attachedAttributes[name] = newattrib;
if (oldattrib.buffer)
oldattrib.buffer->release();
}
bool Mesh::detachAttribute(const std::string &name)
{
auto it = attachedAttributes.find(name);
if (it != attachedAttributes.end() && it->second.buffer != vertexBuffer.get())
if (it != attachedAttributes.end())
{
it->second.buffer->release();
attachedAttributes.erase(it);
if (getAttributeIndex(name) != -1)
@@ -340,7 +328,7 @@ void Mesh::flush()
template <typename T>
static void copyToIndexBuffer(const std::vector<uint32> &indices, Buffer::Mapper &buffermap, size_t maxval)
{
T *elems = (T *) buffermap.get();
T *elems = (T *) buffermap.data;
for (size_t i = 0; i < indices.size(); i++)
{
@@ -405,7 +393,7 @@ void Mesh::setVertexMap(IndexDataType datatype, const void *data, size_t datasiz
return;
Buffer::Mapper ibomap(*indexBuffer);
memcpy(ibomap.get(), data, datasize);
memcpy(ibomap.data, data, datasize);
useIndexBuffer = true;
indexDataType = datatype;
@@ -541,7 +529,7 @@ void Mesh::drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount)
if (!attrib.second.enabled)
continue;
Buffer *buffer = attrib.second.buffer;
Buffer *buffer = attrib.second.buffer.get();
int attributeindex = -1;
// If the attribute is one of the LOVE-defined ones, use the constant
+1 -1
View File
@@ -174,7 +174,7 @@ private:
struct AttachedAttribute
{
Buffer *buffer;
StrongRef<Buffer> buffer;
int index;
AttributeStep step;
bool enabled;