Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
render/gles2: compute projection matrix in begin step
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ckb0ne committed Mar 8, 2021
1 parent 1a370b1 commit d93031a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/render/gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct wlr_gles2_tex_shader {
struct wlr_gles2_renderer {
struct wlr_renderer wlr_renderer;

float projection[9];
struct wlr_egl *egl;
int drm_fd;

Expand Down
24 changes: 11 additions & 13 deletions render/gles2/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width,
renderer->viewport_width = width;
renderer->viewport_height = height;

// refresh projection matrix
wlr_matrix_projection(renderer->projection, width, height,
WL_OUTPUT_TRANSFORM_NORMAL);

// enable transparency
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Expand Down Expand Up @@ -240,7 +244,7 @@ static const float flip_180[9] = {

static bool gles2_render_subtexture_with_matrix(
struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture,
const struct wlr_fbox *box, const float mat[static 9],
const struct wlr_fbox *box, const float matrix[static 9],
float alpha) {
struct wlr_gles2_renderer *renderer =
gles2_get_renderer_in_context(wlr_renderer);
Expand Down Expand Up @@ -270,17 +274,9 @@ static bool gles2_render_subtexture_with_matrix(
abort();
}

float proj[9];
wlr_matrix_projection(proj, box->width, box->height,
WL_OUTPUT_TRANSFORM_NORMAL);

float matrix[9];
wlr_matrix_multiply(matrix, proj, mat);

wlr_matrix_scale(matrix, 1.f/box->width, 1.f/box->height);

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down Expand Up @@ -334,7 +330,8 @@ static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down Expand Up @@ -364,7 +361,8 @@ static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer,
gles2_get_renderer_in_context(wlr_renderer);

float gl_matrix[9];
wlr_matrix_multiply(gl_matrix, flip_180, matrix);
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);

// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
// to GL_FALSE
Expand Down

0 comments on commit d93031a

Please sign in to comment.