From 47798568f3f05b8267ae3700369a4a396073ef97 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 25 Oct 2023 20:31:56 +0200 Subject: feat(engine): enable depth testing --- engine/src/opengl/mod.rs | 14 ++++++++++++++ engine/src/renderer/mod.rs | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'engine') diff --git a/engine/src/opengl/mod.rs b/engine/src/opengl/mod.rs index 6f95a1f..4f4f96f 100644 --- a/engine/src/opengl/mod.rs +++ b/engine/src/opengl/mod.rs @@ -33,6 +33,13 @@ pub fn clear_buffers(mask: BufferClearMask) } } +pub fn enable(capacity: Capability) +{ + unsafe { + gl::Enable(capacity as u32); + } +} + bitflags! { #[derive(Debug, Clone, Copy)] pub struct BufferClearMask: u32 { @@ -41,3 +48,10 @@ bitflags! { const STENCIL = gl::STENCIL_BUFFER_BIT; } } + +#[derive(Debug)] +#[repr(u32)] +pub enum Capability +{ + DepthTest = gl::DEPTH_TEST, +} diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index aa828fe..4dcc075 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -16,7 +16,7 @@ use crate::opengl::buffer::{ use crate::opengl::debug::{MessageSeverity, MessageSource, MessageType}; use crate::opengl::shader::Program as ShaderProgram; use crate::opengl::vertex_array::{PrimitiveKind, VertexArray}; -use crate::opengl::{clear_buffers, BufferClearMask}; +use crate::opengl::{clear_buffers, enable, BufferClearMask, Capability}; use crate::projection::new_perspective; use crate::vector::Vec2; use crate::vertex::Vertex; @@ -59,6 +59,8 @@ pub fn initialize(window: &glfw::Window) -> Result<(), Error> set_viewport(&Vec2 { x: 0, y: 0 }, &window_size); + enable(Capability::DepthTest); + Ok(()) } @@ -107,7 +109,7 @@ pub fn render<'obj>( camera: &Camera, ) { - clear_buffers(BufferClearMask::COLOR); + clear_buffers(BufferClearMask::COLOR | BufferClearMask::DEPTH); for obj in objects { obj.renderable().shader_program.activate(); -- cgit v1.2.3-18-g5258