a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 72a62a1f652db5629d3e5590a794a1b9b0c9b63e
parent c39c262c868d24698f5a6a7c26e41610f947b60a
Author: amin <dev@aminmesbah.com>
Date:   Mon, 10 Jun 2019 04:56:12 +0000

Fix two render order bugs

The first bug was that we were not binding an initial EBO at the
beginning of rendering each frame. That meant that the first frame was
rendered normally, but every subsequent used the EBO that was bound at
the end of the first.

The second was that we were using RENDER_LAYER_TILES as the initial
layer type when iterating the enum, which assumed that it was the first
value in the enum. Since we want to be able to change the order around,
we can't make that assumption. It caused very confusing render output
and was surprisingly difficult to track down.

FossilOrigin-Name: b97e5e1746061fdf4cc255a2d700e5dc5b02b55d0e35cad1c782cdfcfb8585c5
Diffstat:
Msrc/render.c | 23++++++++++++++++++++---
Msrc/render.h | 2+-
2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/render.c b/src/render.c @@ -67,7 +67,8 @@ internal void render_jobs_draw(struct RendererState *renderer) shader_setm4(&renderer->shader, "view", &renderer->view); GLuint current_ebo = renderer->quad_ebo; - for (u32 i = 0; i < renderer->queue_count; i++) + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, current_ebo); + for (size_t i = 0; i < renderer->queue_count; i++) { struct RenderJob j = renderer->queue[i]; if (current_ebo != j.ebo) @@ -81,10 +82,16 @@ internal void render_jobs_draw(struct RendererState *renderer) { glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); } - else + else if (j.ebo == renderer->rect_ebo) { glDrawElements(GL_LINES, 8, GL_UNSIGNED_INT, 0); } + else + { + assert(false); + } + + assert(j.layer < NUM_RENDER_LAYERS); } renderer->queue_count = 0; @@ -104,14 +111,24 @@ internal void render_jobs_sort(struct RendererState *renderer, struct StackAlloc layer_pop_count[j.layer] += 1; } + { + size_t sum = 0; + for (size_t i = 0; i < NUM_RENDER_LAYERS; i++) + { + sum += layer_pop_count[i]; + } + assert(sum == renderer->queue_count); + } + struct RenderJob *sorted = mem_st_alloc_buffer(allocator, struct RenderJob, renderer->queue_count); size_t layer_pop_count_sorted[NUM_RENDER_LAYERS] = {0}; for (size_t i = 0; i < renderer->queue_count; i++) { struct RenderJob j = queue[i]; + assert(j.layer < NUM_RENDER_LAYERS); size_t insertion_index = 0; - for (enum RenderLayer l = RENDER_LAYER_TILES; l < j.layer; l++) + for (enum RenderLayer l = 0; l < j.layer; l++) { insertion_index += layer_pop_count[l]; } diff --git a/src/render.h b/src/render.h @@ -3,8 +3,8 @@ enum RenderLayer { RENDER_LAYER_TILES = 0, - RENDER_LAYER_DEBUG, RENDER_LAYER_PLAYER, + RENDER_LAYER_DEBUG, NUM_RENDER_LAYERS, };