Fast Mesh Vertex Setting

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Fast Mesh Vertex Setting

Post by Tanner » Mon Jan 23, 2017 2:02 pm

Are you using meshes with thousands or tens of thousands of vertices? Are you updating those vertices every frame? Do you long for speed, blazing speed above all else, including memory safety and your game targets platforms where you have access to LuaJIT's FFI?


It doesn't seem to be on the wiki anywhere but this little gem does appear in the changelog for Love version 0.10.0: "Added the ability for and Mesh:setVertices to accept a Data object." Under the hood, what this means, is that instead of iterating over a Lua table and pulling vertex data from it, `memcpy` can be used on a piece of contiguous memory to buffer your vertex data. What this means is you're faster than this. Don't think you are, know you are. Come on. Stop trying to hit me and hit me.

Example implementation: ... 9ff571cff2

Essentially, we 'abuse' `love.image.newImageData` to allocate us a block of memory, cast that pointer into something useful using the FFI and then gain a 10 to 20 times speed increase when setting vertices.

# Lua Table

# Data Object
Benchmarks performed on a MacBook Pro (Retina, 13-inch, Early 2015).

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests