librashader/librashader-runtime-gl/src/render_target.rs

39 lines
891 B
Rust
Raw Normal View History

2022-11-20 15:16:19 +11:00
use crate::framebuffer::Framebuffer;
use crate::util::Viewport;
2022-11-20 17:09:05 +11:00
#[rustfmt::skip]
2022-11-20 15:16:19 +11:00
static DEFAULT_MVP: &[f32] = &[
2022-11-20 16:05:50 +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,
2022-11-20 15:16:19 +11:00
];
#[derive(Debug, Copy, Clone)]
pub struct RenderTarget<'a> {
pub mvp: &'a [f32],
2022-11-20 15:16:57 +11:00
pub framebuffer: &'a Framebuffer,
2022-11-20 15:16:19 +11:00
}
2022-11-20 15:16:57 +11:00
impl<'a> RenderTarget<'a> {
2022-11-20 15:16:19 +11:00
pub fn new(backbuffer: &'a Framebuffer, mvp: Option<&'a [f32]>) -> Self {
if let Some(mvp) = mvp {
RenderTarget {
framebuffer: backbuffer,
2022-11-20 15:16:57 +11:00
mvp,
2022-11-20 15:16:19 +11:00
}
} else {
RenderTarget {
framebuffer: backbuffer,
2022-11-20 15:16:57 +11:00
mvp: DEFAULT_MVP,
2022-11-20 15:16:19 +11:00
}
}
}
}
2022-11-20 15:16:57 +11:00
impl<'a> From<&Viewport<'a>> for RenderTarget<'a> {
2022-11-20 15:16:19 +11:00
fn from(value: &Viewport<'a>) -> Self {
RenderTarget::new(value.output, value.mvp)
}
2022-11-20 15:16:57 +11:00
}