Register
Handmade Hero»Forums»Game»Day 229: why don't use a depth buffer instead of sorting?
9 posts
Day 229: why don't use a depth buffer instead of sorting?
7 months, 2 weeks ago Edited by Terans on Dec. 19, 2020, 9:53 a.m. Reason: Initial post
At day 229 we sort the render elements before rendering them in order, but could we use a depth buffer with the sort key as the depth value? This would take some more memory but isn't this more efficient, instead of sorting all the render elements?
Miles
119 posts / 4 projects
Day 229: why don't use a depth buffer instead of sorting?
7 months, 2 weeks ago
The sprites have alpha transparency, so they need to be rendered back-to-front in order to get alpha blending. Imagine you draw a transparent portion of a sprite with the depth buffer, then you draw another sprite behind it. The sprite in back should be visible, but it won't be drawn because it fails the depth test. This page has some good visual examples of what that looks like: https://learnopengl.com/Advanced-OpenGL/Blending