render: add simple functions to render rectangles and ellipses
This commit is contained in:
parent
bcb74c2c78
commit
793c3b3047
|
@ -49,7 +49,6 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
||||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||||
|
|
||||||
float matrix[9];
|
|
||||||
float distance = 0.8f * (1 - sample->distance);
|
float distance = 0.8f * (1 - sample->distance);
|
||||||
float tool_color[4] = { distance, distance, distance, 1 };
|
float tool_color[4] = { distance, distance, distance, 1 };
|
||||||
for (size_t i = 0; sample->button && i < 4; ++i) {
|
for (size_t i = 0; sample->button && i < 4; ++i) {
|
||||||
|
@ -61,12 +60,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
float pad_height = sample->height_mm * scale;
|
float pad_height = sample->height_mm * scale;
|
||||||
float left = width / 2.0f - pad_width / 2.0f;
|
float left = width / 2.0f - pad_width / 2.0f;
|
||||||
float top = height / 2.0f - pad_height / 2.0f;
|
float top = height / 2.0f - pad_height / 2.0f;
|
||||||
struct wlr_box box = {
|
const struct wlr_box box = {
|
||||||
.x = left, .y = top,
|
.x = left, .y = top,
|
||||||
.width = pad_width, .height = pad_height,
|
.width = pad_width, .height = pad_height,
|
||||||
};
|
};
|
||||||
wlr_matrix_project_box(matrix, &box, 0, 0, wlr_output->transform_matrix);
|
wlr_render_rect(sample->renderer, &box, sample->pad_color,
|
||||||
wlr_render_colored_quad(sample->renderer, sample->pad_color, matrix);
|
wlr_output->transform_matrix);
|
||||||
|
|
||||||
if (sample->proximity) {
|
if (sample->proximity) {
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
|
@ -75,16 +74,17 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
.width = 16 * (sample->pressure + 1),
|
.width = 16 * (sample->pressure + 1),
|
||||||
.height = 16 * (sample->pressure + 1),
|
.height = 16 * (sample->pressure + 1),
|
||||||
};
|
};
|
||||||
wlr_matrix_project_box(matrix, &box, 0, sample->ring,
|
float matrix[9];
|
||||||
wlr_output->transform_matrix);
|
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
|
||||||
wlr_render_colored_quad(sample->renderer, tool_color, matrix);
|
sample->ring, wlr_output->transform_matrix);
|
||||||
|
wlr_render_quad_with_matrix(sample->renderer, tool_color, matrix);
|
||||||
|
|
||||||
box.x += sample->x_tilt;
|
box.x += sample->x_tilt;
|
||||||
box.y += sample->y_tilt;
|
box.y += sample->y_tilt;
|
||||||
box.width /= 2;
|
box.width /= 2;
|
||||||
box.height /= 2;
|
box.height /= 2;
|
||||||
wlr_matrix_project_box(matrix, &box, 0, 0,
|
wlr_render_rect(sample->renderer, &box, tool_color,
|
||||||
wlr_output->transform_matrix);
|
wlr_output->transform_matrix);
|
||||||
wlr_render_colored_quad(sample->renderer, tool_color, matrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_renderer_end(sample->renderer);
|
wlr_renderer_end(sample->renderer);
|
||||||
|
|
|
@ -27,9 +27,9 @@ struct wlr_renderer_impl {
|
||||||
bool (*render_texture_with_matrix)(struct wlr_renderer *renderer,
|
bool (*render_texture_with_matrix)(struct wlr_renderer *renderer,
|
||||||
struct wlr_texture *texture, const float matrix[static 9],
|
struct wlr_texture *texture, const float matrix[static 9],
|
||||||
float alpha);
|
float alpha);
|
||||||
void (*render_quad)(struct wlr_renderer *renderer,
|
void (*render_quad_with_matrix)(struct wlr_renderer *renderer,
|
||||||
const float color[static 4], const float matrix[static 9]);
|
const float color[static 4], const float matrix[static 9]);
|
||||||
void (*render_ellipse)(struct wlr_renderer *renderer,
|
void (*render_ellipse_with_matrix)(struct wlr_renderer *renderer,
|
||||||
const float color[static 4], const float matrix[static 9]);
|
const float color[static 4], const float matrix[static 9]);
|
||||||
const enum wl_shm_format *(*formats)(
|
const enum wl_shm_format *(*formats)(
|
||||||
struct wlr_renderer *renderer, size_t *len);
|
struct wlr_renderer *renderer, size_t *len);
|
||||||
|
|
|
@ -36,14 +36,24 @@ bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
|
||||||
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
|
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
|
||||||
struct wlr_texture *texture, const float matrix[static 9], float alpha);
|
struct wlr_texture *texture, const float matrix[static 9], float alpha);
|
||||||
/**
|
/**
|
||||||
* Renders a solid quad in the specified color.
|
* Renders a solid rectangle in the specified color.
|
||||||
*/
|
*/
|
||||||
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]);
|
||||||
|
/**
|
||||||
|
* Renders a solid quadrangle in the specified color with the specified matrix.
|
||||||
|
*/
|
||||||
|
void wlr_render_quad_with_matrix(struct wlr_renderer *r,
|
||||||
const float color[static 4], const float matrix[static 9]);
|
const float color[static 4], const float matrix[static 9]);
|
||||||
/**
|
/**
|
||||||
* Renders a solid ellipse in the specified color.
|
* Renders a solid ellipse in the specified color.
|
||||||
*/
|
*/
|
||||||
void wlr_render_colored_ellipse(struct wlr_renderer *r,
|
void wlr_render_ellipse(struct wlr_renderer *r, const struct wlr_box *box,
|
||||||
|
const float color[static 4], const float projection[static 9]);
|
||||||
|
/**
|
||||||
|
* Renders a solid ellipse in the specified color with the specified matrix.
|
||||||
|
*/
|
||||||
|
void wlr_render_ellipse_with_matrix(struct wlr_renderer *r,
|
||||||
const float color[static 4], const float matrix[static 9]);
|
const float color[static 4], const float matrix[static 9]);
|
||||||
/**
|
/**
|
||||||
* Returns a list of pixel formats supported by this renderer.
|
* Returns a list of pixel formats supported by this renderer.
|
||||||
|
|
|
@ -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]) {
|
const float color[static 4], const float matrix[static 9]) {
|
||||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
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;
|
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]) {
|
const float color[static 4], const float matrix[static 9]) {
|
||||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
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,
|
.scissor = gles2_scissor,
|
||||||
.texture_create = gles2_renderer_texture_create,
|
.texture_create = gles2_renderer_texture_create,
|
||||||
.render_texture_with_matrix = gles2_render_texture_with_matrix,
|
.render_texture_with_matrix = gles2_render_texture_with_matrix,
|
||||||
.render_quad = gles2_render_quad,
|
.render_quad_with_matrix = gles2_render_quad_with_matrix,
|
||||||
.render_ellipse = gles2_render_ellipse,
|
.render_ellipse_with_matrix = gles2_render_ellipse_with_matrix,
|
||||||
.formats = gles2_renderer_formats,
|
.formats = gles2_renderer_formats,
|
||||||
.buffer_is_drm = gles2_buffer_is_drm,
|
.buffer_is_drm = gles2_buffer_is_drm,
|
||||||
.read_pixels = gles2_read_pixels,
|
.read_pixels = gles2_read_pixels,
|
||||||
|
|
|
@ -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,
|
bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
|
||||||
const float projection[static 9], int x, int y, float alpha) {
|
const float projection[static 9], int x, int y, float alpha) {
|
||||||
float mat[9];
|
const struct wlr_box box = {
|
||||||
wlr_matrix_identity(mat);
|
.x = x, .y = y,
|
||||||
wlr_matrix_translate(mat, x, y);
|
.width = texture->width, .height = texture->height,
|
||||||
wlr_matrix_scale(mat, texture->width, texture->height);
|
};
|
||||||
wlr_matrix_multiply(mat, projection, mat);
|
|
||||||
|
|
||||||
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,
|
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);
|
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 matrix[static 9]) {
|
const float color[static 4], const float projection[static 9]) {
|
||||||
r->impl->render_quad(r, color, matrix);
|
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_colored_ellipse(struct wlr_renderer *r,
|
void wlr_render_quad_with_matrix(struct wlr_renderer *r,
|
||||||
const float color[static 4], const float matrix[static 9]) {
|
const float color[static 4], const float matrix[static 9]) {
|
||||||
r->impl->render_ellipse(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_ellipse_with_matrix(struct wlr_renderer *r,
|
||||||
|
const float color[static 4], const float matrix[static 9]) {
|
||||||
|
r->impl->render_ellipse_with_matrix(r, color, matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
const enum wl_shm_format *wlr_renderer_get_formats(
|
const enum wl_shm_format *wlr_renderer_get_formats(
|
||||||
|
|
|
@ -363,7 +363,7 @@ static void render_decorations(struct roots_view *view,
|
||||||
pixman_region32_rectangles(&damage, &nrects);
|
pixman_region32_rectangles(&damage, &nrects);
|
||||||
for (int i = 0; i < nrects; ++i) {
|
for (int i = 0; i < nrects; ++i) {
|
||||||
scissor_output(output, &rects[i]);
|
scissor_output(output, &rects[i]);
|
||||||
wlr_render_colored_quad(renderer, color, matrix);
|
wlr_render_quad_with_matrix(renderer, color, matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
damage_finish:
|
damage_finish:
|
||||||
|
|
Loading…
Reference in New Issue