gl-renderer: move lut_3x1d curves to union
In the next commit we'll add support for more color curves. So move lut_3x1d to an union. Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
parent
aee3e313c6
commit
d9e2eca13f
@ -113,17 +113,28 @@ struct gl_shader_config {
|
||||
GLfloat unicolor[4];
|
||||
GLint input_tex_filter; /* GL_NEAREST or GL_LINEAR */
|
||||
GLuint input_tex[GL_SHADER_INPUT_TEX_MAX];
|
||||
GLuint color_pre_curve_lut_tex;
|
||||
GLfloat color_pre_curve_lut_scale_offset[2];
|
||||
|
||||
union {
|
||||
struct {
|
||||
GLuint tex;
|
||||
GLuint tex;
|
||||
GLfloat scale_offset[2];
|
||||
} lut_3x1d;
|
||||
} color_pre_curve;
|
||||
|
||||
union {
|
||||
struct {
|
||||
GLuint tex;
|
||||
GLfloat scale_offset[2];
|
||||
} lut3d;
|
||||
GLfloat matrix[9];
|
||||
} color_mapping;
|
||||
GLuint color_post_curve_lut_tex;
|
||||
GLfloat color_post_curve_lut_scale_offset[2];
|
||||
|
||||
union {
|
||||
struct {
|
||||
GLuint tex;
|
||||
GLfloat scale_offset[2];
|
||||
} lut_3x1d;
|
||||
} color_post_curve;
|
||||
};
|
||||
|
||||
struct gl_renderer {
|
||||
|
@ -41,9 +41,13 @@
|
||||
|
||||
struct gl_renderer_color_curve {
|
||||
enum gl_shader_color_curve type;
|
||||
GLuint tex;
|
||||
float scale;
|
||||
float offset;
|
||||
union {
|
||||
struct {
|
||||
GLuint tex;
|
||||
float scale;
|
||||
float offset;
|
||||
} lut_3x1d;
|
||||
} u;
|
||||
};
|
||||
|
||||
struct gl_renderer_color_mapping {
|
||||
@ -69,8 +73,13 @@ struct gl_renderer_color_transform {
|
||||
static void
|
||||
gl_renderer_color_curve_fini(struct gl_renderer_color_curve *gl_curve)
|
||||
{
|
||||
if (gl_curve->tex)
|
||||
glDeleteTextures(1, &gl_curve->tex);
|
||||
switch (gl_curve->type) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
glDeleteTextures(1, &gl_curve->u.lut_3x1d.tex);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
@ -173,9 +182,9 @@ gl_color_curve_lut_3x1d(struct gl_renderer *gr,
|
||||
free(lut);
|
||||
|
||||
gl_curve->type = SHADER_COLOR_CURVE_LUT_3x1D;
|
||||
gl_curve->tex = tex;
|
||||
gl_curve->scale = (float)(lut_len - 1) / lut_len;
|
||||
gl_curve->offset = 0.5f / lut_len;
|
||||
gl_curve->u.lut_3x1d.tex = tex;
|
||||
gl_curve->u.lut_3x1d.scale = (float)(lut_len - 1) / lut_len;
|
||||
gl_curve->u.lut_3x1d.offset = 0.5f / lut_len;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -228,14 +237,8 @@ gl_renderer_color_transform_from(struct gl_renderer *gr,
|
||||
{
|
||||
static const struct gl_renderer_color_transform no_op_gl_xform = {
|
||||
.pre_curve.type = SHADER_COLOR_CURVE_IDENTITY,
|
||||
.pre_curve.tex = 0,
|
||||
.pre_curve.scale = 0.0f,
|
||||
.pre_curve.offset = 0.0f,
|
||||
.mapping.type = SHADER_COLOR_MAPPING_IDENTITY,
|
||||
.post_curve.type = SHADER_COLOR_CURVE_IDENTITY,
|
||||
.post_curve.tex = 0,
|
||||
.post_curve.scale = 0.0f,
|
||||
.post_curve.offset = 0.0f,
|
||||
};
|
||||
struct gl_renderer_color_transform *gl_xform;
|
||||
bool ok = false;
|
||||
@ -265,11 +268,11 @@ gl_renderer_color_transform_from(struct gl_renderer *gr,
|
||||
&xform->pre_curve, xform);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
gl_renderer_color_transform_destroy(gl_xform);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (xform->mapping.type) {
|
||||
case WESTON_COLOR_MAPPING_TYPE_IDENTITY:
|
||||
gl_xform->mapping = no_op_gl_xform.mapping;
|
||||
@ -288,6 +291,7 @@ gl_renderer_color_transform_from(struct gl_renderer *gr,
|
||||
gl_renderer_color_transform_destroy(gl_xform);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (xform->post_curve.type) {
|
||||
case WESTON_COLOR_CURVE_TYPE_IDENTITY:
|
||||
gl_xform->post_curve = no_op_gl_xform.post_curve;
|
||||
@ -319,14 +323,26 @@ gl_shader_config_set_color_transform(struct gl_renderer *gr,
|
||||
return false;
|
||||
|
||||
sconf->req.color_pre_curve = gl_xform->pre_curve.type;
|
||||
sconf->color_pre_curve_lut_tex = gl_xform->pre_curve.tex;
|
||||
sconf->color_pre_curve_lut_scale_offset[0] = gl_xform->pre_curve.scale;
|
||||
sconf->color_pre_curve_lut_scale_offset[1] = gl_xform->pre_curve.offset;
|
||||
switch (gl_xform->pre_curve.type) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
sconf->color_pre_curve.lut_3x1d.tex = gl_xform->pre_curve.u.lut_3x1d.tex;
|
||||
sconf->color_pre_curve.lut_3x1d.scale_offset[0] = gl_xform->pre_curve.u.lut_3x1d.scale;
|
||||
sconf->color_pre_curve.lut_3x1d.scale_offset[1] = gl_xform->pre_curve.u.lut_3x1d.offset;
|
||||
break;
|
||||
}
|
||||
|
||||
sconf->req.color_post_curve = gl_xform->post_curve.type;
|
||||
sconf->color_post_curve_lut_tex = gl_xform->post_curve.tex;
|
||||
sconf->color_post_curve_lut_scale_offset[0] = gl_xform->post_curve.scale;
|
||||
sconf->color_post_curve_lut_scale_offset[1] = gl_xform->post_curve.offset;
|
||||
switch (gl_xform->post_curve.type) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
sconf->color_post_curve.lut_3x1d.tex = gl_xform->post_curve.u.lut_3x1d.tex;
|
||||
sconf->color_post_curve.lut_3x1d.scale_offset[0] = gl_xform->post_curve.u.lut_3x1d.scale;
|
||||
sconf->color_post_curve.lut_3x1d.scale_offset[1] = gl_xform->post_curve.u.lut_3x1d.offset;
|
||||
break;
|
||||
}
|
||||
|
||||
sconf->req.color_mapping = gl_xform->mapping.type;
|
||||
switch (gl_xform->mapping.type) {
|
||||
|
@ -52,6 +52,8 @@
|
||||
#include "fragment-shader.h"
|
||||
|
||||
struct gl_shader {
|
||||
struct wl_list link; /* gl_renderer::shader_list */
|
||||
struct timespec last_used;
|
||||
struct gl_shader_requirements key;
|
||||
GLuint program;
|
||||
GLuint vertex_shader, fragment_shader;
|
||||
@ -60,8 +62,12 @@ struct gl_shader {
|
||||
GLint tex_uniforms[3];
|
||||
GLint view_alpha_uniform;
|
||||
GLint color_uniform;
|
||||
GLint color_pre_curve_lut_2d_uniform;
|
||||
GLint color_pre_curve_lut_scale_offset_uniform;
|
||||
union {
|
||||
struct {
|
||||
GLint tex_2d_uniform;
|
||||
GLint scale_offset_uniform;
|
||||
} lut_3x1d;
|
||||
} color_pre_curve;
|
||||
union {
|
||||
struct {
|
||||
GLint tex_uniform;
|
||||
@ -69,10 +75,12 @@ struct gl_shader {
|
||||
} lut3d;
|
||||
GLint matrix_uniform;
|
||||
} color_mapping;
|
||||
GLint color_post_curve_lut_2d_uniform;
|
||||
GLint color_post_curve_lut_scale_offset_uniform;
|
||||
struct wl_list link; /* gl_renderer::shader_list */
|
||||
struct timespec last_used;
|
||||
union {
|
||||
struct {
|
||||
GLint tex_2d_uniform;
|
||||
GLint scale_offset_uniform;
|
||||
} lut_3x1d;
|
||||
} color_post_curve;
|
||||
};
|
||||
|
||||
static const char *
|
||||
@ -336,15 +344,28 @@ gl_shader_create(struct gl_renderer *gr,
|
||||
} else {
|
||||
shader->color_uniform = -1;
|
||||
}
|
||||
shader->color_pre_curve_lut_2d_uniform =
|
||||
glGetUniformLocation(shader->program, "color_pre_curve_lut_2d");
|
||||
shader->color_pre_curve_lut_scale_offset_uniform =
|
||||
glGetUniformLocation(shader->program, "color_pre_curve_lut_scale_offset");
|
||||
|
||||
shader->color_post_curve_lut_2d_uniform =
|
||||
glGetUniformLocation(shader->program, "color_post_curve_lut_2d");
|
||||
shader->color_post_curve_lut_scale_offset_uniform =
|
||||
glGetUniformLocation(shader->program, "color_post_curve_lut_scale_offset");
|
||||
switch(requirements->color_pre_curve) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
shader->color_pre_curve.lut_3x1d.tex_2d_uniform =
|
||||
glGetUniformLocation(shader->program, "color_pre_curve_lut_2d");
|
||||
shader->color_pre_curve.lut_3x1d.scale_offset_uniform =
|
||||
glGetUniformLocation(shader->program, "color_pre_curve_lut_scale_offset");
|
||||
break;
|
||||
}
|
||||
|
||||
switch(requirements->color_post_curve) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
shader->color_post_curve.lut_3x1d.tex_2d_uniform =
|
||||
glGetUniformLocation(shader->program, "color_post_curve_lut_2d");
|
||||
shader->color_post_curve.lut_3x1d.scale_offset_uniform =
|
||||
glGetUniformLocation(shader->program, "color_post_curve_lut_scale_offset");
|
||||
break;
|
||||
}
|
||||
|
||||
switch(requirements->color_mapping) {
|
||||
case SHADER_COLOR_MAPPING_3DLUT:
|
||||
@ -606,18 +627,17 @@ gl_shader_load_config(struct gl_shader *shader,
|
||||
i = GL_SHADER_INPUT_TEX_MAX;
|
||||
switch (sconf->req.color_pre_curve) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
assert(sconf->color_pre_curve_lut_tex == 0);
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
assert(sconf->color_pre_curve_lut_tex != 0);
|
||||
assert(shader->color_pre_curve_lut_2d_uniform != -1);
|
||||
assert(shader->color_pre_curve_lut_scale_offset_uniform != -1);
|
||||
assert(sconf->color_pre_curve.lut_3x1d.tex != 0);
|
||||
assert(shader->color_pre_curve.lut_3x1d.tex_2d_uniform != -1);
|
||||
assert(shader->color_pre_curve.lut_3x1d.scale_offset_uniform != -1);
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, sconf->color_pre_curve_lut_tex);
|
||||
glUniform1i(shader->color_pre_curve_lut_2d_uniform, i);
|
||||
glBindTexture(GL_TEXTURE_2D, sconf->color_pre_curve.lut_3x1d.tex);
|
||||
glUniform1i(shader->color_pre_curve.lut_3x1d.tex_2d_uniform, i);
|
||||
i++;
|
||||
glUniform2fv(shader->color_pre_curve_lut_scale_offset_uniform,
|
||||
1, sconf->color_pre_curve_lut_scale_offset);
|
||||
glUniform2fv(shader->color_pre_curve.lut_3x1d.scale_offset_uniform,
|
||||
1, sconf->color_pre_curve.lut_3x1d.scale_offset);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -645,18 +665,17 @@ gl_shader_load_config(struct gl_shader *shader,
|
||||
|
||||
switch (sconf->req.color_post_curve) {
|
||||
case SHADER_COLOR_CURVE_IDENTITY:
|
||||
assert(sconf->color_post_curve_lut_tex == 0);
|
||||
break;
|
||||
case SHADER_COLOR_CURVE_LUT_3x1D:
|
||||
assert(sconf->color_post_curve_lut_tex != 0);
|
||||
assert(shader->color_post_curve_lut_2d_uniform != -1);
|
||||
assert(shader->color_post_curve_lut_scale_offset_uniform != -1);
|
||||
assert(sconf->color_post_curve.lut_3x1d.tex != 0);
|
||||
assert(shader->color_post_curve.lut_3x1d.tex_2d_uniform != -1);
|
||||
assert(shader->color_post_curve.lut_3x1d.scale_offset_uniform != -1);
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, sconf->color_post_curve_lut_tex);
|
||||
glUniform1i(shader->color_post_curve_lut_2d_uniform, i);
|
||||
glBindTexture(GL_TEXTURE_2D, sconf->color_post_curve.lut_3x1d.tex);
|
||||
glUniform1i(shader->color_post_curve.lut_3x1d.tex_2d_uniform, i);
|
||||
i++;
|
||||
glUniform2fv(shader->color_post_curve_lut_scale_offset_uniform,
|
||||
1, sconf->color_post_curve_lut_scale_offset);
|
||||
glUniform2fv(shader->color_post_curve.lut_3x1d.scale_offset_uniform,
|
||||
1, sconf->color_post_curve.lut_3x1d.scale_offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user