fix texture uv mess

This commit is contained in:
griffi-gh 2024-03-25 18:00:15 +01:00
parent dca0c0d2a4
commit 405963460d

View file

@ -1,7 +1,5 @@
//! draw commands, tesselation and UI rendering. //! draw commands, tesselation and UI rendering.
//TODO: 9-slice draw command
use crate::{ use crate::{
rect::Corners, rect::Corners,
text::{FontHandle, TextRenderer} text::{FontHandle, TextRenderer}
@ -169,22 +167,26 @@ impl UiDrawCall {
.flatten() .flatten()
.map(|guv| { .map(|guv| {
if let Some(texture_uv) = texture_uv { if let Some(texture_uv) = texture_uv {
//XXX: this assumes that it's not rotated :p //XXX: this may not work if the texture is rotated
//hell will break loose if it is //also is this slow?
//seriously, i fvcking despise this code, and i hope to never touch this file ever again
//FIXME: this is only valid if top_left is acutally the min (e.g. only for rectangular crops) let top = guv.top_left.lerp(guv.top_right, texture_uv.top_left.x);
//We currently only need rectangular crops so i don't give a fvck let bottom = guv.bottom_left.lerp(guv.bottom_right, texture_uv.top_left.x);
let uv_size = guv.bottom_right - guv.top_left; let top_left = top.lerp(bottom, texture_uv.top_left.y);
let mut uv_mapped = *texture_uv;
uv_mapped.top_left *= uv_size; let top = guv.top_left.lerp(guv.top_right, texture_uv.top_right.x);
uv_mapped.top_right *= uv_size; let bottom = guv.bottom_left.lerp(guv.bottom_right, texture_uv.top_right.x);
uv_mapped.bottom_left *= uv_size; let top_right = top.lerp(bottom, texture_uv.top_right.y);
uv_mapped.bottom_right *= uv_size;
uv_mapped.top_left += guv.top_left; let top = guv.top_left.lerp(guv.top_right, texture_uv.bottom_left.x);
uv_mapped.top_right += guv.top_left; let bottom = guv.bottom_left.lerp(guv.bottom_right, texture_uv.bottom_left.x);
uv_mapped.bottom_left += guv.top_left; let bottom_left = top.lerp(bottom, texture_uv.bottom_left.y);
uv_mapped.bottom_right += guv.top_left;
uv_mapped let top = guv.top_left.lerp(guv.top_right, texture_uv.bottom_right.x);
let bottom = guv.bottom_left.lerp(guv.bottom_right, texture_uv.bottom_right.x);
let bottom_right = top.lerp(bottom, texture_uv.bottom_right.y);
Corners { top_left, top_right, bottom_left, bottom_right }
} else { } else {
guv guv
} }