Skip to content

Commit

Permalink
fix bug when clearing the depth buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Jun 4, 2017
1 parent 3cc36cb commit e5aaa21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/am_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,12 @@ void am_draw_elements(am_draw_mode mode, int count, am_element_index_type type,
am_frame_draw_calls++;
}

void am_gl_flush() {
check_initialized();
GLFUNC(glFlush)();
check_for_errors
}

static GLenum to_gl_blend_equation(am_blend_equation eq) {
switch (eq) {
case AM_BLEND_EQUATION_ADD: return GL_FUNC_ADD;
Expand Down
3 changes: 3 additions & 0 deletions src/am_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ enum am_element_index_type {
void am_draw_arrays(am_draw_mode mode, int first, int count);
void am_draw_elements(am_draw_mode mode, int count, am_element_index_type type, int offset);

// Other

void am_gl_flush();
void am_log_gl(const char *msg);
void am_close_gllog();
void am_reset_gl_frame_stats();
20 changes: 14 additions & 6 deletions src/am_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ static void setup(am_render_state *rstate, am_framebuffer_id fb,
rstate->active_color_mask_state.set(true, true, true, true);
am_set_framebuffer_color_mask(true, true, true, true);

rstate->active_depth_test_state.set(has_depthbuffer, has_depthbuffer,
has_depthbuffer ? AM_DEPTH_FUNC_LESS : AM_DEPTH_FUNC_ALWAYS);
rstate->bound_depth_test_state.set(has_depthbuffer, has_depthbuffer,
has_depthbuffer ? AM_DEPTH_FUNC_LESS : AM_DEPTH_FUNC_ALWAYS);
am_set_framebuffer_depth_mask(has_depthbuffer);
am_set_depth_test_enabled(has_depthbuffer);
am_set_depth_func(has_depthbuffer ? AM_DEPTH_FUNC_LESS : AM_DEPTH_FUNC_ALWAYS);

bool is_margin = !(x == 0 && y == 0 && w == fbw && h == fbh);

if (clear && is_margin) {
Expand All @@ -434,11 +442,6 @@ static void setup(am_render_state *rstate, am_framebuffer_id fb,
rstate->active_scissor_test_state.set(scissor_enabled, x, y, w, h);
rstate->bound_scissor_test_state.set(scissor_enabled, x, y, w, h);

rstate->active_depth_test_state.set(has_depthbuffer, has_depthbuffer,
has_depthbuffer ? AM_DEPTH_FUNC_LESS : AM_DEPTH_FUNC_ALWAYS);
am_set_framebuffer_depth_mask(has_depthbuffer);
rstate->bound_depth_test_state.mask_enabled = has_depthbuffer;

if (clear && (!is_margin ||
clear_color.r != 0.0 || clear_color.g != 0.0 ||
clear_color.b != 0.0 || clear_color.a != 1.0))
Expand Down Expand Up @@ -479,6 +482,7 @@ static bool check_pass(am_render_state *rstate) {
}

void am_render_state::draw_arrays(am_draw_mode mode, int first, int draw_array_count) {
if (draw_array_count == 0) return;
if (!check_pass(this)) { return; }
if (active_program == NULL) {
am_log1("%s", "WARNING: ignoring draw, "
Expand Down Expand Up @@ -506,13 +510,17 @@ void am_render_state::draw_arrays(am_draw_mode mode, int first, int draw_array_c
void am_render_state::draw_elements(am_draw_mode mode, int first, int count,
am_buffer_view *indices_view, am_element_index_type type)
{
if (count == 0) return;
if (!check_pass(this)) return;
if (active_program == NULL) {
am_log1("%s", "WARNING: ignoring draw, "
"because no shader program has been bound");
return;
}
update_state();
if (!update_state()) {
// warning would already have been emitted
return;
}
if (validate_active_program(mode)) {
if (indices_view->buffer->elembuf_id == 0) {
indices_view->buffer->create_elembuf();
Expand Down

0 comments on commit e5aaa21

Please sign in to comment.