three_d/core/render_target/
depth_target_multisample.rs1use crate::core::*;
2
3pub struct DepthTargetMultisample<D: DepthTextureDataType> {
12 pub(crate) context: Context,
13 depth: DepthTexture2DMultisample,
14 _d: std::marker::PhantomData<D>,
15}
16
17impl<D: DepthTextureDataType> DepthTargetMultisample<D> {
18 pub fn new(context: &Context, width: u32, height: u32, number_of_samples: u32) -> Self {
23 #[cfg(debug_assertions)]
24 super::multisample_sanity_check(context, number_of_samples);
25 Self {
26 context: context.clone(),
27 depth: DepthTexture2DMultisample::new::<D>(context, width, height, number_of_samples),
28 _d: std::marker::PhantomData,
29 }
30 }
31
32 pub fn clear(&self, clear_state: ClearState) -> &Self {
36 self.clear_partially(self.scissor_box(), clear_state)
37 }
38
39 pub fn clear_partially(&self, scissor_box: ScissorBox, clear_state: ClearState) -> &Self {
43 self.as_render_target().clear_partially(
44 scissor_box,
45 ClearState {
46 depth: clear_state.depth,
47 ..ClearState::none()
48 },
49 );
50 self
51 }
52
53 pub fn write<E: std::error::Error>(
57 &self,
58 render: impl FnOnce() -> Result<(), E>,
59 ) -> Result<&Self, E> {
60 self.write_partially(self.scissor_box(), render)
61 }
62
63 pub fn write_partially<E: std::error::Error>(
67 &self,
68 scissor_box: ScissorBox,
69 render: impl FnOnce() -> Result<(), E>,
70 ) -> Result<&Self, E> {
71 self.as_render_target()
72 .write_partially(scissor_box, render)?;
73 Ok(self)
74 }
75
76 pub fn width(&self) -> u32 {
78 self.depth.width()
79 }
80
81 pub fn height(&self) -> u32 {
83 self.depth.height()
84 }
85
86 pub fn number_of_samples(&self) -> u32 {
88 self.depth.number_of_samples()
89 }
90
91 fn as_render_target(&self) -> RenderTarget<'_> {
92 DepthTarget::new_texture_2d_multisample(&self.context, &self.depth).as_render_target()
93 }
94
95 pub fn resolve_to(&self, target: &DepthTarget<'_>) {
100 self.as_render_target().blit_to(&target.as_render_target());
101 }
102
103 pub fn resolve(&self) -> DepthTexture2D {
108 let mut depth_texture = DepthTexture2D::new::<D>(
109 &self.context,
110 self.width(),
111 self.height(),
112 Wrapping::ClampToEdge,
113 Wrapping::ClampToEdge,
114 );
115 self.resolve_to(&depth_texture.as_depth_target());
116 depth_texture
117 }
118}