chore(render): use Affine2 where possible
This commit is contained in:
parent
8955024bff
commit
60137c0d9e
5 changed files with 31 additions and 26 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::{borrow::Borrow, cell::RefCell, collections::HashMap};
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use glam::{Affine2, Mat3, Vec2};
|
||||
use smithay::{
|
||||
backend::renderer::{
|
||||
element::Kind,
|
||||
|
|
@ -117,18 +117,22 @@ impl ShadowShader {
|
|||
let geo_loc = Vec2::new(-shader_geo.loc.x as f32, -shader_geo.loc.y as f32);
|
||||
shader_geo.loc += offset + geo.loc;
|
||||
|
||||
let input_to_geo = Mat3::from_scale(area_size)
|
||||
* Mat3::from_translation(Vec2::new(
|
||||
-geo_loc.x / area_size.x,
|
||||
-geo_loc.y / area_size.y,
|
||||
));
|
||||
let input_to_geo = Mat3::from(
|
||||
Affine2::from_scale(area_size)
|
||||
* Affine2::from_translation(Vec2::new(
|
||||
-geo_loc.x / area_size.x,
|
||||
-geo_loc.y / area_size.y,
|
||||
)),
|
||||
);
|
||||
|
||||
let window_geo_loc = Vec2::new(window_geo.loc.x as f32, window_geo.loc.y as f32);
|
||||
let window_input_to_geo = Mat3::from_scale(area_size)
|
||||
* Mat3::from_translation(Vec2::new(
|
||||
-window_geo_loc.x / area_size.x,
|
||||
-window_geo_loc.y / area_size.y,
|
||||
));
|
||||
let window_input_to_geo = Mat3::from(
|
||||
Affine2::from_scale(area_size)
|
||||
* Affine2::from_translation(Vec2::new(
|
||||
-window_geo_loc.x / area_size.x,
|
||||
-window_geo_loc.y / area_size.y,
|
||||
)),
|
||||
);
|
||||
|
||||
let element = PixelShaderElement::new(
|
||||
shader,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use glam::{Affine2, Mat3, Vec2};
|
||||
use smithay::{
|
||||
backend::{
|
||||
allocator::Fourcc,
|
||||
|
|
@ -231,16 +231,16 @@ impl BlurElement {
|
|||
// compute input_to_geo so that it crops the extended capture radius
|
||||
let geo_scale = {
|
||||
let Scale { x, y } = geo.size / extended_geo.size;
|
||||
Mat3::from_scale(Vec2::new(x as f32, y as f32)).inverse()
|
||||
Affine2::from_scale(Vec2::new(x as f32, y as f32)).inverse()
|
||||
};
|
||||
let geo_translation = {
|
||||
let offset = geo.loc - extended_geo.loc;
|
||||
Mat3::from_translation(-Vec2::new(
|
||||
Affine2::from_translation(-Vec2::new(
|
||||
(offset.x / extended_geo.size.w) as f32,
|
||||
(offset.y / extended_geo.size.h) as f32,
|
||||
))
|
||||
};
|
||||
let input_to_geo = geo_scale * geo_translation;
|
||||
let input_to_geo = Mat3::from(geo_scale * geo_translation);
|
||||
|
||||
let uniforms = vec![
|
||||
Uniform::new("geo_size", (geometry.size.w as f32, geometry.size.h as f32)),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::borrow::{Borrow, BorrowMut};
|
||||
|
||||
use glam::{Mat3, Vec2};
|
||||
use glam::{Affine2, Mat3, Vec2};
|
||||
use smithay::utils::{Buffer, Logical, Physical, Point, Rectangle, Scale, Size, Transform};
|
||||
use smithay::{
|
||||
backend::renderer::{
|
||||
|
|
@ -63,18 +63,18 @@ where
|
|||
let view = elem.view();
|
||||
|
||||
let transform = elem.transform();
|
||||
let transform_matrix = Mat3::from_translation(Vec2::new(0.5, 0.5))
|
||||
let transform_matrix = Affine2::from_translation(Vec2::new(0.5, 0.5))
|
||||
* transform.matrix()
|
||||
* Mat3::from_translation(-Vec2::new(0.5, 0.5));
|
||||
* Affine2::from_translation(-Vec2::new(0.5, 0.5));
|
||||
|
||||
let geo_scale = {
|
||||
let Scale { x, y } = elem_geo.size.to_f64() / geo.size.to_f64();
|
||||
Mat3::from_scale(Vec2::new(x as f32, y as f32))
|
||||
Affine2::from_scale(Vec2::new(x as f32, y as f32))
|
||||
};
|
||||
|
||||
let geo_translation = {
|
||||
let offset = (elem_geo.loc - geo.loc).to_f64();
|
||||
Mat3::from_translation(Vec2::new(
|
||||
Affine2::from_translation(Vec2::new(
|
||||
(offset.x / elem_geo.size.w as f64) as f32,
|
||||
(offset.y / elem_geo.size.h as f64) as f32,
|
||||
))
|
||||
|
|
@ -82,16 +82,17 @@ where
|
|||
|
||||
let buf_scale = {
|
||||
let Scale { x, y } = buf_size.to_f64() / view.src.size.to_f64();
|
||||
Mat3::from_scale(Vec2::new(x as f32, y as f32))
|
||||
Affine2::from_scale(Vec2::new(x as f32, y as f32))
|
||||
};
|
||||
|
||||
let buf_translation = Mat3::from_translation(Vec2::new(
|
||||
let buf_translation = Affine2::from_translation(Vec2::new(
|
||||
(view.src.loc.x / buf_size.w as f64) as f32,
|
||||
(view.src.loc.y / buf_size.h as f64) as f32,
|
||||
));
|
||||
|
||||
let input_to_geo =
|
||||
transform_matrix * geo_scale * geo_translation * buf_scale * buf_translation;
|
||||
let input_to_geo = Mat3::from(
|
||||
transform_matrix * geo_scale * geo_translation * buf_scale * buf_translation,
|
||||
);
|
||||
|
||||
let uniforms = vec![
|
||||
Uniform::new("geo_size", (geometry.size.w as f32, geometry.size.h as f32)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue