|
|
|
|
@ -22,15 +22,21 @@ struct SDLHandles
|
|
|
|
|
struct RenderState |
|
|
|
|
{ |
|
|
|
|
memory_arena* arena; |
|
|
|
|
// FIXME: revert back to num_/max_(models|textures)
|
|
|
|
|
model_assets* assets; |
|
|
|
|
texture_assets* textures; |
|
|
|
|
|
|
|
|
|
transforms* xforms; // NOTE: would be part of camera in libTangerine
|
|
|
|
|
SDLHandles* handles; |
|
|
|
|
|
|
|
|
|
GLContext* gl_ctx; |
|
|
|
|
gl_mesh_array* gl_mesh_arr; |
|
|
|
|
light_array lights; |
|
|
|
|
|
|
|
|
|
u32 num_gl_meshes; |
|
|
|
|
u32 max_gl_meshes; |
|
|
|
|
GLmesh* gl_meshes; |
|
|
|
|
|
|
|
|
|
u32 num_lights; |
|
|
|
|
u32 max_lights; |
|
|
|
|
PointLight* lights; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
mesh |
|
|
|
|
@ -101,33 +107,16 @@ getModel(RenderState* rs, const char* filepath)
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl_mesh* |
|
|
|
|
getFreeGLMesh(gl_mesh_array* gma) |
|
|
|
|
GLmesh* |
|
|
|
|
getFreeGLMesh(RenderState* rs) |
|
|
|
|
{ |
|
|
|
|
if (gma->count < gma->max) { |
|
|
|
|
gl_mesh* glm = &gma->gl_meshes[gma->count]; |
|
|
|
|
gma->count++; |
|
|
|
|
|
|
|
|
|
return glm; |
|
|
|
|
} |
|
|
|
|
if (rs->num_gl_meshes < rs->max_gl_meshes) |
|
|
|
|
return &rs->gl_meshes[rs->num_gl_meshes++]; |
|
|
|
|
|
|
|
|
|
std::cout << "Error, gl_mesh_array is full\n"; |
|
|
|
|
printf("%s(), Error, rs->gl_meshes is full\n", __FUNCTION__); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl_mesh_array* |
|
|
|
|
initGLMeshArray(memory_arena* arena, u32 count) |
|
|
|
|
{ |
|
|
|
|
gl_mesh_array* gma = |
|
|
|
|
(gl_mesh_array*) arenaAllocateBlock(arena, sizeof(gl_mesh_array)); |
|
|
|
|
gma->max = count; |
|
|
|
|
gma->count = 0; |
|
|
|
|
gma->gl_meshes = |
|
|
|
|
(gl_mesh*) arenaAllocateBlock(arena, count * sizeof(gl_mesh)); |
|
|
|
|
|
|
|
|
|
return gma; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define DEFAULT_SHADER_COUNT 64 |
|
|
|
|
#define DEFAULT_UBO_COUNT 32 |
|
|
|
|
GLContext* |
|
|
|
|
@ -163,7 +152,9 @@ initRenderState(memory_arena* arena)
|
|
|
|
|
(transforms*) arenaAllocateBlock(arena, sizeof(transforms)); |
|
|
|
|
rs->handles = |
|
|
|
|
(SDLHandles*) arenaAllocateBlock(arena, sizeof(SDLHandles)); |
|
|
|
|
rs->gl_mesh_arr = initGLMeshArray(arena, 256); |
|
|
|
|
rs->max_gl_meshes = 256; |
|
|
|
|
rs->gl_meshes = (GLmesh*) arenaAllocateBlock( |
|
|
|
|
arena, rs->max_gl_meshes * sizeof(GLmesh)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rs; |
|
|
|
|
@ -245,7 +236,7 @@ loadScene(RenderState* rs)
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < NUM_CUBES; i++) { |
|
|
|
|
gl_mesh* gmesh = getFreeGLMesh(rs->gl_mesh_arr); |
|
|
|
|
GLmesh* gmesh = getFreeGLMesh(rs); |
|
|
|
|
|
|
|
|
|
if (!gmesh) |
|
|
|
|
return false; |
|
|
|
|
@ -282,8 +273,8 @@ loop(RenderState* rs)
|
|
|
|
|
glClearColor(0.2, 0.2, 0.2, 1); |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < rs->gl_mesh_arr->count; i++) { |
|
|
|
|
gl_mesh& glm = rs->gl_mesh_arr->gl_meshes[i]; |
|
|
|
|
for (u32 i = 0; i < rs->num_gl_meshes; i++) { |
|
|
|
|
GLmesh& glm = rs->gl_meshes[i]; |
|
|
|
|
*glm.model_xform = glm::rotate( |
|
|
|
|
*glm.model_xform, (float) M_PI / 60, glm::vec3(0, 1, 0)); |
|
|
|
|
renderVAO(&glm); |
|
|
|
|
|