1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-19 09:57:34 +00:00

vo_opengl: support GL_EXT_texture_norm16 on GLES

This gives us 16 bit fixed-point integer texture formats, including
ability to sample from them with linear filtering, and using them as FBO
attachments.

The integer texture format path is still there for the sake of ANGLE,
which does not support GL_EXT_texture_norm16 yet.

The change to pass_dither() is needed, because the code path using
GL_R16 for the dither texture relies on glTexImage2D being able to
convert from GL_FLOAT to GL_R16. GLES does not allow this. This could be
trivially fixed by doing the conversion ourselves, but I'm too lazy to
do this now.
This commit is contained in:
wm4 2016-04-27 19:14:10 +02:00
parent 757c8baf8c
commit 9d16837c99
4 changed files with 14 additions and 7 deletions

View File

@ -838,7 +838,8 @@ Available video output drivers are:
``fmt`` can be one of: rgb, rgba, rgb8, rgb10, rgb10_a2, rgb16, rgb16f,
rgb32f, rgba12, rgba16, rgba16f, rgba32f.
Default: ``auto``, which maps to rgba16 on desktop GL, and rgba16f or
rgb10_a2 on GLES (e.g. ANGLE).
rgb10_a2 on GLES (e.g. ANGLE), unless GL_EXT_texture_norm16 is
available.
``gamma=<0.1..2.0>``
Set a gamma value (default: 1.0). If gamma is adjusted in other ways

View File

@ -226,6 +226,12 @@ static const struct gl_functions gl_functions[] = {
.extension = "GL_ARB_texture_rg",
.provides = MPGL_CAP_TEX_RG,
},
// GL_R16 etc.
{
.ver_core = 300,
.extension = "GL_EXT_texture_norm16",
.provides = MPGL_CAP_EXT16,
},
{
.ver_core = 320,
.extension = "GL_ARB_sync",

View File

@ -61,6 +61,7 @@ enum {
MPGL_CAP_3D_TEX = (1 << 15),
MPGL_CAP_DEBUG = (1 << 16),
MPGL_CAP_DXINTEROP = (1 << 17), // WGL_NV_DX_interop
MPGL_CAP_EXT16 = (1 << 18), // GL_EXT_texture_norm16
MPGL_CAP_SW = (1 << 30), // indirect or sw renderer
};

View File

@ -260,6 +260,7 @@ static const struct fmt_entry mp_to_gl_formats[] = {
{0},
};
// These are used for desktop GL 3+, and GLES 3+ with GL_EXT_texture_norm16.
static const struct fmt_entry gl_byte_formats[] = {
{0, GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // 1 x 8
{0, GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // 2 x 8
@ -551,10 +552,8 @@ static const struct fmt_entry *find_tex_format(GL *gl, int bytes_per_comp,
assert(bytes_per_comp == 1 || bytes_per_comp == 2);
assert(n_channels >= 1 && n_channels <= 4);
const struct fmt_entry *fmts = gl_byte_formats;
if (gl->es >= 300) {
fmts = gl_byte_formats_gles3;
} else if (gl->es) {
fmts = gl_byte_formats_gles2;
if (gl->es && !(gl->mpgl_caps & MPGL_CAP_EXT16)) {
fmts = gl->es >= 300 ? gl_byte_formats_gles3 : gl_byte_formats_gles2;
} else if (!(gl->mpgl_caps & MPGL_CAP_TEX_RG)) {
fmts = gl_byte_formats_legacy;
}
@ -1959,7 +1958,7 @@ static void pass_dither(struct gl_video *p)
const struct fmt_entry *fmt = find_tex_format(gl, 2, 1);
tex_size = size;
// Prefer R16 texture since they provide higher precision.
if (fmt->internal_format) {
if (fmt->internal_format && !gl->es) {
tex_iformat = fmt->internal_format;
tex_format = fmt->format;
} else {
@ -2637,7 +2636,7 @@ static void check_gl_features(struct gl_video *p)
if (have_fbo) {
if (!p->opts.fbo_format) {
p->opts.fbo_format = GL_RGBA16;
if (gl->es)
if (gl->es && !(gl->mpgl_caps & MPGL_CAP_EXT16))
p->opts.fbo_format = have_float_tex ? GL_RGBA16F : GL_RGB10_A2;
}
have_fbo = test_fbo(p);