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

45 lines
1.1 KiB
Rust
Raw Normal View History

2022-11-30 22:50:57 -05:00
use crate::gl::Framebuffer;
2023-01-15 03:06:09 -05:00
use librashader_common::Viewport;
2022-11-19 23:16:19 -05:00
2022-11-20 01:09:05 -05:00
#[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[
2022-11-20 00:05:50 -05: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-19 23:16:19 -05:00
];
#[derive(Debug, Copy, Clone)]
pub(crate) struct RenderTarget<'a> {
pub mvp: &'a [f32; 16],
pub framebuffer: &'a Framebuffer,
2022-11-27 02:10:11 -05:00
pub x: i32,
2022-11-30 01:38:05 -05:00
pub y: i32,
2022-11-19 23:16:19 -05:00
}
impl<'a> RenderTarget<'a> {
pub fn new(backbuffer: &'a Framebuffer, mvp: Option<&'a [f32; 16]>, x: i32, y: i32) -> Self {
2022-11-19 23:16:19 -05:00
if let Some(mvp) = mvp {
RenderTarget {
framebuffer: backbuffer,
2022-11-27 02:10:11 -05:00
x,
2022-11-19 23:16:57 -05:00
mvp,
2022-11-27 02:10:11 -05:00
y,
2022-11-19 23:16:19 -05:00
}
} else {
RenderTarget {
framebuffer: backbuffer,
2022-11-27 02:10:11 -05:00
x,
2022-11-19 23:16:57 -05:00
mvp: DEFAULT_MVP,
2022-11-27 02:10:11 -05:00
y,
2022-11-19 23:16:19 -05:00
}
}
}
}
2023-01-13 02:54:16 -05:00
impl<'a> From<&Viewport<'a, &'a Framebuffer>> for RenderTarget<'a> {
fn from(value: &Viewport<'a, &'a Framebuffer>) -> Self {
2022-11-30 19:05:24 -05:00
RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32)
2022-11-19 23:16:19 -05:00
}
2022-11-19 23:16:57 -05:00
}