mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-29 16:05:59 +01:00
Add alpha to wlr_render_with_matrix
so we can use the alpha channel to e.g. blend in textures
This commit is contained in:
parent
e6ca78b0e4
commit
d08792bfff
11 changed files with 18 additions and 17 deletions
|
@ -647,7 +647,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
||||||
float matrix[16];
|
float matrix[16];
|
||||||
wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0);
|
wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0);
|
||||||
wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex,
|
wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex,
|
||||||
&matrix);
|
&matrix, 1.0f);
|
||||||
|
|
||||||
glFinish();
|
glFinish();
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);
|
||||||
|
|
|
@ -239,7 +239,7 @@ struct gbm_bo *wlr_drm_surface_mgpu_copy(struct wlr_drm_surface *dest,
|
||||||
glViewport(0, 0, dest->width, dest->height);
|
glViewport(0, 0, dest->width, dest->height);
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
wlr_render_with_matrix(dest->renderer->wlr_rend, tex, &matrix);
|
wlr_render_with_matrix(dest->renderer->wlr_rend, tex, &matrix, 1.0f);
|
||||||
|
|
||||||
return wlr_drm_surface_swap_buffers(dest, NULL);
|
return wlr_drm_surface_swap_buffers(dest, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ static void handle_output_frame(struct output_state *output,
|
||||||
wlr_texture_get_matrix(sample->cat_texture, &matrix,
|
wlr_texture_get_matrix(sample->cat_texture, &matrix,
|
||||||
&wlr_output->transform_matrix, local_x, local_y);
|
&wlr_output->transform_matrix, local_x, local_y);
|
||||||
wlr_render_with_matrix(sample->renderer,
|
wlr_render_with_matrix(sample->renderer,
|
||||||
sample->cat_texture, &matrix);
|
sample->cat_texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_renderer_end(sample->renderer);
|
wlr_renderer_end(sample->renderer);
|
||||||
|
|
|
@ -52,7 +52,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
wlr_texture_get_matrix(sample->cat_texture, &matrix,
|
wlr_texture_get_matrix(sample->cat_texture, &matrix,
|
||||||
&wlr_output->transform_matrix, x, y);
|
&wlr_output->transform_matrix, x, y);
|
||||||
wlr_render_with_matrix(sample->renderer,
|
wlr_render_with_matrix(sample->renderer,
|
||||||
sample->cat_texture, &matrix);
|
sample->cat_texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
(int)(p->x * width) - sample->cat_texture->width / 2,
|
(int)(p->x * width) - sample->cat_texture->width / 2,
|
||||||
(int)(p->y * height) - sample->cat_texture->height / 2);
|
(int)(p->y * height) - sample->cat_texture->height / 2);
|
||||||
wlr_render_with_matrix(sample->renderer,
|
wlr_render_with_matrix(sample->renderer,
|
||||||
sample->cat_texture, &matrix);
|
sample->cat_texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_renderer_end(sample->renderer);
|
wlr_renderer_end(sample->renderer);
|
||||||
|
|
|
@ -33,12 +33,13 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r);
|
||||||
* float projection[16];
|
* float projection[16];
|
||||||
* float matrix[16];
|
* float matrix[16];
|
||||||
* wlr_texture_get_matrix(texture, &matrix, &projection, 123, 321);
|
* wlr_texture_get_matrix(texture, &matrix, &projection, 123, 321);
|
||||||
* wlr_render_with_matrix(renderer, texture, &matrix);
|
* wlr_render_with_matrix(renderer, texture, &matrix, 0.5f);
|
||||||
*
|
*
|
||||||
* This will render the texture at <123, 321>.
|
* This will render the texture at <123, 321> with an alpha channel of 0.5.
|
||||||
*/
|
*/
|
||||||
bool wlr_render_with_matrix(struct wlr_renderer *r,
|
bool wlr_render_with_matrix(struct wlr_renderer *r,
|
||||||
struct wlr_texture *texture, const float (*matrix)[16]);
|
struct wlr_texture *texture, const float (*matrix)[16], float alpha);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a solid quad in the specified color.
|
* Renders a solid quad in the specified color.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,7 +22,7 @@ struct wlr_renderer_impl {
|
||||||
void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
|
void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box);
|
||||||
struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer);
|
struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer);
|
||||||
bool (*render_with_matrix)(struct wlr_renderer *renderer,
|
bool (*render_with_matrix)(struct wlr_renderer *renderer,
|
||||||
struct wlr_texture *texture, const float (*matrix)[16]);
|
struct wlr_texture *texture, const float (*matrix)[16], float alpha);
|
||||||
void (*render_quad)(struct wlr_renderer *renderer,
|
void (*render_quad)(struct wlr_renderer *renderer,
|
||||||
const float (*color)[4], const float (*matrix)[16]);
|
const float (*color)[4], const float (*matrix)[16]);
|
||||||
void (*render_ellipse)(struct wlr_renderer *renderer,
|
void (*render_ellipse)(struct wlr_renderer *renderer,
|
||||||
|
|
|
@ -171,7 +171,7 @@ static void draw_quad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
|
static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
|
||||||
struct wlr_texture *texture, const float (*matrix)[16]) {
|
struct wlr_texture *texture, const float (*matrix)[16], float alpha) {
|
||||||
if (!texture || !texture->valid) {
|
if (!texture || !texture->valid) {
|
||||||
wlr_log(L_ERROR, "attempt to render invalid texture");
|
wlr_log(L_ERROR, "attempt to render invalid texture");
|
||||||
return false;
|
return false;
|
||||||
|
@ -179,12 +179,12 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
|
||||||
|
|
||||||
wlr_texture_bind(texture);
|
wlr_texture_bind(texture);
|
||||||
GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
|
GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
|
||||||
// TODO: source alpha from somewhere else I guess
|
GL_CALL(glUniform1f(2, alpha));
|
||||||
GL_CALL(glUniform1f(2, 1.0f));
|
|
||||||
draw_quad();
|
draw_quad();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
|
static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
|
||||||
const float (*color)[4], const float (*matrix)[16]) {
|
const float (*color)[4], const float (*matrix)[16]) {
|
||||||
GL_CALL(glUseProgram(shaders.quad));
|
GL_CALL(glUseProgram(shaders.quad));
|
||||||
|
|
|
@ -36,8 +36,8 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wlr_render_with_matrix(struct wlr_renderer *r,
|
bool wlr_render_with_matrix(struct wlr_renderer *r,
|
||||||
struct wlr_texture *texture, const float (*matrix)[16]) {
|
struct wlr_texture *texture, const float (*matrix)[16], float alpha) {
|
||||||
return r->impl->render_with_matrix(r, texture, matrix);
|
return r->impl->render_with_matrix(r, texture, matrix, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_render_colored_quad(struct wlr_renderer *r,
|
void wlr_render_colored_quad(struct wlr_renderer *r,
|
||||||
|
|
|
@ -296,7 +296,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
|
||||||
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
|
pixman_box32_t *rects = 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_with_matrix(renderer, surface->texture, &matrix);
|
wlr_render_with_matrix(renderer, surface->texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
damage_finish:
|
damage_finish:
|
||||||
|
|
|
@ -391,7 +391,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output,
|
||||||
for (int i = 0; i < nrects; ++i) {
|
for (int i = 0; i < nrects; ++i) {
|
||||||
output_scissor(output, &rects[i]);
|
output_scissor(output, &rects[i]);
|
||||||
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
|
wlr_renderer_clear(renderer, &(float[]){0, 0, 0, 0});
|
||||||
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix);
|
wlr_render_with_matrix(surface->renderer, surface->texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
wlr_renderer_scissor(renderer, NULL);
|
wlr_renderer_scissor(renderer, NULL);
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
||||||
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
|
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
|
||||||
for (int i = 0; i < nrects; ++i) {
|
for (int i = 0; i < nrects; ++i) {
|
||||||
output_scissor(cursor->output, &rects[i]);
|
output_scissor(cursor->output, &rects[i]);
|
||||||
wlr_render_with_matrix(renderer, texture, &matrix);
|
wlr_render_with_matrix(renderer, texture, &matrix, 1.0f);
|
||||||
}
|
}
|
||||||
wlr_renderer_scissor(renderer, NULL);
|
wlr_renderer_scissor(renderer, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue