util/matrix: Simplify matrix_projection

The transform argument is always passed WL_OUTPUT_TRANSFORM_FLIPPED_180
This commit is contained in:
Alexander Orzechowski 2025-01-27 13:48:07 -05:00
parent b6fec1b101
commit 51c07a662a
4 changed files with 7 additions and 20 deletions

View file

@ -31,12 +31,10 @@ void wlr_matrix_transform(float mat[static 9],
void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box); void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box);
/** /**
* Writes a 2D orthographic projection matrix to mat of (width, height) with a * Writes a 2D orthographic projection matrix to mat of (width, height).
* specified wl_output_transform.
* *
* Equivalent to glOrtho(0, width, 0, height, 1, -1) with the transform applied. * Equivalent to glOrtho(0, width, 0, height, 1, -1) with the transform applied.
*/ */
void matrix_projection(float mat[static 9], int width, int height, void matrix_projection(float mat[static 9], int width, int height);
enum wl_output_transform transform);
#endif #endif

View file

@ -327,8 +327,7 @@ struct wlr_gles2_render_pass *begin_gles2_buffer_pass(struct wlr_gles2_buffer *b
pass->signal_point = signal_point; pass->signal_point = signal_point;
} }
matrix_projection(pass->projection_matrix, wlr_buffer->width, wlr_buffer->height, matrix_projection(pass->projection_matrix, wlr_buffer->width, wlr_buffer->height);
WL_OUTPUT_TRANSFORM_FLIPPED_180);
push_gles2_debug(renderer); push_gles2_debug(renderer);
glBindFramebuffer(GL_FRAMEBUFFER, fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo);

View file

@ -1131,9 +1131,7 @@ struct wlr_vk_render_pass *vulkan_begin_render_pass(struct wlr_vk_renderer *rend
.maxDepth = 1, .maxDepth = 1,
}); });
// matrix_projection() assumes a GL coordinate system so we need matrix_projection(pass->projection, width, height);
// to pass WL_OUTPUT_TRANSFORM_FLIPPED_180 to adjust it for vulkan.
matrix_projection(pass->projection, width, height, WL_OUTPUT_TRANSFORM_FLIPPED_180);
wlr_buffer_lock(buffer->wlr_buffer); wlr_buffer_lock(buffer->wlr_buffer);
pass->render_buffer = buffer; pass->render_buffer = buffer;

View file

@ -97,19 +97,11 @@ void wlr_matrix_transform(float mat[static 9],
wlr_matrix_multiply(mat, mat, transforms[transform]); wlr_matrix_multiply(mat, mat, transforms[transform]);
} }
void matrix_projection(float mat[static 9], int width, int height, void matrix_projection(float mat[static 9], int width, int height) {
enum wl_output_transform transform) {
memset(mat, 0, sizeof(*mat) * 9); memset(mat, 0, sizeof(*mat) * 9);
const float *t = transforms[transform]; mat[0] = 2.0f / width;
float x = 2.0f / width; mat[4] = 2.0f / height;
float y = 2.0f / height;
// Rotation + reflection
mat[0] = x * t[0];
mat[1] = x * t[1];
mat[3] = y * -t[3];
mat[4] = y * -t[4];
// Translation // Translation
mat[2] = -copysign(1.0f, mat[0] + mat[1]); mat[2] = -copysign(1.0f, mat[0] + mat[1]);