summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-06 16:15:00 +0200
committerHampusM <hampus@hampusmat.com>2026-08-06 16:15:00 +0200
commit6f683a66582dd543b957216b466c07dc64d5b9a7 (patch)
tree13a269bf3ead7f29900b7c39033cc71e25040253
parent26a5b10d84dcbb9f22acec30aa549e9992235e9e (diff)
feat(engine): add depth function to rendering::DrawProperties
-rw-r--r--engine/src/rendering.rs40
-rw-r--r--engine/src/rendering/backend/opengl.rs23
2 files changed, 60 insertions, 3 deletions
diff --git a/engine/src/rendering.rs b/engine/src/rendering.rs
index dc3cb76..3af1ab8 100644
--- a/engine/src/rendering.rs
+++ b/engine/src/rendering.rs
@@ -321,6 +321,37 @@ impl Default for ScissorBox
}
}
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
+pub enum DepthFunction
+{
+ /// Never passes.
+ Never,
+
+ /// Passes if the incoming depth value is less than the stored depth value.
+ #[default]
+ Less,
+
+ /// Passes if the incoming depth value is equal to the stored depth value.
+ Equal,
+
+ /// Passes if the incoming depth value is less than or equal to the stored depth
+ /// value.
+ LessOrEqual,
+
+ /// Passes if the incoming depth value is greater than the stored depth value.
+ Greater,
+
+ /// Passes if the incoming depth value is not equal to the stored depth value.
+ NotEqual,
+
+ /// Passes if the incoming depth value is greater than or equal to the stored depth
+ /// value.
+ GreaterOrEqual,
+
+ /// Always passes.
+ Always,
+}
+
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct DrawProperties
@@ -329,6 +360,7 @@ pub struct DrawProperties
pub blending_enabled: bool,
pub blending_config: BlendingConfig,
pub depth_test_enabled: bool,
+ pub depth_function: DepthFunction,
pub scissor_test_enabled: bool,
pub scissor_box: ScissorBox,
pub face_culling_enabled: bool,
@@ -343,6 +375,7 @@ impl Default for DrawProperties
blending_enabled: false,
blending_config: BlendingConfig::default(),
depth_test_enabled: true,
+ depth_function: DepthFunction::default(),
scissor_test_enabled: false,
scissor_box: ScissorBox::default(),
face_culling_enabled: false,
@@ -358,9 +391,10 @@ bitflags! {
const BLENDING_CONFIG = 1 << 1;
const BLENDING_ENABLED = 1 << 2;
const DEPTH_TEST_ENABLED = 1 << 3;
- const SCISSOR_TEST_ENABLED = 1 << 4;
- const SCISSOR_BOX = 1 << 5;
- const FACE_CULLING_ENABLED = 1 << 6;
+ const DEPTH_FUNCTION = 1 << 4;
+ const SCISSOR_TEST_ENABLED = 1 << 5;
+ const SCISSOR_BOX = 1 << 6;
+ const FACE_CULLING_ENABLED = 1 << 7;
}
}
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs
index dc636ef..49f857b 100644
--- a/engine/src/rendering/backend/opengl.rs
+++ b/engine/src/rendering/backend/opengl.rs
@@ -35,10 +35,12 @@ use opengl_bindings::misc::{
define_scissor_box as gl_define_scissor_box,
enable,
get_viewport as gl_get_viewport,
+ set_depth_function as gl_set_depth_function,
set_enabled,
set_viewport as gl_set_viewport,
BufferClearMask as GlBufferClearMask,
Capability,
+ DepthFunction as GlDepthFunction,
};
use opengl_bindings::shader::{
Error as GlShaderError,
@@ -108,6 +110,7 @@ use crate::rendering::{
BufferClearMask,
Command,
CommandQueue,
+ DepthFunction,
DrawMeshOptions,
DrawPropertiesUpdateFlags,
GraphicsProperties,
@@ -1033,6 +1036,26 @@ fn handle_commands(
}
if draw_props_update_flags
+ .contains(DrawPropertiesUpdateFlags::DEPTH_FUNCTION)
+ {
+ gl_set_depth_function(
+ gl_context,
+ match draw_props.depth_function {
+ DepthFunction::Never => GlDepthFunction::Never,
+ DepthFunction::Less => GlDepthFunction::Less,
+ DepthFunction::Equal => GlDepthFunction::Equal,
+ DepthFunction::LessOrEqual => GlDepthFunction::LessOrEqual,
+ DepthFunction::Greater => GlDepthFunction::Greater,
+ DepthFunction::NotEqual => GlDepthFunction::NotEqual,
+ DepthFunction::GreaterOrEqual => {
+ GlDepthFunction::GreaterOrEqual
+ }
+ DepthFunction::Always => GlDepthFunction::Always,
+ },
+ );
+ }
+
+ if draw_props_update_flags
.contains(DrawPropertiesUpdateFlags::SCISSOR_TEST_ENABLED)
{
set_enabled(