From e669b499ef06ff0ace25ad0c06e6b8a8ac6dacce Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Mon, 23 Aug 2021 19:20:01 +0200 Subject: [PATCH] Add support for DepthStencil texture format --- native/sapp-windows/src/gl.rs | 3 +++ src/graphics.rs | 5 ++++- src/graphics/texture.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/native/sapp-windows/src/gl.rs b/native/sapp-windows/src/gl.rs index 9bdcb63b..937d4f93 100644 --- a/native/sapp-windows/src/gl.rs +++ b/native/sapp-windows/src/gl.rs @@ -89,6 +89,8 @@ pub const GL_FRAGMENT_SHADER: u32 = 0x8B30; pub const GL_FLOAT: u32 = 0x1406; pub const GL_TEXTURE_MAX_LOD: u32 = 0x813B; pub const GL_DEPTH_COMPONENT: u32 = 0x1902; +pub const GL_DEPTH_STENCIL: u32 = 0x84F9; +pub const GL_DEPTH24_STENCIL8: u32 = 0x88F0; pub const GL_ONE_MINUS_DST_ALPHA: u32 = 0x0305; pub const GL_COLOR: u32 = 0x1800; pub const GL_TEXTURE_2D_ARRAY: u32 = 0x8C1A; @@ -130,6 +132,7 @@ pub const GL_INVERT: u32 = 0x150A; pub const GL_INT: u32 = 0x1404; pub const GL_UNSIGNED_INT: u32 = 0x1405; pub const GL_UNSIGNED_SHORT: u32 = 0x1403; +pub const GL_UNSIGNED_INT_24_8: u32 = 0x84FA; pub const GL_NEAREST: u32 = 0x2600; pub const GL_SCISSOR_TEST: u32 = 0x0C11; pub const GL_LEQUAL: u32 = 0x0203; diff --git a/src/graphics.rs b/src/graphics.rs index 60464f9c..28d08f74 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -584,7 +584,10 @@ impl RenderPass { if let Some(depth_img) = depth_img { glFramebufferTexture2D( GL_FRAMEBUFFER, - GL_DEPTH_ATTACHMENT, + match depth_img.format { + TextureFormat::DepthStencil => GL_DEPTH_ATTACHMENT | GL_STENCIL_ATTACHMENT, + _ => GL_DEPTH_ATTACHMENT, + }, GL_TEXTURE_2D, depth_img.texture, 0, diff --git a/src/graphics/texture.rs b/src/graphics/texture.rs index 1bcc5c46..7fa71837 100644 --- a/src/graphics/texture.rs +++ b/src/graphics/texture.rs @@ -54,6 +54,7 @@ pub enum TextureFormat { RGBA8, Depth, Alpha, + DepthStencil, } /// Converts from TextureFormat to (internal_format, format, pixel_type) @@ -67,6 +68,9 @@ impl From for (GLenum, GLenum, GLenum) { TextureFormat::Alpha => (GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE), #[cfg(not(target_arch = "wasm32"))] TextureFormat::Alpha => (GL_R8, GL_RED, GL_UNSIGNED_BYTE), // texture updates will swizzle Red -> Alpha to match WASM + TextureFormat::DepthStencil => { + (GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8) + } } } } @@ -80,6 +84,7 @@ impl TextureFormat { TextureFormat::RGBA8 => 4 * square, TextureFormat::Depth => 2 * square, TextureFormat::Alpha => 1 * square, + TextureFormat::DepthStencil => 4 * square, } } } @@ -148,6 +153,9 @@ impl Texture { bytes_data.len() ); } + if params.format == TextureFormat::DepthStencil { + assert_eq!(params.filter, FilterMode::Nearest); + } let (internal_format, format, pixel_type) = params.format.into();