Batching for rectangles, points, lines?
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Batching for rectangles, points, lines?
I remember there was a user-made library called "pointbatch" which allowed batching things like rectangle and points, though I'm not sure whether it works in the newest version anymore. Is there a possibility you guys could make it an actual thing and add something like that natively to love2d? Performance wise this can be a huge win for things like GUI rendering.
Re: Batching for rectangles, points, lines?
Why not draw to a canvas and only redraw to the canvas when the GUI layout changes?
You can batch rectangles & lines really easily: add a 1x1 pixel image with the desired width/height/rotation to a spritebatch.
You can batch rectangles & lines really easily: add a 1x1 pixel image with the desired width/height/rotation to a spritebatch.
Re: Batching for rectangles, points, lines?
As szensk mentions, canvases can do that and much more. Is there anything a "pointbatch" would do easier or faster than how a canvas works?
I guess the same question applies to Spritebatches too...
I guess the same question applies to Spritebatches too...
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Batching for rectangles, points, lines?
SpriteBatches are faster than drawing all images seperately (onto canvas or screen). A Mesh is basically the equivalent of a SpriteBatch for non-AABBs (Quads)T-Bone wrote:As szensk mentions, canvases can do that and much more. Is there anything a "pointbatch" would do easier or faster than how a canvas works?
I guess the same question applies to Spritebatches too...
Meshes also support points, i am not sure why GL_LINES is not exposed... though thinking about it, it's probably because lines are not actually OpenGL lines but are hand-drawn by löve to enable things like caps etc.
So if you want to draw lines with a VBO you will need to tesselate them by yourself and build a mesh with them.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Batching for rectangles, points, lines?
Because in the situation that I need to use rects in, that's still slower. I wouldn't be asking for a pointbatch if I didn't know what I was talking about.szensk wrote:Why not draw to a canvas and only redraw to the canvas when the GUI layout changes?
You can batch rectangles & lines really easily: add a 1x1 pixel image with the desired width/height/rotation to a spritebatch.
Re: Batching for rectangles, points, lines?
OK then. What's the issue with a sprite batch of a 1x1 image with the width + height of the rectangle as scale? It works fine for many thousand of rectangles and definitely isn't slower than a sprite batch, because it is a sprite batch.Whatthefuck wrote:Because in the situation that I need to use rects in, that's still slower. I wouldn't be asking for a pointbatch if I didn't know what I was talking about.
Anything more complicated than a rectangle and you'll have to use meshes, as mentioned above.
- slime
- Solid Snayke
- Posts: 3172
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Batching for rectangles, points, lines?
You can also use a [wiki]Mesh[/wiki] as a 'point batch'. Create a new Mesh with the number of vertices set to the maximum number of points you want, and use the "points" draw mode with the texture argument left at nil. You can use [wiki]Mesh:setVertex[/wiki] and [wiki]Mesh:setDrawRange[/wiki] to modify where the points are drawn and what color they are, and how many points are drawn.
Generally I'd recommend just using the rectangle approach (via spritebatches, as mentioned above) instead, though.
Something like a shape batch and a line batch might potentially make it into LÖVE 0.10.0.
Generally I'd recommend just using the rectangle approach (via spritebatches, as mentioned above) instead, though.
Something like a shape batch and a line batch might potentially make it into LÖVE 0.10.0.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Batching for rectangles, points, lines?
Because calling :set on a spritebatch every frame is much more expensive than rendering a rect.szensk wrote:OK then. What's the issue with a sprite batch of a 1x1 image with the width + height of the rectangle as scale? It works fine for many thousand of rectangles and definitely isn't slower than a sprite batch, because it is a sprite batch.Whatthefuck wrote:Because in the situation that I need to use rects in, that's still slower. I wouldn't be asking for a pointbatch if I didn't know what I was talking about.
Anything more complicated than a rectangle and you'll have to use meshes, as mentioned above.
Okay, that mesh part is exactly what I was looking for, thanks a lot.slime wrote:You can also use a [wiki]Mesh[/wiki] as a 'point batch'. Create a new Mesh with the number of vertices set to the maximum number of points you want, and use the "points" draw mode with the texture argument left at nil. You can use [wiki]Mesh:setVertex[/wiki] and [wiki]Mesh:setDrawRange[/wiki] to modify where the points are drawn and what color they are, and how many points are drawn.
Generally I'd recommend just using the rectangle approach (via spritebatches, as mentioned above) instead, though.
Something like a shape batch and a line batch might potentially make it into LÖVE 0.10.0.
- slime
- Solid Snayke
- Posts: 3172
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Batching for rectangles, points, lines?
It shouldn't be, especially if you use LÖVE 0.9.2.Whatthefuck wrote:calling :set on a spritebatch every frame is much more expensive than rendering a rect.
Every love.graphics.rectangle call has to upload the rectangle's vertices to the GPU and issue a draw call. The spritebatch approach just sets the values of the vertices (without uploading them), then uploads all modified vertices at once later, and issues a single draw call for all sprites/rectangles in the batch.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Batching for rectangles, points, lines?
Wait, the :set call is now much cheaper than it was in 0.9.1? Because I remember :bind'ing spritebatches, then calling :set, and yet it was still much slower than rendering a rect. (in 0.9.1)slime wrote:It shouldn't be, especially if you use LÖVE 0.9.2.Whatthefuck wrote:calling :set on a spritebatch every frame is much more expensive than rendering a rect.
Every love.graphics.rectangle call has to upload the rectangle's vertices to the GPU and issue a draw call. The spritebatch approach just sets the values of the vertices (without uploading them), then uploads all modified vertices at once later, and issues a single draw call for all sprites/rectangles in the batch.
Sorry for the necro-bump, just need a small clarification.
EDIT: Just tried doing that, it is much more expensive to call :set every frame instead of drawing a rect, unfortunately
Who is online
Users browsing this forum: No registered users and 3 guests