Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DepthStencil texture format #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions native/sapp-windows/src/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/graphics/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum TextureFormat {
RGBA8,
Depth,
Alpha,
DepthStencil,
}

/// Converts from TextureFormat to (internal_format, format, pixel_type)
Expand All @@ -67,6 +68,9 @@ impl From<TextureFormat> 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)
}
}
}
}
Expand All @@ -80,6 +84,7 @@ impl TextureFormat {
TextureFormat::RGBA8 => 4 * square,
TextureFormat::Depth => 2 * square,
TextureFormat::Alpha => 1 * square,
TextureFormat::DepthStencil => 4 * square,
}
}
}
Expand Down Expand Up @@ -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();

Expand Down