mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-04 20:55:58 +01:00
Fix surface transforms
This commit is contained in:
parent
779cccf8b4
commit
f4754ad1a2
4 changed files with 36 additions and 0 deletions
|
@ -10,6 +10,8 @@ void wlr_matrix_rotate(float (*output)[16], float radians);
|
|||
void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]);
|
||||
|
||||
enum wl_output_transform;
|
||||
void wlr_matrix_transform(float mat[static 16],
|
||||
enum wl_output_transform transform);
|
||||
void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
|
||||
enum wl_output_transform transform);
|
||||
|
||||
|
|
|
@ -106,4 +106,6 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
|
|||
double x, double y);
|
||||
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor);
|
||||
|
||||
enum wl_output_transform wlr_output_transform_invert(enum wl_output_transform);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -118,6 +118,23 @@ static const float transforms[][4] = {
|
|||
},
|
||||
};
|
||||
|
||||
void wlr_matrix_transform(float mat[static 16],
|
||||
enum wl_output_transform transform) {
|
||||
memset(mat, 0, sizeof(*mat) * 16);
|
||||
|
||||
const float *t = transforms[transform];
|
||||
|
||||
// Rotation + relection
|
||||
mat[0] = t[0];
|
||||
mat[1] = t[1];
|
||||
mat[4] = -t[2];
|
||||
mat[5] = -t[3];
|
||||
|
||||
// Identity
|
||||
mat[10] = 1.0f;
|
||||
mat[15] = 1.0f;
|
||||
}
|
||||
|
||||
// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied
|
||||
void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
|
||||
enum wl_output_transform transform) {
|
||||
|
|
|
@ -63,10 +63,25 @@ static void render_surface(struct wlr_surface *surface,
|
|||
float scale[16];
|
||||
wlr_matrix_scale(&scale, render_width, render_height, 1);
|
||||
|
||||
float translate_mdr[16];
|
||||
wlr_matrix_translate(&translate_mdr, 0.5, 0.5, 0);
|
||||
|
||||
float surface_transform[16];
|
||||
wlr_matrix_transform(surface_transform,
|
||||
wlr_output_transform_invert(surface->current->transform)); // TODO
|
||||
|
||||
float translate_mdr2[16];
|
||||
wlr_matrix_translate(&translate_mdr2, -0.5, -0.5, 0);
|
||||
|
||||
float transform[16];
|
||||
wlr_matrix_mul(&translate_origin, &rotate, &transform);
|
||||
wlr_matrix_mul(&transform, &translate_center, &transform);
|
||||
wlr_matrix_mul(&transform, &scale, &transform);
|
||||
|
||||
wlr_matrix_mul(&transform, &translate_mdr, &transform);
|
||||
wlr_matrix_mul(&transform, &surface_transform, &transform);
|
||||
wlr_matrix_mul(&transform, &translate_mdr2, &transform);
|
||||
|
||||
wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
|
||||
|
||||
wlr_render_with_matrix(desktop->server->renderer, surface->texture,
|
||||
|
|
Loading…
Reference in a new issue