Add love.graphics.newMesh variant to create a Mesh from existing Buffers.

This allows a Mesh to be created that doesn't have its own internal vertex buffer and purely references other vertex buffers instead.

The prototype looks like this:
mesh = love.graphics.newMesh(attributelist, drawmode)

where attributelist is an array of tables each with the following fields, similar to Mesh:attachAttribute:
{
    buffer = vertexbuffer,
    name = "VertexPosition", -- the name this vertex attribute will use in a shader
    nameinbuffer = nil, -- the name of the attribute in the vertex buffer. Defaults to the name field.
    step = nil, -- vertex attribute step ("pervertex" or "perinstance"), defaults to "pervertex".
    startindex = nil, -- 1-based array index within the given vertex buffer where the attribute data will start being pulled from during rendering. Defaults to 1.
}
This commit is contained in:
Sasha Szpakowski
2023-09-30 20:12:43 -03:00
parent 691d910c3e
commit dbc7d7f3ca
3 changed files with 110 additions and 17 deletions
+2
View File
@@ -56,6 +56,7 @@ public:
std::string name;
StrongRef<Buffer> buffer;
StrongRef<Mesh> mesh;
std::string nameInBuffer;
int indexInBuffer;
int startArrayIndex;
AttributeStep step;
@@ -186,6 +187,7 @@ private:
void setupAttachedAttributes();
int getAttachedAttributeIndex(const std::string &name) const;
void finalizeAttribute(Graphics *gfx, BufferAttribute &attrib) const;
void drawInternal(Graphics *gfx, const Matrix4 &m, int instancecount, Buffer *indirectargs, int argsindex);