vo_opengl: fix display of ARGB ith color management enabled

PNG uses a different component order from GL_RGBA, so we upload the
surface using the "wrong" order, and then fix it in the shader. This
breaks if a sRGB texture (GL_SRGB) is used: the hardware will not touch
the alpha channel, which means that the B component is not adjusted,
leading to incorrect output.

Just remove the use of sRGB textures completely. It might lead to a
slight slow down when playing RGB with color management enabled, but
with this combination of obscure use case with minor performance impact
it's not a meaningful disadvantage.

Unfortunately this also means that alpha is handled incorrectly with our
own color management, but alpha isn't so important and can be fixed
later. (0.0 and 1.0 are unchanged by the transfer function, so it
"mostly" works.)

Fixes #1530.
This commit is contained in:
wm4 2015-01-28 13:36:07 +01:00
parent 631c256819
commit f3c84a322d
3 changed files with 9 additions and 37 deletions

View File

@ -91,7 +91,6 @@ struct feature {
static const struct feature features[] = {
{MPGL_CAP_FB, "Framebuffers"},
{MPGL_CAP_VAO, "VAOs"},
{MPGL_CAP_SRGB_TEX, "sRGB textures"},
{MPGL_CAP_FLOAT_TEX, "Float textures"},
{MPGL_CAP_TEX_RG, "RG textures"},
{MPGL_CAP_1ST_CLASS_ARRAYS, "1st class shader arrays"},
@ -224,8 +223,7 @@ static const struct gl_functions gl_functions[] = {
{
.ver_core = 300,
.ver_es_core = 300,
.provides = MPGL_CAP_SRGB_TEX | MPGL_CAP_3D_TEX |
MPGL_CAP_1ST_CLASS_ARRAYS,
.provides = MPGL_CAP_3D_TEX | MPGL_CAP_1ST_CLASS_ARRAYS,
.functions = (const struct gl_function[]) {
DEF_FN(GetStringi),
// for ES 3.0
@ -285,12 +283,6 @@ static const struct gl_functions gl_functions[] = {
{0}
}
},
// sRGB textures, extension in GL 2.x, core in GL 3.x core.
{
.ver_core = 300,
.extension = "GL_EXT_texture_sRGB",
.provides = MPGL_CAP_SRGB_TEX,
},
// Float textures, extension in GL 2.x, core in GL 3.x core.
{
.ver_core = 300,

View File

@ -66,7 +66,6 @@ enum {
MPGL_CAP_ROW_LENGTH = (1 << 4), // GL_[UN]PACK_ROW_LENGTH
MPGL_CAP_FB = (1 << 5),
MPGL_CAP_VAO = (1 << 6),
MPGL_CAP_SRGB_TEX = (1 << 7),
MPGL_CAP_FLOAT_TEX = (1 << 9),
MPGL_CAP_TEX_RG = (1 << 10), // GL_ARB_texture_rg / GL 3.x
MPGL_CAP_VDPAU = (1 << 11), // GL_NV_vdpau_interop

View File

@ -170,7 +170,6 @@ struct gl_video {
struct mp_imgfmt_desc image_desc;
bool is_yuv, is_rgb, is_packed_yuv;
bool is_linear_rgb;
bool has_alpha;
char color_swizzle[5];
@ -1118,6 +1117,7 @@ static void compile_shaders(struct gl_video *p)
float input_gamma = 1.0;
float conv_gamma = 1.0;
bool is_linear_rgb = false;
if (p->image_desc.flags & MP_IMGFLAG_XYZ) {
input_gamma *= 2.6;
@ -1126,7 +1126,7 @@ static void compile_shaders(struct gl_video *p)
// otherwise we just scale back to 2.40 to match typical displays,
// as a reasonable approximation.
if (use_cms) {
p->is_linear_rgb = true;
is_linear_rgb = true;
} else {
conv_gamma *= 1.0 / 2.40;
}
@ -1144,7 +1144,7 @@ static void compile_shaders(struct gl_video *p)
// Linear light scaling is only enabled when either color correction
// option (3dlut or srgb) is enabled, otherwise scaling is done in the
// source space.
if (!p->is_linear_rgb && use_cms) {
if (!is_linear_rgb && use_cms) {
// We just use the color level range to distinguish between PC
// content like images, which are most likely sRGB, and TV content
// like movies, which are most likely BT.1886
@ -1157,7 +1157,7 @@ static void compile_shaders(struct gl_video *p)
}
}
bool use_linear_light = gamma_fun != MP_CSP_TRC_NONE || p->is_linear_rgb;
bool use_linear_light = gamma_fun != MP_CSP_TRC_NONE || is_linear_rgb;
// Optionally transform to sigmoidal color space if requested, but only
// when upscaling in linear light
@ -1717,14 +1717,6 @@ static void init_video(struct gl_video *p, const struct mp_image_params *params)
p->image_dh = params->d_h;
p->image_params = *params;
if (p->is_rgb && (p->opts.srgb || p->use_lut_3d) && !p->hwdec_active) {
// If we're opening an RGB source like a png file or similar,
// we just sample it using GL_SRGB which treats it as an sRGB source
// and pretend it's linear as far as CMS is concerned
p->is_linear_rgb = true;
p->image.planes[0].gl_internal_format = GL_SRGB;
}
int eq_caps = MP_CSP_EQ_CAPS_GAMMA;
if (p->is_yuv && p->image_params.colorspace != MP_CSP_BT_2020_C)
eq_caps |= MP_CSP_EQ_CAPS_COLORMATRIX;
@ -2307,7 +2299,6 @@ static void check_gl_features(struct gl_video *p)
GL *gl = p->gl;
bool have_float_tex = gl->mpgl_caps & MPGL_CAP_FLOAT_TEX;
bool have_fbo = gl->mpgl_caps & MPGL_CAP_FB;
bool have_srgb = gl->mpgl_caps & MPGL_CAP_SRGB_TEX;
bool have_arrays = gl->mpgl_caps & MPGL_CAP_1ST_CLASS_ARRAYS;
bool have_1d_tex = gl->mpgl_caps & MPGL_CAP_1D_TEX;
bool have_3d_tex = gl->mpgl_caps & MPGL_CAP_3D_TEX;
@ -2372,19 +2363,10 @@ static void check_gl_features(struct gl_video *p)
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (FBO)";
}
if (p->is_rgb) {
// When opening RGB files we use SRGB to expand
if (!have_srgb && use_cms) {
p->opts.srgb = false;
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (SRGB textures)";
}
} else {
// when opening non-RGB files we use bt709_expand()
if (!have_mix && p->use_lut_3d) {
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (GLSL version)";
}
// because of bt709_expand()
if (!have_mix && p->use_lut_3d) {
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (GLSL version)";
}
if (gl->es && p->opts.pbo) {
p->opts.pbo = 0;
@ -2669,7 +2651,6 @@ supported:
init->is_yuv = desc.flags & MP_IMGFLAG_YUV;
init->is_rgb = desc.flags & MP_IMGFLAG_RGB;
init->is_linear_rgb = false;
init->plane_count = desc.num_planes;
init->image_desc = desc;