Skip to content

Commit

Permalink
restructured forward renderer, stripped deferred one for the time being
Browse files Browse the repository at this point in the history
  • Loading branch information
exezin committed Dec 3, 2019
1 parent 5442799 commit c28d1a8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 494 deletions.
35 changes: 21 additions & 14 deletions src/exengine/render/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void ex_render(ex_renderer_e renderer, ex_renderable_t *renderables)


/* -- LIGHT DEPTH MAPS -- */
ex_renderlist_t *point_lights = renderables->point_lights;
ex_renderlist_t *models = renderables->models;
ex_renderlist_t *point_lights = &renderables->point_lights;
ex_renderlist_t *models = &renderables->models;

// render light depth maps
glCullFace(GL_BACK);
Expand All @@ -56,7 +56,7 @@ void ex_render(ex_renderer_e renderer, ex_renderable_t *renderables)
for (int j=0; j<models->count; j++) {
ex_model_t *model = (ex_model_t*)models->nodes[j].obj;

if (!model->is_shadow)
if (model->is_shadow)
ex_render_model(model, pointfbo_shader);
}
}
Expand All @@ -81,8 +81,8 @@ void ex_render(ex_renderer_e renderer, ex_renderable_t *renderables)
void ex_render_forward(ex_renderable_t *renderables)
{
// render lists
ex_renderlist_t *point_lights = renderables->point_lights;
ex_renderlist_t *models = renderables->models;
ex_renderlist_t *point_lights = &renderables->point_lights;
ex_renderlist_t *models = &renderables->models;

// bind main framebuffer
glViewport(0, 0, framebuffer->width, framebuffer->height);
Expand Down Expand Up @@ -116,9 +116,9 @@ void ex_render_forward(ex_renderable_t *renderables)
for (int i=0; i<point_lights->count; i++) {
ex_point_light_t *light = (ex_point_light_t*)point_lights->nodes[i].obj;

if (light->is_visible) {
sprintf(buff, "u_point_lights[%ul]", (uint32_t)pcount++);
ex_render_point_light_draw(light, forward_shader, buff);
if (light->is_visible && !light->is_shadow) {
sprintf(buff, "u_point_lights[%u]", (uint32_t)pcount++);
ex_render_point_light(light, forward_shader, buff);
}
}

Expand All @@ -127,9 +127,7 @@ void ex_render_forward(ex_renderable_t *renderables)
glUniform1i(ex_uniform(forward_shader, "u_ambient_pass"), 1);
for (int i=0; i<models->count; i++) {
ex_model_t *model = (ex_model_t*)models->nodes[i].obj;

if (!model->is_shadow)
ex_render_model(model, forward_shader);
ex_render_model(model, forward_shader);
}
glUniform1i(ex_uniform(forward_shader, "u_ambient_pass"), 0);
glUniform1i(ex_uniform(forward_shader, "u_point_count"), 0);
Expand All @@ -146,13 +144,12 @@ void ex_render_forward(ex_renderable_t *renderables)
if (!light->is_shadow || !light->is_visible)
continue;

ex_render_point_light_draw(light, forward_shader, NULL);
ex_render_point_light(light, forward_shader, NULL);
for (int i=0; i<models->count; i++) {
ex_model_t *model = (ex_model_t*)models->nodes[i].obj;
ex_render_model(model, forward_shader);
}
}
glUniform1i(ex_uniform(forward_shader, "u_point_active"), 0);
glDisable(GL_BLEND);

glBindFramebuffer(GL_FRAMEBUFFER, 0);
Expand Down Expand Up @@ -306,7 +303,7 @@ void ex_render_point_light_begin(ex_point_light_t *light, GLuint shader)
glUniform3fv(ex_uniform(shader, "u_light_pos"), 1, light->position);
}

void ex_render_point_light_draw(ex_point_light_t *light, GLuint shader, const char *prefix)
void ex_render_point_light(ex_point_light_t *light, GLuint shader, const char *prefix)
{
if (light->is_shadow) {
glUniform1i(ex_uniform(shader, "u_point_light.is_shadow"), 1);
Expand Down Expand Up @@ -335,4 +332,14 @@ void ex_render_point_light_draw(ex_point_light_t *light, GLuint shader, const ch
glUniform3fv(ex_uniform(shader, "u_point_light.position"), 1, light->position);
glUniform3fv(ex_uniform(shader, "u_point_light.color"), 1, light->color);
}
}

void ex_render_resize(size_t width, size_t height)
{
framebuffer = ex_framebuffer_resize(framebuffer, width, height);
}

void ex_render_destroy()
{
ex_framebuffer_destroy(framebuffer);
}
24 changes: 20 additions & 4 deletions src/exengine/render/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ typedef struct {
} ex_renderlist_t;

typedef struct {
ex_renderlist_t *models;
ex_renderlist_t *point_lights;
ex_renderlist_t models;
ex_renderlist_t point_lights;
ex_camera_matrices_t *camera;
} ex_renderable_t;

Expand All @@ -53,7 +53,19 @@ static inline ex_rendernode_t *ex_rendernode_push(ex_renderlist_t *list) {
return node;
}

static inline void ex_rendernode_pop(ex_renderlist_t *list, ex_rendernode_t *node) {
static inline void ex_rendernode_pop(ex_renderlist_t *list, void *obj) {
ex_rendernode_t *node = NULL;

for (int i=0; i<list->count; i++) {
if (list->nodes[i].obj == obj) {
node = &list->nodes[i];
break;
}
}

if (!node)
return;

// node is somewhere middle of list, pop from list
if (node->index < list->count) {
size_t index = node->index;
Expand Down Expand Up @@ -84,6 +96,10 @@ void ex_render_mesh(ex_mesh_t *mesh, GLuint shader, size_t count);

void ex_render_point_light_begin(ex_point_light_t *light, GLuint shader);

void ex_render_point_light_draw(ex_point_light_t *light, GLuint shader, const char *prefix);
void ex_render_point_light(ex_point_light_t *light, GLuint shader, const char *prefix);

void ex_render_resize(size_t width, size_t height);

void ex_render_destroy();

#endif // EX_RENDERER_H
Loading

0 comments on commit c28d1a8

Please sign in to comment.