summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-12-30 19:24:34 +0100
committerwm4 <wm4@nowhere>2016-12-30 20:03:17 +0100
commitd4e7b981bfcdcd7c6930af73494529d11b8bcde9 (patch)
tree2a89c7eb9660502396d9d2fc28fbac8911c868a1 /video
parentb9cebf180b6d0b429dccbffb60243a88b600aca1 (diff)
downloadmpv-d4e7b981bfcdcd7c6930af73494529d11b8bcde9.tar.bz2
mpv-d4e7b981bfcdcd7c6930af73494529d11b8bcde9.tar.xz
vo_opengl: egl_helpers: add a way to pass more options
For X11 garbage we have to pass some annoying parameters to EGL context creation. Add some sort of extensible API, so that adding a new parameter doesn't break all callers. We still want to keep it as a single function, because it's so nice isolating all the EGL nonsense API boilerplate like this. (Did I mention yet that X11 and EGL are garbage?) Also somewhat simplifies the vo_flags mess in the helper internals.
Diffstat (limited to 'video')
-rw-r--r--video/out/opengl/egl_helpers.c42
-rw-r--r--video/out/opengl/egl_helpers.h9
2 files changed, 35 insertions, 16 deletions
diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c
index 31a31dfb24..3594f72022 100644
--- a/video/out/opengl/egl_helpers.c
+++ b/video/out/opengl/egl_helpers.c
@@ -31,23 +31,22 @@
#define EGL_OPENGL_ES3_BIT 0x00000040
#endif
+// es_version = 0 (desktop), 2/3 (ES major version)
static bool create_context(EGLDisplay display, struct mp_log *log, bool probing,
- int vo_flags, bool es3,
+ int es_version, struct mpegl_opts *opts,
EGLContext *out_context, EGLConfig *out_config)
{
int msgl = probing ? MSGL_V : MSGL_FATAL;
- bool es = vo_flags & VOFLAG_GLES;
-
EGLenum api = EGL_OPENGL_API;
EGLint rend = EGL_OPENGL_BIT;
const char *name = "Desktop OpenGL";
- if (es) {
+ if (es_version == 2) {
api = EGL_OPENGL_ES_API;
rend = EGL_OPENGL_ES2_BIT;
name = "GLES 2.0";
}
- if (es3) {
+ if (es_version == 3) {
api = EGL_OPENGL_ES_API;
rend = EGL_OPENGL_ES3_BIT;
name = "GLES 3.x";
@@ -66,8 +65,8 @@ static bool create_context(EGLDisplay display, struct mp_log *log, bool probing,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
- EGL_ALPHA_SIZE, (vo_flags & VOFLAG_ALPHA ) ? 1 : 0,
- EGL_DEPTH_SIZE, 0,
+ EGL_ALPHA_SIZE, (opts->vo_flags & VOFLAG_ALPHA ) ? 1 : 0,
+ EGL_DEPTH_SIZE, 1,
EGL_RENDERABLE_TYPE, rend,
EGL_NONE
};
@@ -84,9 +83,9 @@ static bool create_context(EGLDisplay display, struct mp_log *log, bool probing,
EGLContext *ctx = NULL;
- if (es) {
+ if (es_version) {
EGLint attrs[] = {
- EGL_CONTEXT_CLIENT_VERSION, es3 ? 3 : 2,
+ EGL_CONTEXT_CLIENT_VERSION, es_version,
EGL_NONE
};
@@ -134,6 +133,18 @@ static bool create_context(EGLDisplay display, struct mp_log *log, bool probing,
bool mpegl_create_context(EGLDisplay display, struct mp_log *log, int vo_flags,
EGLContext *out_context, EGLConfig *out_config)
{
+ return mpegl_create_context_opts(display, log,
+ &(struct mpegl_opts){.vo_flags = vo_flags}, out_context, out_config);
+}
+
+// Create a context and return it and the config it was created with. If it
+// returns false, the out_* pointers are set to NULL.
+bool mpegl_create_context_opts(EGLDisplay display, struct mp_log *log,
+ struct mpegl_opts *opts,
+ EGLContext *out_context, EGLConfig *out_config)
+{
+ assert(opts);
+
*out_context = NULL;
*out_config = NULL;
@@ -143,26 +154,25 @@ bool mpegl_create_context(EGLDisplay display, struct mp_log *log, int vo_flags,
mp_verbose(log, "EGL_VERSION=%s\nEGL_VENDOR=%s\nEGL_CLIENT_APIS=%s\n",
STR_OR_ERR(version), STR_OR_ERR(vendor), STR_OR_ERR(apis));
- int clean_flags = vo_flags & ~(unsigned)(VOFLAG_GLES | VOFLAG_NO_GLES);
- bool probing = vo_flags & VOFLAG_PROBING;
+ bool probing = opts->vo_flags & VOFLAG_PROBING;
int msgl = probing ? MSGL_V : MSGL_FATAL;
- bool try_desktop = !(vo_flags & VOFLAG_NO_GLES);
+ bool try_desktop = !(opts->vo_flags & VOFLAG_NO_GLES);
- if (!(vo_flags & VOFLAG_GLES)) {
+ if (!(opts->vo_flags & VOFLAG_GLES)) {
// Desktop OpenGL
- if (create_context(display, log, try_desktop | probing, clean_flags, false,
+ if (create_context(display, log, try_desktop | probing, 0, opts,
out_context, out_config))
return true;
}
if (try_desktop) {
// ES 3.x
- if (create_context(display, log, true, clean_flags | VOFLAG_GLES, true,
+ if (create_context(display, log, true, 3, opts,
out_context, out_config))
return true;
// ES 2.0
- if (create_context(display, log, probing, clean_flags | VOFLAG_GLES, false,
+ if (create_context(display, log, probing, 2, opts,
out_context, out_config))
return true;
}
diff --git a/video/out/opengl/egl_helpers.h b/video/out/opengl/egl_helpers.h
index 04197493f3..15033834f4 100644
--- a/video/out/opengl/egl_helpers.h
+++ b/video/out/opengl/egl_helpers.h
@@ -11,4 +11,13 @@ struct mp_log;
bool mpegl_create_context(EGLDisplay display, struct mp_log *log, int vo_flags,
EGLContext *out_context, EGLConfig *out_config);
+struct mpegl_opts {
+ // combination of VOFLAG_* values.
+ int vo_flags;
+};
+
+bool mpegl_create_context_opts(EGLDisplay display, struct mp_log *log,
+ struct mpegl_opts *opts,
+ EGLContext *out_context, EGLConfig *out_config);
+
#endif