new: renderstate additions

main
Dominik Madarász 2024-04-18 09:57:28 +02:00
parent ba60e86882
commit 7df5ea4ca6
6 changed files with 93 additions and 17 deletions

View File

@ -1038,6 +1038,9 @@ typedef struct renderstate_t {
bool depth_test_enabled; bool depth_test_enabled;
bool depth_write_enabled; bool depth_write_enabled;
unsigned depth_func; unsigned depth_func;
bool polygon_offset_enabled;
float polygon_offset;
float polygon_offset_factor;
bool blend_enabled; bool blend_enabled;
unsigned blend_func; unsigned blend_func;
unsigned blend_src; unsigned blend_src;
@ -1046,8 +1049,10 @@ typedef struct renderstate_t {
unsigned cull_face_mode; unsigned cull_face_mode;
bool stencil_test_enabled; bool stencil_test_enabled;
unsigned stencil_func; unsigned stencil_func;
unsigned stencil_op_fail, stencil_op_zfail, stencil_op_zpass;
int stencil_ref; int stencil_ref;
unsigned stencil_mask; unsigned stencil_read_mask;
unsigned stencil_write_mask;
unsigned front_face; unsigned front_face;
bool line_smooth_enabled; bool line_smooth_enabled;
float line_width; float line_width;
@ -1356,7 +1361,6 @@ enum MODEL_FLAGS {
MODEL_MATCAPS = 16, MODEL_MATCAPS = 16,
MODEL_RIMLIGHT = 32, MODEL_RIMLIGHT = 32,
MODEL_PBR = 64, MODEL_PBR = 64,
MODEL_CULLFACE = 128,
}; };
enum SHADING_MODE { enum SHADING_MODE {
SHADING_NONE, SHADING_NONE,

View File

@ -17044,6 +17044,11 @@ typedef struct renderstate_t {
bool depth_write_enabled; bool depth_write_enabled;
unsigned depth_func; unsigned depth_func;
// Polygon offset
bool polygon_offset_enabled;
float polygon_offset;
float polygon_offset_factor;
// Blending // Blending
bool blend_enabled; bool blend_enabled;
unsigned blend_func; unsigned blend_func;
@ -17057,8 +17062,10 @@ typedef struct renderstate_t {
// Stencil test // Stencil test
bool stencil_test_enabled; bool stencil_test_enabled;
unsigned stencil_func; unsigned stencil_func;
unsigned stencil_op_fail, stencil_op_zfail, stencil_op_zpass;
int stencil_ref; int stencil_ref;
unsigned stencil_mask; unsigned stencil_read_mask;
unsigned stencil_write_mask;
// Face culling direction // Face culling direction
unsigned front_face; // GL_CW or GL_CCW unsigned front_face; // GL_CW or GL_CCW
@ -17608,7 +17615,6 @@ enum MODEL_FLAGS {
MODEL_MATCAPS = 16, MODEL_MATCAPS = 16,
MODEL_RIMLIGHT = 32, MODEL_RIMLIGHT = 32,
MODEL_PBR = 64, MODEL_PBR = 64,
MODEL_CULLFACE = 128,
}; };
enum SHADING_MODE { enum SHADING_MODE {
@ -382704,6 +382710,11 @@ renderstate_t renderstate() {
state.depth_write_enabled = GL_TRUE; state.depth_write_enabled = GL_TRUE;
state.depth_func = GL_LEQUAL; state.depth_func = GL_LEQUAL;
// Disable polygon offset by default
state.polygon_offset_enabled = GL_FALSE;
state.polygon_offset_factor = 0.0f;
state.polygon_offset = 0.0f;
// Disable blending by default // Disable blending by default
state.blend_enabled = GL_FALSE; state.blend_enabled = GL_FALSE;
state.blend_func = GL_FUNC_ADD; state.blend_func = GL_FUNC_ADD;
@ -382717,8 +382728,12 @@ renderstate_t renderstate() {
// Disable stencil test by default // Disable stencil test by default
state.stencil_test_enabled = GL_FALSE; state.stencil_test_enabled = GL_FALSE;
state.stencil_func = GL_ALWAYS; state.stencil_func = GL_ALWAYS;
state.stencil_op_fail = GL_KEEP;
state.stencil_op_zfail = GL_KEEP;
state.stencil_op_zpass = GL_KEEP;
state.stencil_ref = 0; state.stencil_ref = 0;
state.stencil_mask = 0xFFFFFFFF; state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise // Set default front face to counter-clockwise
state.front_face = GL_CCW; state.front_face = GL_CCW;
@ -382771,6 +382786,14 @@ void renderstate_apply(const renderstate_t *state) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
// Apply polygon offset
if (state->polygon_offset_enabled) {
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(state->polygon_offset_factor, state->polygon_offset);
} else {
glDisable(GL_POLYGON_OFFSET_FILL);
}
// Apply depth write // Apply depth write
glDepthMask(state->depth_write_enabled); glDepthMask(state->depth_write_enabled);
@ -382794,7 +382817,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test // Apply stencil test
if (state->stencil_test_enabled) { if (state->stencil_test_enabled) {
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_mask); glStencilMask(state->stencil_write_mask);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_read_mask);
glStencilOp(state->stencil_op_fail, state->stencil_op_zfail, state->stencil_op_zpass);
} else { } else {
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
} }
@ -386767,7 +386792,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader); shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL]; renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs); renderstate_apply(rs);

View File

@ -70,6 +70,11 @@ renderstate_t renderstate() {
state.depth_write_enabled = GL_TRUE; state.depth_write_enabled = GL_TRUE;
state.depth_func = GL_LEQUAL; state.depth_func = GL_LEQUAL;
// Disable polygon offset by default
state.polygon_offset_enabled = GL_FALSE;
state.polygon_offset_factor = 0.0f;
state.polygon_offset = 0.0f;
// Disable blending by default // Disable blending by default
state.blend_enabled = GL_FALSE; state.blend_enabled = GL_FALSE;
state.blend_func = GL_FUNC_ADD; state.blend_func = GL_FUNC_ADD;
@ -83,8 +88,12 @@ renderstate_t renderstate() {
// Disable stencil test by default // Disable stencil test by default
state.stencil_test_enabled = GL_FALSE; state.stencil_test_enabled = GL_FALSE;
state.stencil_func = GL_ALWAYS; state.stencil_func = GL_ALWAYS;
state.stencil_op_fail = GL_KEEP;
state.stencil_op_zfail = GL_KEEP;
state.stencil_op_zpass = GL_KEEP;
state.stencil_ref = 0; state.stencil_ref = 0;
state.stencil_mask = 0xFFFFFFFF; state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise // Set default front face to counter-clockwise
state.front_face = GL_CCW; state.front_face = GL_CCW;
@ -137,6 +146,14 @@ void renderstate_apply(const renderstate_t *state) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
// Apply polygon offset
if (state->polygon_offset_enabled) {
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(state->polygon_offset_factor, state->polygon_offset);
} else {
glDisable(GL_POLYGON_OFFSET_FILL);
}
// Apply depth write // Apply depth write
glDepthMask(state->depth_write_enabled); glDepthMask(state->depth_write_enabled);
@ -160,7 +177,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test // Apply stencil test
if (state->stencil_test_enabled) { if (state->stencil_test_enabled) {
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_mask); glStencilMask(state->stencil_write_mask);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_read_mask);
glStencilOp(state->stencil_op_fail, state->stencil_op_zfail, state->stencil_op_zpass);
} else { } else {
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
} }
@ -4133,7 +4152,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader); shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL]; renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs); renderstate_apply(rs);

