gl-renderer: add matrix
Add matrix in color.h Matrix is used as an optimized method for color mapping vs 3DLUT. Nothing sets color mapping to matrix yet. Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
This commit is contained in:
parent
96f0fc3974
commit
cd888bde6f
@ -106,6 +106,9 @@ enum weston_color_mapping_type {
|
||||
|
||||
/** 3D-dimensional look-up table */
|
||||
WESTON_COLOR_MAPPING_TYPE_3D_LUT,
|
||||
|
||||
/** matrix */
|
||||
WESTON_COLOR_MAPPING_TYPE_MATRIX,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -155,6 +158,13 @@ struct weston_color_mapping_3dlut {
|
||||
unsigned optimal_len;
|
||||
};
|
||||
|
||||
/**
|
||||
* A 3x3 matrix and data is arranged as column major
|
||||
*/
|
||||
struct weston_color_mapping_matrix {
|
||||
float matrix[9];
|
||||
};
|
||||
|
||||
/**
|
||||
* Color mapping function
|
||||
*
|
||||
@ -169,6 +179,7 @@ struct weston_color_mapping {
|
||||
union {
|
||||
/* identity: no parameters */
|
||||
struct weston_color_mapping_3dlut lut3d;
|
||||
struct weston_color_mapping_matrix mat;
|
||||
} u;
|
||||
};
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
/* enum gl_shader_color_mapping */
|
||||
#define SHADER_COLOR_MAPPING_IDENTITY 0
|
||||
#define SHADER_COLOR_MAPPING_3DLUT 1
|
||||
#define SHADER_COLOR_MAPPING_MATRIX 2
|
||||
|
||||
#if DEF_VARIANT == SHADER_VARIANT_EXTERNAL
|
||||
#extension GL_OES_EGL_image_external : require
|
||||
@ -132,6 +133,7 @@ uniform HIGHPRECISION vec2 color_post_curve_lut_scale_offset;
|
||||
uniform HIGHPRECISION sampler3D color_mapping_lut_3d;
|
||||
uniform HIGHPRECISION vec2 color_mapping_lut_scale_offset;
|
||||
#endif
|
||||
uniform HIGHPRECISION mat3 color_mapping_matrix;
|
||||
|
||||
vec4
|
||||
sample_input_texture()
|
||||
@ -246,6 +248,8 @@ color_mapping(vec3 color)
|
||||
return color;
|
||||
else if (c_color_mapping == SHADER_COLOR_MAPPING_3DLUT)
|
||||
return sample_color_mapping_lut_3d(color);
|
||||
else if (c_color_mapping == SHADER_COLOR_MAPPING_MATRIX)
|
||||
return color_mapping_matrix * color.rgb;
|
||||
else /* Never reached, bad c_color_mapping. */
|
||||
return vec3(1.0, 0.3, 1.0);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ enum gl_shader_color_curve {
|
||||
enum gl_shader_color_mapping {
|
||||
SHADER_COLOR_MAPPING_IDENTITY = 0,
|
||||
SHADER_COLOR_MAPPING_3DLUT,
|
||||
SHADER_COLOR_MAPPING_MATRIX,
|
||||
};
|
||||
|
||||
/** GL shader requirements key
|
||||
@ -79,13 +80,13 @@ struct gl_shader_requirements
|
||||
bool green_tint:1;
|
||||
|
||||
unsigned color_pre_curve:1; /* enum gl_shader_color_curve */
|
||||
unsigned color_mapping:1; /* enum gl_shader_color_mapping */
|
||||
unsigned color_mapping:2; /* enum gl_shader_color_mapping */
|
||||
unsigned color_post_curve:1; /* enum gl_shader_color_curve */
|
||||
/*
|
||||
* The total size of all bitfields plus pad_bits_ must fill up exactly
|
||||
* how many bytes the compiler allocates for them together.
|
||||
*/
|
||||
unsigned pad_bits_:23;
|
||||
unsigned pad_bits_:22;
|
||||
};
|
||||
static_assert(sizeof(struct gl_shader_requirements) ==
|
||||
4 /* total bitfield size in bytes */,
|
||||
@ -110,6 +111,7 @@ struct gl_shader_config {
|
||||
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];
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libweston/libweston.h>
|
||||
#include "color.h"
|
||||
@ -53,6 +54,7 @@ struct gl_renderer_color_mapping {
|
||||
float scale;
|
||||
float offset;
|
||||
} lut3d;
|
||||
struct weston_color_mapping_matrix mat;
|
||||
};
|
||||
} ;
|
||||
|
||||
@ -273,6 +275,11 @@ gl_renderer_color_transform_from(struct weston_color_transform *xform)
|
||||
case WESTON_COLOR_MAPPING_TYPE_3D_LUT:
|
||||
ok = gl_3d_lut(gl_xform, xform);
|
||||
break;
|
||||
case WESTON_COLOR_MAPPING_TYPE_MATRIX:
|
||||
gl_xform->mapping.type = SHADER_COLOR_MAPPING_MATRIX;
|
||||
gl_xform->mapping.mat = xform->mapping.u.mat;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
if (!ok) {
|
||||
gl_renderer_color_transform_destroy(gl_xform);
|
||||
@ -329,6 +336,11 @@ gl_shader_config_set_color_transform(struct gl_shader_config *sconf,
|
||||
assert(sconf->color_mapping.lut3d.scale_offset[1] > 0.0);
|
||||
ret = true;
|
||||
break;
|
||||
case SHADER_COLOR_MAPPING_MATRIX:
|
||||
assert(sconf->req.color_mapping == SHADER_COLOR_MAPPING_MATRIX);
|
||||
ARRAY_COPY(sconf->color_mapping.matrix, gl_xform->mapping.mat.matrix);
|
||||
ret = true;
|
||||
break;
|
||||
case SHADER_COLOR_MAPPING_IDENTITY:
|
||||
ret = true;
|
||||
break;
|
||||
|
@ -66,6 +66,7 @@ struct gl_shader {
|
||||
GLint tex_uniform;
|
||||
GLint scale_offset_uniform;
|
||||
} lut3d;
|
||||
GLint matrix_uniform;
|
||||
} color_mapping;
|
||||
GLint color_post_curve_lut_2d_uniform;
|
||||
GLint color_post_curve_lut_scale_offset_uniform;
|
||||
@ -113,6 +114,7 @@ gl_shader_color_mapping_to_string(enum gl_shader_color_mapping kind)
|
||||
#define CASERET(x) case x: return #x;
|
||||
CASERET(SHADER_COLOR_MAPPING_IDENTITY)
|
||||
CASERET(SHADER_COLOR_MAPPING_3DLUT)
|
||||
CASERET(SHADER_COLOR_MAPPING_MATRIX)
|
||||
#undef CASERET
|
||||
}
|
||||
|
||||
@ -304,9 +306,16 @@ gl_shader_create(struct gl_renderer *gr,
|
||||
switch(requirements->color_mapping) {
|
||||
case SHADER_COLOR_MAPPING_3DLUT:
|
||||
shader->color_mapping.lut3d.tex_uniform =
|
||||
glGetUniformLocation(shader->program, "color_mapping_lut_3d");
|
||||
glGetUniformLocation(shader->program,
|
||||
"color_mapping_lut_3d");
|
||||
shader->color_mapping.lut3d.scale_offset_uniform =
|
||||
glGetUniformLocation(shader->program,"color_mapping_lut_scale_offset");
|
||||
glGetUniformLocation(shader->program,
|
||||
"color_mapping_lut_scale_offset");
|
||||
break;
|
||||
case SHADER_COLOR_MAPPING_MATRIX:
|
||||
shader->color_mapping.matrix_uniform =
|
||||
glGetUniformLocation(shader->program,
|
||||
"color_mapping_matrix");
|
||||
break;
|
||||
case SHADER_COLOR_MAPPING_IDENTITY:
|
||||
break;
|
||||
@ -575,8 +584,11 @@ gl_shader_load_config(struct gl_shader *shader,
|
||||
glUniform2fv(shader->color_mapping.lut3d.scale_offset_uniform,
|
||||
1, sconf->color_mapping.lut3d.scale_offset);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
case SHADER_COLOR_MAPPING_MATRIX:
|
||||
assert(shader->color_mapping.matrix_uniform != -1);
|
||||
glUniformMatrix3fv(shader->color_mapping.matrix_uniform,
|
||||
1, GL_FALSE,
|
||||
sconf->color_mapping.matrix);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user