mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-05-07 18:58:00 +02:00
render: gles2: Add colour conversion matrix to shaders
This allows mapping to YCbCr without modifying the shader itself. Signed-off-by: Andri Yngvason <andri@yngvason.is>
This commit is contained in:
parent
e8c03e9ce9
commit
1924113a5a
7 changed files with 31 additions and 10 deletions
|
|
@ -28,12 +28,21 @@ struct wlr_gles2_pixel_format {
|
|||
GLint gl_format, gl_type;
|
||||
};
|
||||
|
||||
struct wlr_gles2_quad_shader {
|
||||
GLuint program;
|
||||
GLint proj;
|
||||
GLint color;
|
||||
GLint color_matrix;
|
||||
GLint pos_attrib;
|
||||
};
|
||||
|
||||
struct wlr_gles2_tex_shader {
|
||||
GLuint program;
|
||||
GLint proj;
|
||||
GLint tex_proj;
|
||||
GLint tex;
|
||||
GLint alpha;
|
||||
GLint color_matrix;
|
||||
GLint pos_attrib;
|
||||
};
|
||||
|
||||
|
|
@ -74,12 +83,7 @@ struct wlr_gles2_renderer {
|
|||
} procs;
|
||||
|
||||
struct {
|
||||
struct {
|
||||
GLuint program;
|
||||
GLint proj;
|
||||
GLint color;
|
||||
GLint pos_attrib;
|
||||
} quad;
|
||||
struct wlr_gles2_quad_shader quad;
|
||||
struct wlr_gles2_tex_shader tex_rgba;
|
||||
struct wlr_gles2_tex_shader tex_rgbx;
|
||||
struct wlr_gles2_tex_shader tex_ext;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,13 @@
|
|||
|
||||
#define MAX_QUADS 86 // 4kb
|
||||
|
||||
static const GLfloat color_matrix_identity[16] = {
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
};
|
||||
|
||||
static const struct wlr_render_pass_impl render_pass_impl;
|
||||
|
||||
static struct wlr_gles2_render_pass *get_render_pass(struct wlr_render_pass *wlr_pass) {
|
||||
|
|
@ -227,6 +234,7 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
|
|||
WLR_RENDER_BLEND_MODE_NONE : options->blend_mode);
|
||||
|
||||
glUseProgram(shader->program);
|
||||
glUniformMatrix4fv(shader->color_matrix, 1, GL_FALSE, color_matrix_identity);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(texture->target, texture->tex);
|
||||
|
|
@ -276,6 +284,7 @@ static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,
|
|||
} else {
|
||||
setup_blending(blend_mode);
|
||||
glUseProgram(renderer->shaders.quad.program);
|
||||
glUniformMatrix4fv(renderer->shaders.quad.color_matrix, 1, GL_FALSE, color_matrix_identity);
|
||||
set_proj_matrix(renderer->shaders.quad.proj, pass->projection_matrix, &box);
|
||||
glUniform4f(renderer->shaders.quad.color, color->r, color->g, color->b, color->a);
|
||||
render(&box, options->clip, renderer->shaders.quad.pos_attrib);
|
||||
|
|
|
|||
|
|
@ -640,6 +640,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
}
|
||||
renderer->shaders.quad.proj = glGetUniformLocation(prog, "proj");
|
||||
renderer->shaders.quad.color = glGetUniformLocation(prog, "color");
|
||||
renderer->shaders.quad.color_matrix = glGetUniformLocation(prog, "color_matrix");
|
||||
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||
|
||||
renderer->shaders.tex_rgba.program = prog =
|
||||
|
|
@ -651,6 +652,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.tex_rgba.tex_proj = glGetUniformLocation(prog, "tex_proj");
|
||||
renderer->shaders.tex_rgba.tex = glGetUniformLocation(prog, "tex");
|
||||
renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha");
|
||||
renderer->shaders.tex_rgba.color_matrix = glGetUniformLocation(prog, "color_matrix");
|
||||
renderer->shaders.tex_rgba.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||
|
||||
renderer->shaders.tex_rgbx.program = prog =
|
||||
|
|
@ -662,6 +664,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.tex_rgbx.tex_proj = glGetUniformLocation(prog, "tex_proj");
|
||||
renderer->shaders.tex_rgbx.tex = glGetUniformLocation(prog, "tex");
|
||||
renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha");
|
||||
renderer->shaders.tex_rgbx.color_matrix = glGetUniformLocation(prog, "color_matrix");
|
||||
renderer->shaders.tex_rgbx.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||
|
||||
if (renderer->exts.OES_egl_image_external) {
|
||||
|
|
@ -674,6 +677,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||
renderer->shaders.tex_ext.tex_proj = glGetUniformLocation(prog, "tex_proj");
|
||||
renderer->shaders.tex_ext.tex = glGetUniformLocation(prog, "tex");
|
||||
renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha");
|
||||
renderer->shaders.tex_ext.color_matrix = glGetUniformLocation(prog, "color_matrix");
|
||||
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ precision mediump float;
|
|||
varying vec4 v_color;
|
||||
varying vec2 v_texcoord;
|
||||
uniform vec4 color;
|
||||
uniform mat4 color_matrix;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = color;
|
||||
gl_FragColor = color * color_matrix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ precision mediump float;
|
|||
varying vec2 v_texcoord;
|
||||
uniform samplerExternalOES texture0;
|
||||
uniform float alpha;
|
||||
uniform mat4 color_matrix;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(texture0, v_texcoord) * alpha;
|
||||
gl_FragColor = texture2D(texture0, v_texcoord) * alpha * color_matrix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ precision mediump float;
|
|||
varying vec2 v_texcoord;
|
||||
uniform sampler2D tex;
|
||||
uniform float alpha;
|
||||
uniform mat4 color_matrix;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(tex, v_texcoord) * alpha;
|
||||
gl_FragColor = texture2D(tex, v_texcoord) * alpha * color_matrix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ precision mediump float;
|
|||
varying vec2 v_texcoord;
|
||||
uniform sampler2D tex;
|
||||
uniform float alpha;
|
||||
uniform mat4 color_matrix;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0) * alpha;
|
||||
gl_FragColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0) * alpha * color_matrix;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue