ultraq / redhorizon

Recreating the original 2D Command & Conquer games
Apache License 2.0
6 stars 4 forks source link

Build texture atlases to remove batch rendering limit being tied to available texture units #47

Closed ultraq closed 3 years ago

ultraq commented 3 years ago

Each individual image is still being assigned its own unique texture, which makes lower-power graphics hardware, like the Intel integrated graphics I'm rocking in my MacBook, not get as much as it could from the batch renderer since it's limited by the number of available texture units.

By building out a texture atlas of all of the tiles used in the current map, and having texture coordinates into said atlas, I should be able to reduce the number of texture switches in the batch renderer, allowing it to render far more objects per batch.

ultraq commented 3 years ago

Done, though I then ran into a bottleneck: the batch renderer is constantly shuttling data from main memory to the GPU, and no matter what I did I was running into the limit of how much I could send down that pipe.

So, in conjunction with this change, I've also created a mechanism for bundling materials together into a single "material" that, when renderered, renders all of the other materials in a single draw call. This bundled material also lives in GPU memory, so there's no more memory transfer bottleneck, allowing even the integrated graphics to go fast 😁

Given all I do is render map tiles for now, I've bundled all map tiles into one of these materials. It does render the object culling somewhat obsolete, until I have other objects to draw.