lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
156 stars 24 forks source link

Stroke and fill in single VAO #3

Open lordmauve opened 5 years ago

lordmauve commented 5 years ago

Currently shapes may be either filled or not.

This was because the generic VAO class only maintains one buffer of indirect commands and makes only one draw call.

A filled, stroked shape can share vertices; only the draw mode and index sequence will differ. So these could be held in a single VAO.

We could subclass VAO to allow separate index allocations for stroke and fill commands. These could share the index buffer and simply exist as separate indirect draw commands.

Maybe the way to achieve this is to split out a separate manager for indirect draw commands currently integrated with the VAO code here to allow multiple per VAO.

Additionally shapes should be able to toggle filling and stroke visibility after creation, probably by zeroing and resetting the number of indices to draw within the draw command (a draw command of 0 vertices should be a no-op). The ability to set this would also allow line trails that grow without needing to be reallocated.

lordmauve commented 4 years ago

I think GL_LINE_ADJACENCY might be the way to do this.

A polygon of n vertices should allocate n + 1 vertices and assign vertex 0 a position (nan, nan), that also has the fill colour.

Then we can indicate to the geometry shader whether to draw strokes or fills. GL_LINE_ADJACENCY basically means we can send 4 vertices into each geometry shader invocation.