use crate::core::*;
pub struct DepthTargetMultisample<D: DepthTextureDataType> {
pub(crate) context: Context,
depth: DepthTexture2DMultisample,
_d: std::marker::PhantomData<D>,
}
impl<D: DepthTextureDataType> DepthTargetMultisample<D> {
pub fn new(context: &Context, width: u32, height: u32, number_of_samples: u32) -> Self {
#[cfg(debug_assertions)]
super::multisample_sanity_check(context, number_of_samples);
Self {
context: context.clone(),
depth: DepthTexture2DMultisample::new::<D>(context, width, height, number_of_samples),
_d: std::marker::PhantomData,
}
}
pub fn clear(&self, clear_state: ClearState) -> &Self {
self.clear_partially(self.scissor_box(), clear_state)
}
pub fn clear_partially(&self, scissor_box: ScissorBox, clear_state: ClearState) -> &Self {
self.as_render_target().clear_partially(
scissor_box,
ClearState {
depth: clear_state.depth,
..ClearState::none()
},
);
self
}
pub fn write<E: std::error::Error>(
&self,
render: impl FnOnce() -> Result<(), E>,
) -> Result<&Self, E> {
self.write_partially(self.scissor_box(), render)
}
pub fn write_partially<E: std::error::Error>(
&self,
scissor_box: ScissorBox,
render: impl FnOnce() -> Result<(), E>,
) -> Result<&Self, E> {
self.as_render_target()
.write_partially(scissor_box, render)?;
Ok(self)
}
pub fn width(&self) -> u32 {
self.depth.width()
}
pub fn height(&self) -> u32 {
self.depth.height()
}
pub fn number_of_samples(&self) -> u32 {
self.depth.number_of_samples()
}
fn as_render_target(&self) -> RenderTarget<'_> {
DepthTarget::new_texture_2d_multisample(&self.context, &self.depth).as_render_target()
}
pub fn resolve_to(&self, target: &DepthTarget<'_>) {
self.as_render_target().blit_to(&target.as_render_target());
}
pub fn resolve(&self) -> DepthTexture2D {
let depth_texture = DepthTexture2D::new::<D>(
&self.context,
self.width(),
self.height(),
Wrapping::ClampToEdge,
Wrapping::ClampToEdge,
);
self.resolve_to(&depth_texture.as_depth_target());
depth_texture
}
}