View File

@ -22,6 +22,11 @@ typedef struct renderstate_t {
bool depth_write_enabled; bool depth_write_enabled;
unsigned depth_func; unsigned depth_func;
// Polygon offset
bool polygon_offset_enabled;
float polygon_offset;
float polygon_offset_factor;
// Blending // Blending
bool blend_enabled; bool blend_enabled;
unsigned blend_func; unsigned blend_func;
@ -35,8 +40,10 @@ typedef struct renderstate_t {
// Stencil test // Stencil test
bool stencil_test_enabled; bool stencil_test_enabled;
unsigned stencil_func; unsigned stencil_func;
unsigned stencil_op_fail, stencil_op_zfail, stencil_op_zpass;
int stencil_ref; int stencil_ref;
unsigned stencil_mask; unsigned stencil_read_mask;
unsigned stencil_write_mask;
// Face culling direction // Face culling direction
unsigned front_face; // GL_CW or GL_CCW unsigned front_face; // GL_CW or GL_CCW
@ -586,7 +593,6 @@ enum MODEL_FLAGS {
MODEL_MATCAPS = 16, MODEL_MATCAPS = 16,
MODEL_RIMLIGHT = 32, MODEL_RIMLIGHT = 32,
MODEL_PBR = 64, MODEL_PBR = 64,
MODEL_CULLFACE = 128,
}; };
enum SHADING_MODE { enum SHADING_MODE {

View File

@ -17243,6 +17243,11 @@ renderstate_t renderstate() {
state.depth_write_enabled = GL_TRUE; state.depth_write_enabled = GL_TRUE;
state.depth_func = GL_LEQUAL; state.depth_func = GL_LEQUAL;
// Disable polygon offset by default
state.polygon_offset_enabled = GL_FALSE;
state.polygon_offset_factor = 0.0f;
state.polygon_offset = 0.0f;
// Disable blending by default // Disable blending by default
state.blend_enabled = GL_FALSE; state.blend_enabled = GL_FALSE;
state.blend_func = GL_FUNC_ADD; state.blend_func = GL_FUNC_ADD;
@ -17256,8 +17261,12 @@ renderstate_t renderstate() {
// Disable stencil test by default // Disable stencil test by default
state.stencil_test_enabled = GL_FALSE; state.stencil_test_enabled = GL_FALSE;
state.stencil_func = GL_ALWAYS; state.stencil_func = GL_ALWAYS;
state.stencil_op_fail = GL_KEEP;
state.stencil_op_zfail = GL_KEEP;
state.stencil_op_zpass = GL_KEEP;
state.stencil_ref = 0; state.stencil_ref = 0;
state.stencil_mask = 0xFFFFFFFF; state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise // Set default front face to counter-clockwise
state.front_face = GL_CCW; state.front_face = GL_CCW;
@ -17310,6 +17319,14 @@ void renderstate_apply(const renderstate_t *state) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
// Apply polygon offset
if (state->polygon_offset_enabled) {
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(state->polygon_offset_factor, state->polygon_offset);
} else {
glDisable(GL_POLYGON_OFFSET_FILL);
}
// Apply depth write // Apply depth write
glDepthMask(state->depth_write_enabled); glDepthMask(state->depth_write_enabled);
@ -17333,7 +17350,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test // Apply stencil test
if (state->stencil_test_enabled) { if (state->stencil_test_enabled) {
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_mask); glStencilMask(state->stencil_write_mask);
glStencilFunc(state->stencil_func, state->stencil_ref, state->stencil_read_mask);
glStencilOp(state->stencil_op_fail, state->stencil_op_zfail, state->stencil_op_zpass);
} else { } else {
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
} }
@ -21306,7 +21325,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader); shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL]; renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs); renderstate_apply(rs);

View File

@ -3111,6 +3111,11 @@ typedef struct renderstate_t {
bool depth_write_enabled; bool depth_write_enabled;
unsigned depth_func; unsigned depth_func;
// Polygon offset
bool polygon_offset_enabled;
float polygon_offset;
float polygon_offset_factor;
// Blending // Blending
bool blend_enabled; bool blend_enabled;
unsigned blend_func; unsigned blend_func;
@ -3124,8 +3129,10 @@ typedef struct renderstate_t {
// Stencil test // Stencil test
bool stencil_test_enabled; bool stencil_test_enabled;
unsigned stencil_func; unsigned stencil_func;
unsigned stencil_op_fail, stencil_op_zfail, stencil_op_zpass;
int stencil_ref; int stencil_ref;
unsigned stencil_mask; unsigned stencil_read_mask;
unsigned stencil_write_mask;
// Face culling direction // Face culling direction
unsigned front_face; // GL_CW or GL_CCW unsigned front_face; // GL_CW or GL_CCW
@ -3675,7 +3682,6 @@ enum MODEL_FLAGS {
MODEL_MATCAPS = 16, MODEL_MATCAPS = 16,
MODEL_RIMLIGHT = 32, MODEL_RIMLIGHT = 32,
MODEL_PBR = 64, MODEL_PBR = 64,
MODEL_CULLFACE = 128,
}; };
enum SHADING_MODE { enum SHADING_MODE {