Page 1 of 1

Hooking up SpriteBatch to vertex buffer?

Posted: Fri Feb 05, 2016 3:57 am
by perrako
Howdy folks! I'm hooking up LiquidFun to Lua/Love2D with LuaBridge and having trouble with rendering. Most of the work getting the two to talk is already done, but I'm having a spot of bother rendering it. LiquidFun stores its liquid particle positions in a contiguous buffer in memory to make calling things like glVertexPointer the efficient way to render them. The closest equivalent to glVertexPointer in Love2D would be SpriteBatch, but I can't figure out how to give SpriteBatch a pointer to the positions buffer.

Is there a good way to do this without modifying and recompiling Love? I could rewrite or modify SpriteBatch itself, but I'd love to make it easier to distribute my LiquidFun bindings.

Re: Hooking up SpriteBatch to vertex buffer?

Posted: Fri Feb 05, 2016 11:27 am
by slime
[wiki]Mesh[/wiki]es are the closest thing to Vertex Buffers in LÖVE, currently.

[wiki]Mesh:setVertices[/wiki] can also accept a [wiki]Data[/wiki] object as of 0.10.0 (although I haven't documented that on the wiki yet), and you can copy bytes to a Data object with the FFI by using [wiki]Data:getPointer[/wiki] and [wiki]Data:getSize[/wiki] with ffi.copy.

Re: Hooking up SpriteBatch to vertex buffer?

Posted: Fri Feb 05, 2016 10:37 pm
by perrako
Ah, good idea. I'm able to get that about 50% working, but I can't seem to get Mesh to render Point Sprites. I can get it rendering uniform squares taken from one texture coordinate, but nothing like this. Before I go about writing a vertex shader to transform the point into a quad, is there something I'm missing inside of Mesh that would do what I want?

Re: Hooking up SpriteBatch to vertex buffer?

Posted: Fri Feb 05, 2016 10:39 pm
by slime
LÖVE doesn't provide a way to enable/use point-sprite rendering.

Re: Hooking up SpriteBatch to vertex buffer?

Posted: Fri Feb 05, 2016 11:00 pm
by perrako
Gotcha. Alright, I'll use SpriteBatch until performance seems to be a non-starter, then write a fragment shader to try and make it work.