FoundationGames / Phonos

A FabricMC mod adding radio and audio related blocks.
MIT License
12 stars 8 forks source link

Lazy VBO generation #42

Closed jaskarth closed 11 months ago

jaskarth commented 11 months ago

This changeset implements dynamic buffer baking for phonos cables, which greatly improves rendering performance. On the BlanketCon 2023 world, I get roughly double the FPS (55 -> 115) from these changes. The primary slowdown is from submitting so many vertices to the immediate mode vertex buffers, which are re-calculated and submitted every frame. using VBOs allows the renderer to re-build the vertices only when a change to the render state occurs, and re-use the calculated vertex data every frame with a single draw call.

Caveats

The downside of using a vertex buffer for this kind of rendering is that you're forced to maintain the buffer manually, which can lead to hard to detect native memory leaks if not closed properly when the state changes or when the block entity is unloaded. In addition, LODs are not supported with this setup since it would need a refresh of the buffer, which is unpractical. In addition, the frustum culling is disabled, but it could be fairly easily re-enabled by checking the frustum against all of the connected cables instead of just the cable being rendered.

In addition, this patch was kind of thrown together, and while it works it has some unclean code and potential bugs. I would highly suggest not integrating in its current form.