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

View File

@ -17043,6 +17043,11 @@ typedef struct renderstate_t {
bool depth_test_enabled;
bool depth_write_enabled;
unsigned depth_func;
// Polygon offset
bool polygon_offset_enabled;
float polygon_offset;
float polygon_offset_factor;
// Blending
bool blend_enabled;
@ -17057,8 +17062,10 @@ typedef struct renderstate_t {
// Stencil test
bool stencil_test_enabled;
unsigned stencil_func;
unsigned stencil_op_fail, stencil_op_zfail, stencil_op_zpass;
int stencil_ref;
unsigned stencil_mask;
unsigned stencil_read_mask;
unsigned stencil_write_mask;
// Face culling direction
unsigned front_face; // GL_CW or GL_CCW
@ -17608,7 +17615,6 @@ enum MODEL_FLAGS {
MODEL_MATCAPS = 16,
MODEL_RIMLIGHT = 32,
MODEL_PBR = 64,
MODEL_CULLFACE = 128,
};
enum SHADING_MODE {
@ -382703,6 +382709,11 @@ renderstate_t renderstate() {
state.depth_test_enabled = GL_TRUE;
state.depth_write_enabled = GL_TRUE;
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
state.blend_enabled = GL_FALSE;
@ -382717,8 +382728,12 @@ renderstate_t renderstate() {
// Disable stencil test by default
state.stencil_test_enabled = GL_FALSE;
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_mask = 0xFFFFFFFF;
state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise
state.front_face = GL_CCW;
@ -382771,6 +382786,14 @@ void renderstate_apply(const renderstate_t *state) {
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
glDepthMask(state->depth_write_enabled);
@ -382794,7 +382817,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test
if (state->stencil_test_enabled) {
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 {
glDisable(GL_STENCIL_TEST);
}
@ -386767,7 +386792,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs);

View File

@ -69,6 +69,11 @@ renderstate_t renderstate() {
state.depth_test_enabled = GL_TRUE;
state.depth_write_enabled = GL_TRUE;
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
state.blend_enabled = GL_FALSE;
@ -83,8 +88,12 @@ renderstate_t renderstate() {
// Disable stencil test by default
state.stencil_test_enabled = GL_FALSE;
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_mask = 0xFFFFFFFF;
state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise
state.front_face = GL_CCW;
@ -137,6 +146,14 @@ void renderstate_apply(const renderstate_t *state) {
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
glDepthMask(state->depth_write_enabled);
@ -160,7 +177,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test
if (state->stencil_test_enabled) {
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 {
glDisable(GL_STENCIL_TEST);
}
@ -4133,7 +4152,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs);

View File

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

View File

@ -17242,6 +17242,11 @@ renderstate_t renderstate() {
state.depth_test_enabled = GL_TRUE;
state.depth_write_enabled = GL_TRUE;
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
state.blend_enabled = GL_FALSE;
@ -17256,8 +17261,12 @@ renderstate_t renderstate() {
// Disable stencil test by default
state.stencil_test_enabled = GL_FALSE;
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_mask = 0xFFFFFFFF;
state.stencil_read_mask = 0xFFFFFFFF;
state.stencil_write_mask = 0xFFFFFFFF;
// Set default front face to counter-clockwise
state.front_face = GL_CCW;
@ -17310,6 +17319,14 @@ void renderstate_apply(const renderstate_t *state) {
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
glDepthMask(state->depth_write_enabled);
@ -17333,7 +17350,9 @@ void renderstate_apply(const renderstate_t *state) {
// Apply stencil test
if (state->stencil_test_enabled) {
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 {
glDisable(GL_STENCIL_TEST);
}
@ -21306,7 +21325,6 @@ void model_draw_call(model_t m, int shader) {
shader_bind(shader);
renderstate_t *rs = &m.rs[RENDER_PASS_NORMAL];
rs->cull_face_enabled = m.flags&MODEL_CULLFACE;
renderstate_apply(rs);

View File

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