diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-26 16:27:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-26 16:27:37 -0400 |
commit | b66ab811a675b0ceff72943dc1c0ed1ad2bd46ed (patch) | |
tree | ee25807dec18f6f79dfbe262567cb2259d66119c /render | |
parent | bcb74c2c781405149af99f66ce61b1a8f63771fd (diff) | |
parent | 793c3b30473bcad488eae9266b67ccfdf3106231 (diff) |
Merge pull request #750 from emersion/renderer-simple-interface
render: add simple functions to render rectangles and ellipses
Diffstat (limited to 'render')
-rw-r--r-- | render/gles2/renderer.c | 8 | ||||
-rw-r--r-- | render/wlr_renderer.c | 41 |
2 files changed, 35 insertions, 14 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9403c0ed..61665a07 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -144,7 +144,7 @@ static bool gles2_render_texture_with_matrix( } -static void gles2_render_quad(struct wlr_renderer *wlr_renderer, +static void gles2_render_quad_with_matrix(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -161,7 +161,7 @@ static void gles2_render_quad(struct wlr_renderer *wlr_renderer, GLES2_DEBUG_POP; } -static void gles2_render_ellipse(struct wlr_renderer *wlr_renderer, +static void gles2_render_ellipse_with_matrix(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -256,8 +256,8 @@ static const struct wlr_renderer_impl renderer_impl = { .scissor = gles2_scissor, .texture_create = gles2_renderer_texture_create, .render_texture_with_matrix = gles2_render_texture_with_matrix, - .render_quad = gles2_render_quad, - .render_ellipse = gles2_render_ellipse, + .render_quad_with_matrix = gles2_render_quad_with_matrix, + .render_ellipse_with_matrix = gles2_render_ellipse_with_matrix, .formats = gles2_renderer_formats, .buffer_is_drm = gles2_buffer_is_drm, .read_pixels = gles2_read_pixels, diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 622aa1dd..5598a0e7 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -39,13 +39,16 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, const float projection[static 9], int x, int y, float alpha) { - float mat[9]; - wlr_matrix_identity(mat); - wlr_matrix_translate(mat, x, y); - wlr_matrix_scale(mat, texture->width, texture->height); - wlr_matrix_multiply(mat, projection, mat); + const struct wlr_box box = { + .x = x, .y = y, + .width = texture->width, .height = texture->height, + }; - return wlr_render_texture_with_matrix(r, texture, mat, alpha); + float matrix[9]; + wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + return wlr_render_texture_with_matrix(r, texture, matrix, alpha); } bool wlr_render_texture_with_matrix(struct wlr_renderer *r, @@ -54,14 +57,32 @@ bool wlr_render_texture_with_matrix(struct wlr_renderer *r, return r->impl->render_texture_with_matrix(r, texture, matrix, alpha); } -void wlr_render_colored_quad(struct wlr_renderer *r, +void wlr_render_rect(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]) { + float matrix[9]; + wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + wlr_render_quad_with_matrix(r, color, matrix); +} + +void wlr_render_quad_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]) { - r->impl->render_quad(r, color, matrix); + r->impl->render_quad_with_matrix(r, color, matrix); +} + +void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box, + const float color[static 4], const float projection[static 9]) { + float matrix[9]; + wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, + projection); + + wlr_render_ellipse_with_matrix(r, color, matrix); } -void wlr_render_colored_ellipse(struct wlr_renderer *r, +void wlr_render_ellipse_with_matrix(struct wlr_renderer *r, const float color[static 4], const float matrix[static 9]) { - r->impl->render_ellipse(r, color, matrix); + r->impl->render_ellipse_with_matrix(r, color, matrix); } const enum wl_shm_format *wlr_renderer_get_formats( |