2022-11-30 17:38:05 +11:00
|
|
|
use crate::framebuffer::OutputFramebuffer;
|
2022-12-01 11:05:12 +11:00
|
|
|
use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT;
|
2023-01-13 18:54:16 +11:00
|
|
|
use librashader_common::Viewport;
|
|
|
|
use crate::D3D11OutputView;
|
2022-11-27 18:21:36 +11:00
|
|
|
|
|
|
|
#[rustfmt::skip]
|
2022-11-29 16:23:48 +11:00
|
|
|
static DEFAULT_MVP: &[f32; 16] = &[
|
2022-11-27 18:21:36 +11:00
|
|
|
2f32, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 2.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 2.0, 0.0,
|
|
|
|
-1.0, -1.0, 0.0, 1.0,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2022-12-01 11:05:12 +11:00
|
|
|
pub(crate) struct RenderTarget<'a> {
|
2022-11-29 16:23:48 +11:00
|
|
|
pub mvp: &'a [f32; 16],
|
2022-11-30 17:38:05 +11:00
|
|
|
pub output: OutputFramebuffer,
|
2022-11-27 18:21:36 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> RenderTarget<'a> {
|
2022-11-29 16:23:48 +11:00
|
|
|
pub fn new(backbuffer: OutputFramebuffer, mvp: Option<&'a [f32; 16]>) -> Self {
|
2022-11-27 18:21:36 +11:00
|
|
|
if let Some(mvp) = mvp {
|
|
|
|
RenderTarget {
|
|
|
|
output: backbuffer,
|
|
|
|
mvp,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RenderTarget {
|
|
|
|
output: backbuffer,
|
|
|
|
mvp: DEFAULT_MVP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 11:05:12 +11:00
|
|
|
|
2023-01-13 18:54:16 +11:00
|
|
|
impl<'a> From<&Viewport<'a, D3D11OutputView>> for RenderTarget<'a> {
|
|
|
|
fn from(value: &Viewport<'a, D3D11OutputView>) -> Self {
|
2022-12-01 11:05:12 +11:00
|
|
|
RenderTarget::new(
|
|
|
|
OutputFramebuffer {
|
2023-01-13 18:54:16 +11:00
|
|
|
rtv: value.output.handle.clone(),
|
|
|
|
size: value.output.size,
|
2022-12-01 11:05:12 +11:00
|
|
|
viewport: D3D11_VIEWPORT {
|
|
|
|
TopLeftX: value.x,
|
|
|
|
TopLeftY: value.y,
|
2023-01-13 18:54:16 +11:00
|
|
|
Width: value.output.size.width as f32,
|
|
|
|
Height: value.output.size.height as f32,
|
2022-12-01 11:05:12 +11:00
|
|
|
MinDepth: 0.0,
|
|
|
|
MaxDepth: 1.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
value.mvp,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|