Browse Source

fix bug reusing attrib_mappings variable in loadScene()

main
cinnaboot 5 years ago
parent
commit
d71a988be4
  1. 29
      src/main.cpp

29
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;
}

Loading…
Cancel
Save