mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-18 06:47:31 -04:00
Merge branch 'color-management' into 'master'
Draft: Add support for ICC profiles for outputs See merge request wlroots/wlroots!3804
This commit is contained in:
commit
dadcf64584
15 changed files with 320 additions and 83 deletions
|
|
@ -3,6 +3,7 @@ packages:
|
||||||
- eudev-dev
|
- eudev-dev
|
||||||
- ffmpeg-dev
|
- ffmpeg-dev
|
||||||
- glslang
|
- glslang
|
||||||
|
- lcms2-dev
|
||||||
- libinput-dev
|
- libinput-dev
|
||||||
- libxkbcommon-dev
|
- libxkbcommon-dev
|
||||||
- mesa-dev
|
- mesa-dev
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ image: archlinux
|
||||||
packages:
|
packages:
|
||||||
- clang
|
- clang
|
||||||
- ffmpeg
|
- ffmpeg
|
||||||
|
- lcms2
|
||||||
- libinput
|
- libinput
|
||||||
- libxkbcommon
|
- libxkbcommon
|
||||||
- mesa
|
- mesa
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ packages:
|
||||||
- devel/meson # implies ninja
|
- devel/meson # implies ninja
|
||||||
- devel/pkgconf
|
- devel/pkgconf
|
||||||
- graphics/glslang
|
- graphics/glslang
|
||||||
|
- graphics/lcms2
|
||||||
- graphics/libdrm
|
- graphics/libdrm
|
||||||
- graphics/mesa-libs
|
- graphics/mesa-libs
|
||||||
- graphics/png
|
- graphics/png
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,13 @@ struct wlr_gles2_pixel_format {
|
||||||
bool has_alpha;
|
bool has_alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct wlr_gles2_quad_shader {
|
||||||
|
GLuint program;
|
||||||
|
GLint proj;
|
||||||
|
GLint color;
|
||||||
|
GLint pos_attrib;
|
||||||
|
};
|
||||||
|
|
||||||
struct wlr_gles2_tex_shader {
|
struct wlr_gles2_tex_shader {
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLint proj;
|
GLint proj;
|
||||||
|
|
@ -57,15 +64,11 @@ struct wlr_gles2_renderer {
|
||||||
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
|
PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR;
|
||||||
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
|
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES;
|
||||||
PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR;
|
PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR;
|
||||||
|
PFNGLTEXIMAGE3DOESPROC glTexImage3DOES;
|
||||||
} procs;
|
} procs;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct {
|
struct wlr_gles2_quad_shader quad;
|
||||||
GLuint program;
|
|
||||||
GLint proj;
|
|
||||||
GLint color;
|
|
||||||
GLint pos_attrib;
|
|
||||||
} quad;
|
|
||||||
struct wlr_gles2_tex_shader tex_rgba;
|
struct wlr_gles2_tex_shader tex_rgba;
|
||||||
struct wlr_gles2_tex_shader tex_rgbx;
|
struct wlr_gles2_tex_shader tex_rgbx;
|
||||||
struct wlr_gles2_tex_shader tex_ext;
|
struct wlr_gles2_tex_shader tex_ext;
|
||||||
|
|
@ -112,6 +115,22 @@ struct wlr_gles2_texture {
|
||||||
struct wlr_addon buffer_addon;
|
struct wlr_addon buffer_addon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum wlr_gles2_shader_source {
|
||||||
|
WLR_GLES2_SHADER_SOURCE_SINGLE_COLOR = 1,
|
||||||
|
WLR_GLES2_SHADER_SOURCE_TEXTURE_RGBA = 2,
|
||||||
|
WLR_GLES2_SHADER_SOURCE_TEXTURE_RGBX = 3,
|
||||||
|
WLR_GLES2_SHADER_SOURCE_TEXTURE_EXTERNAL = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum wlr_gles2_shader_color_transform {
|
||||||
|
WLR_GLES2_SHADER_COLOR_TRANSFORM_IDENTITY = 0,
|
||||||
|
WLR_GLES2_SHADER_COLOR_TRANSFORM_LUT_3D = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_gles2_shader_params {
|
||||||
|
enum wlr_gles2_shader_source source;
|
||||||
|
enum wlr_gles2_shader_color_transform color_transform;
|
||||||
|
};
|
||||||
|
|
||||||
bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
|
bool is_gles2_pixel_format_supported(const struct wlr_gles2_renderer *renderer,
|
||||||
const struct wlr_gles2_pixel_format *format);
|
const struct wlr_gles2_pixel_format *format);
|
||||||
|
|
|
||||||
44
include/wlr/render/color.h
Normal file
44
include/wlr/render/color.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* This an unstable interface of wlroots. No guarantees are made regarding the
|
||||||
|
* future consistency of this API.
|
||||||
|
*/
|
||||||
|
#ifndef WLR_USE_UNSTABLE
|
||||||
|
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WLR_RENDER_COLOR_H
|
||||||
|
#define WLR_RENDER_COLOR_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A color transformation formula.
|
||||||
|
*
|
||||||
|
* The formula is approximated via a 3D look-up table. A 3D LUT is a
|
||||||
|
* three-dimensional array where each element is an RGB triplet. The flat lut_3d
|
||||||
|
* array has a length of dim_len³.
|
||||||
|
*
|
||||||
|
* Color channel values in the range [0.0, 1.0] are mapped linearly to
|
||||||
|
* 3D LUT indices such that 0.0 maps exactly to the first element and 1.0 maps
|
||||||
|
* exactly to the last element in each dimension.
|
||||||
|
*
|
||||||
|
* The offset of the RGB triplet given red, green and blue indices r_index,
|
||||||
|
* g_index and b_index is:
|
||||||
|
*
|
||||||
|
* offset = 3 * (r_index + dim_len * g_index + dim_len * dim_len * b_index)
|
||||||
|
*/
|
||||||
|
struct wlr_color_transform {
|
||||||
|
float *lut_3d;
|
||||||
|
size_t dim_len;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a color transformation to convert sRGB to an ICC profile.
|
||||||
|
*/
|
||||||
|
bool wlr_color_transform_init_srgb_to_icc(struct wlr_color_transform *tr,
|
||||||
|
const void *data, size_t size);
|
||||||
|
|
||||||
|
void wlr_color_transform_finish(struct wlr_color_transform *tr);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -7,3 +7,4 @@ option('backends', type: 'array', choices: ['auto', 'drm', 'libinput', 'x11'], v
|
||||||
option('allocators', type: 'array', choices: ['auto', 'gbm'], value: ['auto'],
|
option('allocators', type: 'array', choices: ['auto', 'gbm'], value: ['auto'],
|
||||||
description: 'Select built-in allocators')
|
description: 'Select built-in allocators')
|
||||||
option('session', type: 'feature', value: 'auto', description: 'Enable session support')
|
option('session', type: 'feature', value: 'auto', description: 'Enable session support')
|
||||||
|
option('color-management', type: 'feature', value: 'auto', description: 'Enable support for color management')
|
||||||
|
|
|
||||||
94
render/color.c
Normal file
94
render/color.c
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#include <lcms2.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wlr/render/color.h>
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
static void handle_lcms_error(cmsContext ctx, cmsUInt32Number code, const char *text) {
|
||||||
|
wlr_log(WLR_ERROR, "[lcms] %s", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wlr_color_transform_init_srgb_to_icc(struct wlr_color_transform *tr,
|
||||||
|
const void *data, size_t size) {
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
cmsContext ctx = cmsCreateContext(NULL, NULL);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
wlr_log(WLR_ERROR, "cmsCreateContext failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmsSetLogErrorHandlerTHR(ctx, handle_lcms_error);
|
||||||
|
|
||||||
|
cmsHPROFILE icc_profile = cmsOpenProfileFromMemTHR(ctx, data, size);
|
||||||
|
if (icc_profile == NULL) {
|
||||||
|
wlr_log(WLR_ERROR, "cmsOpenProfileFromMemTHR failed");
|
||||||
|
goto out_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmsGetDeviceClass(icc_profile) != cmsSigDisplayClass) {
|
||||||
|
wlr_log(WLR_ERROR, "ICC profile must have the Display device class");
|
||||||
|
goto out_icc_profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmsHPROFILE srgb_profile = cmsCreate_sRGBProfile();
|
||||||
|
if (srgb_profile == NULL) {
|
||||||
|
wlr_log(WLR_ERROR, "cmsCreate_sRGBProfile failed");
|
||||||
|
goto out_icc_profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmsHTRANSFORM lcms_tr = cmsCreateTransformTHR(ctx,
|
||||||
|
srgb_profile, TYPE_RGB_FLT, icc_profile, TYPE_RGB_FLT,
|
||||||
|
INTENT_RELATIVE_COLORIMETRIC, 0);
|
||||||
|
if (lcms_tr == NULL) {
|
||||||
|
wlr_log(WLR_ERROR, "cmsCreateTransformTHR failed");
|
||||||
|
goto out_srgb_profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t dim_len = 33;
|
||||||
|
float *lut_3d = calloc(3 * dim_len * dim_len * dim_len, sizeof(float));
|
||||||
|
if (lut_3d == NULL) {
|
||||||
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
||||||
|
goto out_lcms_tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
float factor = 1.0f / (dim_len - 1);
|
||||||
|
for (size_t b_index = 0; b_index < dim_len; b_index++) {
|
||||||
|
for (size_t g_index = 0; g_index < dim_len; g_index++) {
|
||||||
|
for (size_t r_index = 0; r_index < dim_len; r_index++) {
|
||||||
|
float rgb_in[3] = {
|
||||||
|
r_index * factor,
|
||||||
|
g_index * factor,
|
||||||
|
b_index * factor,
|
||||||
|
};
|
||||||
|
float rgb_out[3];
|
||||||
|
cmsDoTransform(lcms_tr, rgb_in, rgb_out, 1);
|
||||||
|
|
||||||
|
size_t offset = 3 * (r_index + dim_len * g_index + dim_len * dim_len * b_index);
|
||||||
|
// TODO: maybe clamp values to [0.0, 1.0] here?
|
||||||
|
lut_3d[offset] = rgb_out[0];
|
||||||
|
lut_3d[offset + 1] = rgb_out[1];
|
||||||
|
lut_3d[offset + 2] = rgb_out[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
*tr = (struct wlr_color_transform){
|
||||||
|
.lut_3d = lut_3d,
|
||||||
|
.dim_len = dim_len,
|
||||||
|
};
|
||||||
|
|
||||||
|
out_lcms_tr:
|
||||||
|
cmsDeleteTransform(lcms_tr);
|
||||||
|
out_srgb_profile:
|
||||||
|
cmsCloseProfile(srgb_profile);
|
||||||
|
out_icc_profile:
|
||||||
|
cmsCloseProfile(icc_profile);
|
||||||
|
out_ctx:
|
||||||
|
cmsDeleteContext(ctx);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_color_transform_finish(struct wlr_color_transform *tr) {
|
||||||
|
free(tr->lut_3d);
|
||||||
|
}
|
||||||
|
|
@ -20,10 +20,7 @@
|
||||||
#include "types/wlr_matrix.h"
|
#include "types/wlr_matrix.h"
|
||||||
|
|
||||||
#include "common_vert_src.h"
|
#include "common_vert_src.h"
|
||||||
#include "quad_frag_src.h"
|
#include "common_frag_src.h"
|
||||||
#include "tex_rgba_frag_src.h"
|
|
||||||
#include "tex_rgbx_frag_src.h"
|
|
||||||
#include "tex_external_frag_src.h"
|
|
||||||
|
|
||||||
static const GLfloat verts[] = {
|
static const GLfloat verts[] = {
|
||||||
1, 0, // top right
|
1, 0, // top right
|
||||||
|
|
@ -610,11 +607,11 @@ static void gles2_log(GLenum src, GLenum type, GLuint id, GLenum severity,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint compile_shader(struct wlr_gles2_renderer *renderer,
|
static GLuint compile_shader(struct wlr_gles2_renderer *renderer,
|
||||||
GLuint type, const GLchar *src) {
|
GLuint type, const GLchar **srcs, size_t srcs_len) {
|
||||||
push_gles2_debug(renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
GLuint shader = glCreateShader(type);
|
GLuint shader = glCreateShader(type);
|
||||||
glShaderSource(shader, 1, &src, NULL);
|
glShaderSource(shader, srcs_len, srcs, NULL);
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
|
|
||||||
GLint ok;
|
GLint ok;
|
||||||
|
|
@ -630,15 +627,24 @@ static GLuint compile_shader(struct wlr_gles2_renderer *renderer,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLuint link_program(struct wlr_gles2_renderer *renderer,
|
static GLuint link_program(struct wlr_gles2_renderer *renderer,
|
||||||
const GLchar *vert_src, const GLchar *frag_src) {
|
const struct wlr_gles2_shader_params *params) {
|
||||||
|
static char frag_preamble[1024];
|
||||||
|
snprintf(frag_preamble, sizeof(frag_preamble),
|
||||||
|
"#define SOURCE %d\n"
|
||||||
|
"#define COLOR_TRANSFORM %d\n",
|
||||||
|
params->source, params->color_transform);
|
||||||
|
|
||||||
push_gles2_debug(renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
GLuint vert = compile_shader(renderer, GL_VERTEX_SHADER, vert_src);
|
const GLchar *vert_src = common_vert_src;
|
||||||
|
GLuint vert = compile_shader(renderer, GL_VERTEX_SHADER, &vert_src, 1);
|
||||||
if (!vert) {
|
if (!vert) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint frag = compile_shader(renderer, GL_FRAGMENT_SHADER, frag_src);
|
const GLchar *frag_srcs[2] = { frag_preamble, common_frag_src };
|
||||||
|
GLuint frag =
|
||||||
|
compile_shader(renderer, GL_FRAGMENT_SHADER, frag_srcs, 2);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
glDeleteShader(vert);
|
glDeleteShader(vert);
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -670,6 +676,23 @@ error:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool link_tex_program(struct wlr_gles2_renderer *renderer,
|
||||||
|
struct wlr_gles2_tex_shader *shader,
|
||||||
|
const struct wlr_gles2_shader_params *params) {
|
||||||
|
shader->program = link_program(renderer, params);
|
||||||
|
if (!shader->program) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader->proj = glGetUniformLocation(shader->program, "proj");
|
||||||
|
shader->tex = glGetUniformLocation(shader->program, "tex");
|
||||||
|
shader->alpha = glGetUniformLocation(shader->program, "alpha");
|
||||||
|
shader->pos_attrib = glGetAttribLocation(shader->program, "pos");
|
||||||
|
shader->tex_attrib = glGetAttribLocation(shader->program, "texcoord");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool check_gl_ext(const char *exts, const char *ext) {
|
static bool check_gl_ext(const char *exts, const char *ext) {
|
||||||
size_t extlen = strlen(ext);
|
size_t extlen = strlen(ext);
|
||||||
const char *end = exts + strlen(exts);
|
const char *end = exts + strlen(exts);
|
||||||
|
|
@ -808,6 +831,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (check_gl_ext(exts_str, "GL_OES_texture_3D")) {
|
||||||
|
load_gl_proc(&renderer->procs.glTexImage3DOES, "glTexImage3DOES");
|
||||||
|
}
|
||||||
|
|
||||||
if (renderer->exts.KHR_debug) {
|
if (renderer->exts.KHR_debug) {
|
||||||
glEnable(GL_DEBUG_OUTPUT_KHR);
|
glEnable(GL_DEBUG_OUTPUT_KHR);
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
|
||||||
|
|
@ -822,9 +849,18 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
||||||
|
|
||||||
push_gles2_debug(renderer);
|
push_gles2_debug(renderer);
|
||||||
|
|
||||||
|
enum wlr_gles2_shader_color_transform color_transform =
|
||||||
|
WLR_GLES2_SHADER_COLOR_TRANSFORM_IDENTITY;
|
||||||
|
if (renderer->procs.glTexImage3DOES != NULL) {
|
||||||
|
color_transform = WLR_GLES2_SHADER_COLOR_TRANSFORM_LUT_3D;
|
||||||
|
}
|
||||||
|
|
||||||
GLuint prog;
|
GLuint prog;
|
||||||
renderer->shaders.quad.program = prog =
|
renderer->shaders.quad.program = prog =
|
||||||
link_program(renderer, common_vert_src, quad_frag_src);
|
link_program(renderer, &(struct wlr_gles2_shader_params){
|
||||||
|
.source = WLR_GLES2_SHADER_SOURCE_SINGLE_COLOR,
|
||||||
|
.color_transform = color_transform,
|
||||||
|
});
|
||||||
if (!renderer->shaders.quad.program) {
|
if (!renderer->shaders.quad.program) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
@ -832,39 +868,27 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
||||||
renderer->shaders.quad.color = glGetUniformLocation(prog, "color");
|
renderer->shaders.quad.color = glGetUniformLocation(prog, "color");
|
||||||
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
|
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||||
|
|
||||||
renderer->shaders.tex_rgba.program = prog =
|
if (!link_tex_program(renderer, &renderer->shaders.tex_rgba,
|
||||||
link_program(renderer, common_vert_src, tex_rgba_frag_src);
|
&(struct wlr_gles2_shader_params){
|
||||||
if (!renderer->shaders.tex_rgba.program) {
|
.source = WLR_GLES2_SHADER_SOURCE_TEXTURE_RGBA,
|
||||||
|
.color_transform = color_transform,
|
||||||
|
})) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
renderer->shaders.tex_rgba.proj = glGetUniformLocation(prog, "proj");
|
if (!link_tex_program(renderer, &renderer->shaders.tex_rgbx,
|
||||||
renderer->shaders.tex_rgba.tex = glGetUniformLocation(prog, "tex");
|
&(struct wlr_gles2_shader_params){
|
||||||
renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha");
|
.source = WLR_GLES2_SHADER_SOURCE_TEXTURE_RGBX,
|
||||||
renderer->shaders.tex_rgba.pos_attrib = glGetAttribLocation(prog, "pos");
|
.color_transform = color_transform,
|
||||||
renderer->shaders.tex_rgba.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
})) {
|
||||||
|
|
||||||
renderer->shaders.tex_rgbx.program = prog =
|
|
||||||
link_program(renderer, common_vert_src, tex_rgbx_frag_src);
|
|
||||||
if (!renderer->shaders.tex_rgbx.program) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
renderer->shaders.tex_rgbx.proj = glGetUniformLocation(prog, "proj");
|
if (renderer->exts.OES_egl_image_external &&
|
||||||
renderer->shaders.tex_rgbx.tex = glGetUniformLocation(prog, "tex");
|
!link_tex_program(renderer, &renderer->shaders.tex_ext,
|
||||||
renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha");
|
&(struct wlr_gles2_shader_params){
|
||||||
renderer->shaders.tex_rgbx.pos_attrib = glGetAttribLocation(prog, "pos");
|
.source = WLR_GLES2_SHADER_SOURCE_TEXTURE_EXTERNAL,
|
||||||
renderer->shaders.tex_rgbx.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
.color_transform = color_transform,
|
||||||
|
})) {
|
||||||
if (renderer->exts.OES_egl_image_external) {
|
goto error;
|
||||||
renderer->shaders.tex_ext.program = prog =
|
|
||||||
link_program(renderer, common_vert_src, tex_external_frag_src);
|
|
||||||
if (!renderer->shaders.tex_ext.program) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
renderer->shaders.tex_ext.proj = glGetUniformLocation(prog, "proj");
|
|
||||||
renderer->shaders.tex_ext.tex = glGetUniformLocation(prog, "tex");
|
|
||||||
renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha");
|
|
||||||
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
|
||||||
renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pop_gles2_debug(renderer);
|
pop_gles2_debug(renderer);
|
||||||
|
|
|
||||||
83
render/gles2/shaders/common.frag
Normal file
83
render/gles2/shaders/common.frag
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/* enum wlr_gles2_shader_source */
|
||||||
|
#define SOURCE_SINGLE_COLOR 1
|
||||||
|
#define SOURCE_TEXTURE_RGBA 2
|
||||||
|
#define SOURCE_TEXTURE_RGBX 3
|
||||||
|
#define SOURCE_TEXTURE_EXTERNAL 4
|
||||||
|
|
||||||
|
/* enum wlr_gles2_color_transform */
|
||||||
|
#define COLOR_TRANSFORM_IDENTITY 0
|
||||||
|
#define COLOR_TRANSFORM_LUT_3D 1
|
||||||
|
|
||||||
|
#if !defined(SOURCE) || !defined(COLOR_TRANSFORM)
|
||||||
|
#error "Missing shader preamble"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SOURCE == SOURCE_TEXTURE_EXTERNAL
|
||||||
|
#extension GL_OES_EGL_image_external : require
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if COLOR_TRANSFORM == COLOR_TRANSFORM_3DLUT
|
||||||
|
#extension GL_OES_texture_3D : require
|
||||||
|
#endif
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
|
#if SOURCE == SOURCE_TEXTURE_EXTERNAL
|
||||||
|
uniform samplerExternalOES tex;
|
||||||
|
#elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX
|
||||||
|
uniform sampler2D tex;
|
||||||
|
#elif SOURCE == SOURCE_SINGLE_COLOR
|
||||||
|
uniform vec4 color;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SOURCE != SOURCE_SINGLE_COLOR
|
||||||
|
uniform float alpha;
|
||||||
|
#else
|
||||||
|
const float alpha = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if COLOR_TRANSFORM == COLOR_TRANSFORM_LUT_3D
|
||||||
|
uniform mediump sampler3D lut_3d;
|
||||||
|
uniform float lut_3d_offset;
|
||||||
|
uniform float lut_3d_scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vec4 sample_texture() {
|
||||||
|
#if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL
|
||||||
|
return texture2D(tex, v_texcoord);
|
||||||
|
#elif SOURCE == SOURCE_TEXTURE_RGBX
|
||||||
|
return vec4(texture2D(tex, v_texcoord).rgb, 1.0);
|
||||||
|
#elif SOURCE == SOURCE_SINGLE_COLOR
|
||||||
|
return color;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 transform_color(vec4 color) {
|
||||||
|
#if COLOR_TRANSFORM == COLOR_TRANSFORM_IDENTITY
|
||||||
|
return color;
|
||||||
|
#elif COLOR_TRANSFORM == COLOR_TRANSFORM_LUT_3D
|
||||||
|
vec3 pos = lut_3d_offset + color * lut_3d_scale;
|
||||||
|
return texture3D(lut_3d, pos).rgb;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 color = sample_texture() * alpha;
|
||||||
|
|
||||||
|
#if COLOR_TRANSFORM != COLOR_TRANSFORM_IDENTITY
|
||||||
|
// Convert from pre-multiplied alpha to straight alpha
|
||||||
|
if (color.a == 0.0)
|
||||||
|
color.rgb = vec3(0.0, 0.0, 0.0);
|
||||||
|
else
|
||||||
|
color.rgb /= color.a;
|
||||||
|
|
||||||
|
color = transform_color(color);
|
||||||
|
|
||||||
|
// Convert from straight alpha to pre-multiplied alpha
|
||||||
|
color.rgb *= color.a;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,7 @@ embed = find_program('./embed.sh', native: true)
|
||||||
|
|
||||||
shaders = [
|
shaders = [
|
||||||
'common.vert',
|
'common.vert',
|
||||||
'quad.frag',
|
'common.frag',
|
||||||
'tex_rgba.frag',
|
|
||||||
'tex_rgbx.frag',
|
|
||||||
'tex_external.frag',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach name : shaders
|
foreach name : shaders
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
precision mediump float;
|
|
||||||
varying vec4 v_color;
|
|
||||||
varying vec2 v_texcoord;
|
|
||||||
uniform vec4 color;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_FragColor = color;
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#extension GL_OES_EGL_image_external : require
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
varying vec2 v_texcoord;
|
|
||||||
uniform samplerExternalOES texture0;
|
|
||||||
uniform float alpha;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_FragColor = texture2D(texture0, v_texcoord) * alpha;
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
precision mediump float;
|
|
||||||
varying vec2 v_texcoord;
|
|
||||||
uniform sampler2D tex;
|
|
||||||
uniform float alpha;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_FragColor = texture2D(tex, v_texcoord) * alpha;
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
precision mediump float;
|
|
||||||
varying vec2 v_texcoord;
|
|
||||||
uniform sampler2D tex;
|
|
||||||
uniform float alpha;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_FragColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0) * alpha;
|
|
||||||
}
|
|
||||||
|
|
@ -38,3 +38,9 @@ endif
|
||||||
subdir('pixman')
|
subdir('pixman')
|
||||||
|
|
||||||
subdir('allocator')
|
subdir('allocator')
|
||||||
|
|
||||||
|
lcms2 = dependency('lcms2', required: get_option('color-management'))
|
||||||
|
if lcms2.found()
|
||||||
|
wlr_deps += lcms2
|
||||||
|
wlr_files += files('color.c')
|
||||||
|
endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue