|
|
|
|
@ -270,14 +270,47 @@ addShaders(RenderState* rs)
|
|
|
|
|
bool |
|
|
|
|
loadScene(RenderState* rs) |
|
|
|
|
{ |
|
|
|
|
shader_program* s_default = getShaderByName("default", rs->gl_ctx); |
|
|
|
|
shader_program* s_debug = getShaderByName("debug", rs->gl_ctx); |
|
|
|
|
if (!s_default || !s_debug) return false; |
|
|
|
|
// TODO: come up with an easy to use interface for loading a model, setting
|
|
|
|
|
// up the buffer to attrib mappings, and initializing a render group
|
|
|
|
|
|
|
|
|
|
// NOTE: load model and mesh
|
|
|
|
|
model* tex_cube = getModelByPath(&rs->assets, "../data/textured_cube.gltf"); |
|
|
|
|
assert(tex_cube != nullptr); |
|
|
|
|
assert(tex_cube); |
|
|
|
|
const mesh& texmesh = tex_cube->meshes[0]; |
|
|
|
|
|
|
|
|
|
// NOTE: load shader
|
|
|
|
|
shader_program* s_default = getShaderByName("default", rs->gl_ctx); |
|
|
|
|
assert(s_default); |
|
|
|
|
|
|
|
|
|
// NOTE: set up mapping between shader attributes, and vertex buffers
|
|
|
|
|
GLVertexAttrib* df_pos_attrib = |
|
|
|
|
getVertexAttribByName(s_default, "position"); |
|
|
|
|
GLVertexAttrib* df_uv_attrib = getVertexAttribByName(s_default, "uv"); |
|
|
|
|
assert(df_pos_attrib && df_uv_attrib); |
|
|
|
|
|
|
|
|
|
GLBufferToAttribMapping default_mappings[2] = { |
|
|
|
|
{ "position", df_pos_attrib, texmesh.vertices }, |
|
|
|
|
{ "uvs", df_uv_attrib, texmesh.uvs } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// NOTE: init new render group
|
|
|
|
|
RenderGroup* debug_cube_group = getFreeRenderGroup(rs); |
|
|
|
|
assert(debug_cube_group); |
|
|
|
|
initRenderGroup(debug_cube_group, rs->rg_arena, s_default, 1, |
|
|
|
|
"orange_cubes"); |
|
|
|
|
|
|
|
|
|
// NOTE: init entity
|
|
|
|
|
Entity* e = getFreeEntity(debug_cube_group); |
|
|
|
|
assert(e); |
|
|
|
|
|
|
|
|
|
initEntity(e, rs->gl_ctx, rs->rg_arena, tex_cube, |
|
|
|
|
2, default_mappings, "textured_box"); |
|
|
|
|
scaleEntity(e, 5); |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
shader_program* s_debug = getShaderByName("debug", rs->gl_ctx); |
|
|
|
|
if (!s_debug) 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; |
|
|
|
|
@ -314,26 +347,7 @@ loadScene(RenderState* rs)
|
|
|
|
|
|
|
|
|
|
setEntityPosition(e, cube_locs[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RenderGroup* debug_cube_group = getFreeRenderGroup(rs); |
|
|
|
|
assert(debug_cube_group != nullptr); |
|
|
|
|
initRenderGroup(debug_cube_group, rs->rg_arena, s_default, 1, |
|
|
|
|
"orange_cubes"); |
|
|
|
|
Entity* e = getFreeEntity(debug_cube_group); |
|
|
|
|
assert(e != nullptr); |
|
|
|
|
|
|
|
|
|
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, default_mappings, "textured_box"); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|