Merge branch 'gles2-simplify-matrix' into 'master'

util/matrix: Simplify the interface

See merge request wlroots/wlroots!4975
This commit is contained in:
Alexander Orzechowski 2025-06-17 12:37:57 -04:00
commit 0bdcb22f66
6 changed files with 70 additions and 123 deletions

View file

@ -124,31 +124,25 @@ static void render(const struct wlr_box *box, const pixman_region32_t *clip, GLi
pixman_region32_fini(&region);
}
static void set_proj_matrix(GLint loc, float proj[9], const struct wlr_box *box) {
static void set_proj_matrix(GLint loc, struct wlr_gles2_buffer *buffer, const struct wlr_box *box) {
float gl_matrix[9];
wlr_matrix_identity(gl_matrix);
wlr_matrix_translate(gl_matrix, box->x, box->y);
wlr_matrix_scale(gl_matrix, box->width, box->height);
wlr_matrix_multiply(gl_matrix, proj, gl_matrix);
matrix_project_box(gl_matrix, box);
matrix_projection(gl_matrix, buffer->buffer->width, buffer->buffer->height);
glUniformMatrix3fv(loc, 1, GL_FALSE, gl_matrix);
}
static void set_tex_matrix(GLint loc, enum wl_output_transform trans,
const struct wlr_fbox *box) {
float tex_matrix[9];
wlr_matrix_identity(tex_matrix);
wlr_matrix_translate(tex_matrix, box->x, box->y);
wlr_matrix_scale(tex_matrix, box->width, box->height);
wlr_matrix_translate(tex_matrix, .5, .5);
matrix_project_fbox(tex_matrix, box);
// since textures have a different origin point we have to transform
// differently if we are rotating
if (trans & WL_OUTPUT_TRANSFORM_90) {
wlr_matrix_transform(tex_matrix, wlr_output_transform_invert(trans));
matrix_transform(tex_matrix, wlr_output_transform_invert(trans));
} else {
wlr_matrix_transform(tex_matrix, trans);
matrix_transform(tex_matrix, trans);
}
wlr_matrix_translate(tex_matrix, -.5, -.5);
glUniformMatrix3fv(loc, 1, GL_FALSE, tex_matrix);
}
@ -244,7 +238,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha);
set_proj_matrix(shader->proj, pass->projection_matrix, &dst_box);
set_proj_matrix(shader->proj, pass->buffer, &dst_box);
set_tex_matrix(shader->tex_proj, options->transform, &src_fbox);
render(&dst_box, options->clip, shader->pos_attrib);
@ -267,7 +261,7 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
glUseProgram(renderer->shaders.quad.program);
set_proj_matrix(renderer->shaders.quad.proj, pass->projection_matrix, &box);
set_proj_matrix(renderer->shaders.quad.proj, pass->buffer, &box);
glUniform4f(renderer->shaders.quad.color, color->r, color->g, color->b, color->a);
render(&box, options->clip, renderer->shaders.quad.pos_attrib);
@ -329,9 +323,6 @@ struct wlr_gles2_render_pass *begin_gles2_buffer_pass(struct wlr_gles2_buffer *b
pass->signal_point = signal_point;
}
matrix_projection(pass->projection_matrix, wlr_buffer->width, wlr_buffer->height,
WL_OUTPUT_TRANSFORM_FLIPPED_180);
push_gles2_debug(renderer);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);

View file

@ -616,10 +616,11 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
switch (options->blend_mode) {
case WLR_RENDER_BLEND_MODE_PREMULTIPLIED:;
float proj[9], matrix[9];
wlr_matrix_identity(proj);
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, proj);
wlr_matrix_multiply(matrix, pass->projection, matrix);
float matrix[9];
matrix_project_box(matrix, &box);
matrix_projection(matrix,
pass->render_buffer->wlr_buffer->width,
pass->render_buffer->wlr_buffer->height);
struct wlr_vk_render_format_setup *setup = pass->srgb_pathway ?
pass->render_buffer->srgb.render_setup :
@ -707,10 +708,12 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
wlr_render_texture_options_get_dst_box(options, &dst_box);
float alpha = wlr_render_texture_options_get_alpha(options);
float proj[9], matrix[9];
wlr_matrix_identity(proj);
wlr_matrix_project_box(matrix, &dst_box, options->transform, proj);
wlr_matrix_multiply(matrix, pass->projection, matrix);
float matrix[9];
matrix_project_box(matrix, &dst_box);
matrix_transform(matrix, options->transform);
matrix_projection(matrix,
pass->render_buffer->wlr_buffer->width,
pass->render_buffer->wlr_buffer->height);
struct wlr_vk_vert_pcr_data vert_pcr_data = {
.uv_off = {
@ -1156,10 +1159,6 @@ struct wlr_vk_render_pass *vulkan_begin_render_pass(struct wlr_vk_renderer *rend
.maxDepth = 1,
});
// matrix_projection() assumes a GL coordinate system so we need
// 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);
pass->render_buffer = buffer;
pass->command_buffer = cb;