Fix surface transforms

This commit is contained in:
emersion 2017-11-30 23:58:12 +01:00
parent 779cccf8b4
commit f4754ad1a2
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 36 additions and 0 deletions

View file

@ -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]); void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]);
enum wl_output_transform; 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, void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
enum wl_output_transform transform); enum wl_output_transform transform);

View file

@ -106,4 +106,6 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
double x, double y); double x, double y);
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor);
enum wl_output_transform wlr_output_transform_invert(enum wl_output_transform);
#endif #endif

View file

@ -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 // 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, void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
enum wl_output_transform transform) { enum wl_output_transform transform) {

View file

@ -63,10 +63,25 @@ static void render_surface(struct wlr_surface *surface,
float scale[16]; float scale[16];
wlr_matrix_scale(&scale, render_width, render_height, 1); 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]; float transform[16];
wlr_matrix_mul(&translate_origin, &rotate, &transform); wlr_matrix_mul(&translate_origin, &rotate, &transform);
wlr_matrix_mul(&transform, &translate_center, &transform); wlr_matrix_mul(&transform, &translate_center, &transform);
wlr_matrix_mul(&transform, &scale, &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_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
wlr_render_with_matrix(desktop->server->renderer, surface->texture, wlr_render_with_matrix(desktop->server->renderer, surface->texture,