2022-11-30 15:56:10 +11:00
|
|
|
use crate::framebuffer::Viewport;
|
|
|
|
use crate::gl::Framebuffer;
|
2022-11-20 15:16:19 +11:00
|
|
|
|
2022-11-20 17:09:05 +11:00
|
|
|
#[rustfmt::skip]
|
2022-11-28 15:27:21 +11:00
|
|
|
static DEFAULT_MVP: &[f32; 16] = &[
|
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)]
|
2022-11-30 16:39:42 +11:00
|
|
|
pub(crate) struct RenderTarget<'a, T: Framebuffer> {
|
2022-11-28 15:27:21 +11:00
|
|
|
pub mvp: &'a [f32; 16],
|
2022-11-30 16:39:42 +11:00
|
|
|
pub framebuffer: &'a T,
|
2022-11-27 18:10:11 +11:00
|
|
|
pub x: i32,
|
|
|
|
pub y: i32
|
2022-11-20 15:16:19 +11:00
|
|
|
}
|
|
|
|
|
2022-11-30 16:39:42 +11:00
|
|
|
impl<'a, T: Framebuffer> RenderTarget<'a, T> {
|
|
|
|
pub fn new(backbuffer: &'a T, mvp: Option<&'a [f32; 16]>, x: i32, y: i32) -> Self {
|
2022-11-20 15:16:19 +11:00
|
|
|
if let Some(mvp) = mvp {
|
|
|
|
RenderTarget {
|
|
|
|
framebuffer: backbuffer,
|
2022-11-27 18:10:11 +11:00
|
|
|
x,
|
2022-11-20 15:16:57 +11:00
|
|
|
mvp,
|
2022-11-27 18:10:11 +11:00
|
|
|
y,
|
2022-11-20 15:16:19 +11:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RenderTarget {
|
|
|
|
framebuffer: backbuffer,
|
2022-11-27 18:10:11 +11:00
|
|
|
x,
|
2022-11-20 15:16:57 +11:00
|
|
|
mvp: DEFAULT_MVP,
|
2022-11-27 18:10:11 +11:00
|
|
|
y,
|
2022-11-20 15:16:19 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:39:42 +11:00
|
|
|
impl<'a, T: Framebuffer> From<&Viewport<'a, T>> for RenderTarget<'a, T> {
|
|
|
|
fn from(value: &Viewport<'a, T>) -> Self {
|
2022-11-27 18:10:11 +11:00
|
|
|
RenderTarget::new(value.output, value.mvp, value.x, value.y)
|
2022-11-20 15:16:19 +11:00
|
|
|
}
|
2022-11-20 15:16:57 +11:00
|
|
|
}
|