1
0
Fork 0
forked from wry/wry

render: split rendering into two phases

In the first phase we collect a list of simple operations (copying
textures and filling rectangles.)

In the second phase we send this list to the graphics API to be
executed.

As part of this, we also remove the use of scissors.
This commit is contained in:
Julian Orth 2023-10-22 16:10:10 +02:00
parent a2a04512ed
commit 5e8a6eb86f
27 changed files with 732 additions and 384 deletions

View file

@ -0,0 +1,84 @@
use {
crate::{format::Format, render::Texture, theme::Color},
std::rc::Rc,
};
pub enum GfxApiOpt {
Sync,
Clear(Clear),
FillRect(FillRect),
CopyTexture(CopyTexture),
}
#[derive(Default, Debug, Copy, Clone)]
pub struct BufferPoint {
pub x: f32,
pub y: f32,
}
impl BufferPoint {
pub fn is_leq_1(&self) -> bool {
self.x <= 1.0 && self.y <= 1.0
}
}
#[derive(Default, Debug, Copy, Clone)]
pub struct BufferPoints {
pub top_left: BufferPoint,
pub top_right: BufferPoint,
pub bottom_left: BufferPoint,
pub bottom_right: BufferPoint,
}
impl BufferPoints {
pub fn norm(&self, width: f32, height: f32) -> Self {
Self {
top_left: BufferPoint {
x: self.top_left.x / width,
y: self.top_left.y / height,
},
top_right: BufferPoint {
x: self.top_right.x / width,
y: self.top_right.y / height,
},
bottom_left: BufferPoint {
x: self.bottom_left.x / width,
y: self.bottom_left.y / height,
},
bottom_right: BufferPoint {
x: self.bottom_right.x / width,
y: self.bottom_right.y / height,
},
}
}
pub fn is_leq_1(&self) -> bool {
self.top_left.is_leq_1()
&& self.top_right.is_leq_1()
&& self.bottom_left.is_leq_1()
&& self.bottom_right.is_leq_1()
}
}
pub struct AbsoluteRect {
pub x1: f32,
pub x2: f32,
pub y1: f32,
pub y2: f32,
}
pub struct Clear {
pub color: Color,
}
pub struct FillRect {
pub rect: AbsoluteRect,
pub color: Color,
}
pub struct CopyTexture {
pub tex: Rc<Texture>,
pub format: &'static Format,
pub source: BufferPoints,
pub target: AbsoluteRect,
}