librashader/librashader-runtime-gl/src/render_target.rs
2022-11-30 22:50:57 -05:00

45 lines
1 KiB
Rust

use crate::gl::Framebuffer;
use crate::viewport::Viewport;
#[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[
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, Copy, Clone)]
pub(crate) struct RenderTarget<'a> {
pub mvp: &'a [f32; 16],
pub framebuffer: &'a Framebuffer,
pub x: i32,
pub y: i32,
}
impl<'a> RenderTarget<'a> {
pub fn new(backbuffer: &'a Framebuffer, mvp: Option<&'a [f32; 16]>, x: i32, y: i32) -> Self {
if let Some(mvp) = mvp {
RenderTarget {
framebuffer: backbuffer,
x,
mvp,
y,
}
} else {
RenderTarget {
framebuffer: backbuffer,
x,
mvp: DEFAULT_MVP,
y,
}
}
}
}
impl<'a> From<&Viewport<'a>> for RenderTarget<'a> {
fn from(value: &Viewport<'a>) -> Self {
RenderTarget::new(value.output, value.mvp, value.x as i32, value.y as i32)
}
}