From d71a988be465a12bf9c5ba8b6df2e0cb949431f1 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Tue, 4 Jan 2022 08:25:18 -0500 Subject: [PATCH] fix bug reusing attrib_mappings variable in loadScene() --- src/main.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1cc5680..b8a8e3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -253,13 +253,13 @@ loadScene(RenderState* rs) assert(tex_cube != nullptr); const mesh& texmesh = tex_cube->meshes[0]; - GLVertexAttrib* pos_attrib = getVertexAttribByName(s_debug, "position"); - GLVertexAttrib* normal_attrib = getVertexAttribByName(s_debug, "normal"); - if (!pos_attrib || !normal_attrib) return false; + GLVertexAttrib* db_pos_attrib = getVertexAttribByName(s_debug, "position"); + GLVertexAttrib* db_normal_attrib = getVertexAttribByName(s_debug, "normal"); + if (!db_pos_attrib || !db_normal_attrib) return false; - GLBufferToAttribMapping attrib_mappings[2] = { - { "position", pos_attrib, texmesh.vertices }, - { "normal", normal_attrib, texmesh.normals } + GLBufferToAttribMapping debug_mappings[2] = { + { "position", db_pos_attrib, texmesh.vertices }, + { "normal", db_normal_attrib, texmesh.normals } }; const u32 NUM_CUBES = 4; @@ -280,7 +280,7 @@ loadScene(RenderState* rs) assert(e != nullptr); if (!initEntity(e, rs->gl_ctx, rs->rg_arena, tex_cube, - 2, attrib_mappings, "debug_box")) + 2, debug_mappings, "debug_box")) { // FIXME: this doesn't actually do anything freeRenderGroup(orange_cubes, rs->rg_arena); @@ -296,10 +296,19 @@ loadScene(RenderState* rs) "orange_cubes"); Entity* e = getFreeEntity(debug_cube_group); assert(e != nullptr); - // FIXME: this a bug, we're reusing the attrib_mappings from the debug - // shader for the default shader, which could have different attributes + + GLVertexAttrib* df_pos_attrib = + getVertexAttribByName(s_default, "position"); + GLVertexAttrib* df_uv_attrib = getVertexAttribByName(s_default, "uv"); + if (!df_pos_attrib || !df_uv_attrib) return false; + + GLBufferToAttribMapping default_mappings[2] = { + { "position", df_pos_attrib, texmesh.vertices }, + { "uvs", df_uv_attrib, texmesh.uvs } + }; + initEntity(e, rs->gl_ctx, rs->rg_arena, tex_cube, - 2, attrib_mappings, "orange_box"); + 2, default_mappings, "textured_box"); return true; }