gfx: figure out face culling defaults

main
Dominik Madarász 2024-04-11 09:43:10 +02:00
parent 50cc35db90
commit 2277b42619
3 changed files with 78 additions and 27 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;