Skip to content

Commit 49b393d

Browse files
committed
[add] high level depth format implementation.
1 parent ceaf345 commit 49b393d

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

crates/lambda-rs/examples/reflective_room.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use lambda::{
4949
ShaderKind,
5050
VirtualShader,
5151
},
52+
texture::DepthFormat,
5253
vertex::{
5354
ColorFormat,
5455
Vertex,
@@ -66,7 +67,6 @@ use lambda::{
6667
ApplicationRuntimeBuilder,
6768
},
6869
};
69-
use lambda_platform::wgpu::texture::DepthFormat;
7070

7171
// ------------------------------ SHADER SOURCE --------------------------------
7272

crates/lambda-rs/src/render/pipeline.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use super::{
4141
buffer::Buffer,
4242
render_pass::RenderPass,
4343
shader::Shader,
44+
texture,
4445
vertex::VertexAttribute,
4546
RenderContext,
4647
};
@@ -234,7 +235,7 @@ pub struct RenderPipelineBuilder {
234235
bind_group_layouts: Vec<bind::BindGroupLayout>,
235236
label: Option<String>,
236237
use_depth: bool,
237-
depth_format: Option<platform_texture::DepthFormat>,
238+
depth_format: Option<texture::DepthFormat>,
238239
sample_count: u32,
239240
depth_compare: Option<CompareFunction>,
240241
stencil: Option<platform_pipeline::StencilState>,
@@ -307,10 +308,7 @@ impl RenderPipelineBuilder {
307308
}
308309

309310
/// Enable depth with an explicit depth format.
310-
pub fn with_depth_format(
311-
mut self,
312-
format: platform_texture::DepthFormat,
313-
) -> Self {
311+
pub fn with_depth_format(mut self, format: texture::DepthFormat) -> Self {
314312
self.use_depth = true;
315313
self.depth_format = Some(format);
316314
return self;
@@ -457,23 +455,25 @@ impl RenderPipelineBuilder {
457455
}
458456

459457
if self.use_depth {
458+
// Engine-level depth format with default
460459
let mut dfmt = self
461460
.depth_format
462-
.unwrap_or(platform_texture::DepthFormat::Depth32Float);
461+
.unwrap_or(texture::DepthFormat::Depth32Float);
463462
// If stencil state is configured, ensure a stencil-capable depth format.
464463
if self.stencil.is_some()
465-
&& dfmt != platform_texture::DepthFormat::Depth24PlusStencil8
464+
&& dfmt != texture::DepthFormat::Depth24PlusStencil8
466465
{
467466
#[cfg(debug_assertions)]
468467
logging::error!(
469468
"Stencil configured but depth format {:?} lacks stencil; upgrading to Depth24PlusStencil8",
470469
dfmt
471470
);
472-
dfmt = platform_texture::DepthFormat::Depth24PlusStencil8;
471+
dfmt = texture::DepthFormat::Depth24PlusStencil8;
473472
}
474-
// Keep context depth format in sync for attachment creation.
475-
render_context.depth_format = dfmt;
476-
rp_builder = rp_builder.with_depth_stencil(dfmt);
473+
// Map to platform and keep context depth format in sync for attachment creation.
474+
let dfmt_platform = dfmt.to_platform();
475+
render_context.depth_format = dfmt_platform;
476+
rp_builder = rp_builder.with_depth_stencil(dfmt_platform);
477477
if let Some(compare) = self.depth_compare {
478478
rp_builder = rp_builder.with_depth_compare(compare.to_platform());
479479
}

crates/lambda-rs/src/render/texture.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ use lambda_platform::wgpu::texture as platform;
99

1010
use super::RenderContext;
1111

12+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13+
/// Engine-level depth texture formats.
14+
///
15+
/// Maps to platform depth formats without exposing `wgpu` in the public API.
16+
pub enum DepthFormat {
17+
Depth32Float,
18+
Depth24Plus,
19+
Depth24PlusStencil8,
20+
}
21+
22+
impl DepthFormat {
23+
pub(crate) fn to_platform(self) -> platform::DepthFormat {
24+
return match self {
25+
DepthFormat::Depth32Float => platform::DepthFormat::Depth32Float,
26+
DepthFormat::Depth24Plus => platform::DepthFormat::Depth24Plus,
27+
DepthFormat::Depth24PlusStencil8 => {
28+
platform::DepthFormat::Depth24PlusStencil8
29+
}
30+
};
31+
}
32+
}
33+
1234
#[derive(Debug, Clone, Copy)]
1335
/// Supported color texture formats for sampling.
1436
pub enum TextureFormat {

0 commit comments

Comments
 (0)