diff options
-rw-r--r-- | include/wlr/render/matrix.h | 2 | ||||
-rw-r--r-- | include/wlr/types/wlr_output.h | 2 | ||||
-rw-r--r-- | render/matrix.c | 17 | ||||
-rw-r--r-- | rootston/output.c | 15 |
4 files changed, 36 insertions, 0 deletions
diff --git a/include/wlr/render/matrix.h b/include/wlr/render/matrix.h index 177af4b3..0b35aad3 100644 --- a/include/wlr/render/matrix.h +++ b/include/wlr/render/matrix.h @@ -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); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index d382b593..b1b83044 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -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 diff --git a/render/matrix.c b/render/matrix.c index e49d365e..8a3352e0 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -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) { diff --git a/rootston/output.c b/rootston/output.c index bf684f2f..c1d2e9f3 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -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, |