summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-04-27 19:14:10 +0200
committerwm4 <wm4@nowhere>2016-04-27 19:19:56 +0200
commit9d16837c99c91e786e517b2520afa79bcdc433b3 (patch)
treed21daf07515b941fb447fa3ad734395f4b83946f
parent757c8baf8c5bd4598cd5455908e4fa543821837a (diff)
downloadmpv-9d16837c99c91e786e517b2520afa79bcdc433b3.tar.bz2
mpv-9d16837c99c91e786e517b2520afa79bcdc433b3.tar.xz
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.
-rw-r--r--DOCS/man/vo.rst3
-rw-r--r--video/out/opengl/common.c6
-rw-r--r--video/out/opengl/common.h1
-rw-r--r--video/out/opengl/video.c11
4 files changed, 14 insertions, 7 deletions
diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst
index 18e3f4ae64..bf3fb2e8fd 100644
--- a/DOCS/man/vo.rst
+++ b/DOCS/man/vo.rst
@@ -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
diff --git a/video/out/opengl/common.c b/video/out/opengl/common.c
index 30cce911e4..f9c830f25a 100644
--- a/video/out/opengl/common.c
+++ b/video/out/opengl/common.c
@@ -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",
diff --git a/video/out/opengl/common.h b/video/out/opengl/common.h
index f790dcb166..ef75ae1645 100644
--- a/video/out/opengl/common.h
+++ b/video/out/opengl/common.h
@@ -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
};
diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c
index b517e9fb2a..79807d072b 100644
--- a/video/out/opengl/video.c
+++ b/video/out/opengl/video.c
@@ -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);