From 2277b42619663d0b359428839ff0469cb5dbc629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 11 Apr 2024 09:43:10 +0200 Subject: [PATCH] gfx: figure out face culling defaults --- engine/joint/v4k.h | 35 ++++++++++++++++++++++++++--------- engine/split/v4k_render.c | 35 ++++++++++++++++++++++++++--------- engine/v4k.c | 35 ++++++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 27 deletions(-) diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 6132339..d301ec7 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -370140,8 +370140,8 @@ renderstate_t renderstate() { state.blend_src = GL_ONE; state.blend_dst = GL_ZERO; - // Enable culling by default and cull back faces - state.cull_face_enabled = GL_TRUE; + // Disable culling by default but cull back faces + state.cull_face_enabled = GL_FALSE; state.cull_face_mode = GL_BACK; // Disable stencil test by default @@ -370175,8 +370175,18 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state return memcmp(stateA, stateB, sizeof(renderstate_t)) == 0; } +static renderstate_t last_rs; + void renderstate_apply(const renderstate_t *state) { if (state != NULL) { + // Compare renderstates and bail if they are the same + if (renderstate_compare(state, &last_rs)) { + return; + } + + // Store renderstate + last_rs = *state; + // Apply clear color glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]); @@ -370201,12 +370211,12 @@ void renderstate_apply(const renderstate_t *state) { } // Apply culling @fixme - // if (state->cull_face_enabled) { - // glEnable(GL_CULL_FACE); - // glCullFace(state->cull_face_mode); - // } else { - // glDisable(GL_CULL_FACE); - // } + if (state->cull_face_enabled) { + glEnable(GL_CULL_FACE); + glCullFace(state->cull_face_mode); + } else { + glDisable(GL_CULL_FACE); + } // Apply stencil test if (state->stencil_test_enabled) { @@ -370217,7 +370227,7 @@ void renderstate_apply(const renderstate_t *state) { } // Apply front face direction @fixme - // glFrontFace(state->front_face); + glFrontFace(state->front_face); // Apply line width glLineWidth(state->line_width); @@ -372060,6 +372070,9 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) { do_once { skybox_rs = renderstate(); + skybox_rs.depth_test_enabled = 0; + skybox_rs.cull_face_enabled = 0; + skybox_rs.front_face = GL_CW; } // we have to reset clear color here, because of wrong alpha compositing issues on native transparent windows otherwise @@ -373753,6 +373766,10 @@ model_t model_from_mem(const void *mem, int len, int flags) { { m.rs = renderstate(); m.rs.blend_enabled = 1; + m.rs.blend_src = GL_SRC_ALPHA; + m.rs.blend_dst = GL_ONE_MINUS_SRC_ALPHA; + m.rs.cull_face_mode = GL_BACK; + m.rs.front_face = GL_CW; } m.stored_flags = flags; diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index 1d84773..664123a 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -75,8 +75,8 @@ renderstate_t renderstate() { state.blend_src = GL_ONE; state.blend_dst = GL_ZERO; - // Enable culling by default and cull back faces - state.cull_face_enabled = GL_TRUE; + // Disable culling by default but cull back faces + state.cull_face_enabled = GL_FALSE; state.cull_face_mode = GL_BACK; // Disable stencil test by default @@ -110,8 +110,18 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state return memcmp(stateA, stateB, sizeof(renderstate_t)) == 0; } +static renderstate_t last_rs; + void renderstate_apply(const renderstate_t *state) { if (state != NULL) { + // Compare renderstates and bail if they are the same + if (renderstate_compare(state, &last_rs)) { + return; + } + + // Store renderstate + last_rs = *state; + // Apply clear color glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]); @@ -136,12 +146,12 @@ void renderstate_apply(const renderstate_t *state) { } // Apply culling @fixme - // if (state->cull_face_enabled) { - // glEnable(GL_CULL_FACE); - // glCullFace(state->cull_face_mode); - // } else { - // glDisable(GL_CULL_FACE); - // } + if (state->cull_face_enabled) { + glEnable(GL_CULL_FACE); + glCullFace(state->cull_face_mode); + } else { + glDisable(GL_CULL_FACE); + } // Apply stencil test if (state->stencil_test_enabled) { @@ -152,7 +162,7 @@ void renderstate_apply(const renderstate_t *state) { } // Apply front face direction @fixme - // glFrontFace(state->front_face); + glFrontFace(state->front_face); // Apply line width glLineWidth(state->line_width); @@ -1995,6 +2005,9 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) { do_once { skybox_rs = renderstate(); + skybox_rs.depth_test_enabled = 0; + skybox_rs.cull_face_enabled = 0; + skybox_rs.front_face = GL_CW; } // we have to reset clear color here, because of wrong alpha compositing issues on native transparent windows otherwise @@ -3688,6 +3701,10 @@ model_t model_from_mem(const void *mem, int len, int flags) { { m.rs = renderstate(); m.rs.blend_enabled = 1; + m.rs.blend_src = GL_SRC_ALPHA; + m.rs.blend_dst = GL_ONE_MINUS_SRC_ALPHA; + m.rs.cull_face_mode = GL_BACK; + m.rs.front_face = GL_CW; } m.stored_flags = flags; diff --git a/engine/v4k.c b/engine/v4k.c index 12a6394..44239f1 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -17239,8 +17239,8 @@ renderstate_t renderstate() { state.blend_src = GL_ONE; state.blend_dst = GL_ZERO; - // Enable culling by default and cull back faces - state.cull_face_enabled = GL_TRUE; + // Disable culling by default but cull back faces + state.cull_face_enabled = GL_FALSE; state.cull_face_mode = GL_BACK; // Disable stencil test by default @@ -17274,8 +17274,18 @@ bool renderstate_compare(const renderstate_t *stateA, const renderstate_t *state return memcmp(stateA, stateB, sizeof(renderstate_t)) == 0; } +static renderstate_t last_rs; + void renderstate_apply(const renderstate_t *state) { if (state != NULL) { + // Compare renderstates and bail if they are the same + if (renderstate_compare(state, &last_rs)) { + return; + } + + // Store renderstate + last_rs = *state; + // Apply clear color glClearColor(state->clear_color[0], state->clear_color[1], state->clear_color[2], state->clear_color[3]); @@ -17300,12 +17310,12 @@ void renderstate_apply(const renderstate_t *state) { } // Apply culling @fixme - // if (state->cull_face_enabled) { - // glEnable(GL_CULL_FACE); - // glCullFace(state->cull_face_mode); - // } else { - // glDisable(GL_CULL_FACE); - // } + if (state->cull_face_enabled) { + glEnable(GL_CULL_FACE); + glCullFace(state->cull_face_mode); + } else { + glDisable(GL_CULL_FACE); + } // Apply stencil test if (state->stencil_test_enabled) { @@ -17316,7 +17326,7 @@ void renderstate_apply(const renderstate_t *state) { } // Apply front face direction @fixme - // glFrontFace(state->front_face); + glFrontFace(state->front_face); // Apply line width glLineWidth(state->line_width); @@ -19159,6 +19169,9 @@ int skybox_push_state(skybox_t *sky, mat44 proj, mat44 view) { do_once { skybox_rs = renderstate(); + skybox_rs.depth_test_enabled = 0; + skybox_rs.cull_face_enabled = 0; + skybox_rs.front_face = GL_CW; } // we have to reset clear color here, because of wrong alpha compositing issues on native transparent windows otherwise @@ -20852,6 +20865,10 @@ model_t model_from_mem(const void *mem, int len, int flags) { { m.rs = renderstate(); m.rs.blend_enabled = 1; + m.rs.blend_src = GL_SRC_ALPHA; + m.rs.blend_dst = GL_ONE_MINUS_SRC_ALPHA; + m.rs.cull_face_mode = GL_BACK; + m.rs.front_face = GL_CW; } m.stored_flags = flags;