mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Clean up some Mesh code
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -174,7 +174,7 @@ private:
|
||||
|
||||
struct AttachedAttribute
|
||||
{
|
||||
Buffer *buffer;
|
||||
StrongRef<Buffer> buffer;
|
||||
int index;
|
||||
AttributeStep step;
|
||||
bool enabled;
|
||||
|
||||
Reference in New Issue
Block a user