From 03fed576f0d9076d064cd2022099a6cb67df7c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 26 Nov 2015 10:14:45 +0100 Subject: libs: add gl_get_current_api() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to know which OpenGL API use, we must detect the API type of current context. This patch adds the function gl_get_current_api() which returns the OpenGL API type. This function is an adaptation of gst_gl_context_get_current_gl_api() from GstGL. Signed-off-by: Víctor Manuel Jáquez Leal https://bugzilla.gnome.org/show_bug.cgi?id=753099 --- gst-libs/gst/vaapi/gstvaapiutils_glx.c | 89 ++++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapiutils_glx.h | 14 ++++++ 2 files changed, 103 insertions(+) (limited to 'gst-libs') diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c index b21cb6c9..974d3a03 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c @@ -1087,3 +1087,92 @@ gl_unbind_framebuffer_object (GLFramebufferObject * fbo) fbo->is_bound = FALSE; return TRUE; } + +/** + * gl_get_current_api: + * @major: (out): (allow-none): the GL major version + * @minor: (out): (allow-none): the GL minor version + * + * If an error occurs, @major and @minor aren't modified and + * %GST_VAAPI_GL_API_NONE is returned. + * + * This is an adaptation of gst_gl_context_get_current_gl_api() from GstGL. + * + * Returns: The version supported by the OpenGL context current in the calling + * thread or %GST_VAAPI_GL_API_NONE + */ +GstVaapiGLApi +gl_get_current_api (guint * major, guint * minor) +{ + const gchar *version; + gint maj, min, n; + GstVaapiGLApi ret = (1 << 31); + + while (ret != GST_VAAPI_GL_API_NONE) { + version = (const gchar *) glGetString (GL_VERSION); + if (!version) + goto next; + + /* strlen (x.x) == 3 */ + n = strlen (version); + if (n < 3) + goto next; + + if (g_strstr_len (version, 9, "OpenGL ES")) { + /* strlen (OpenGL ES x.x) == 13 */ + if (n < 13) + goto next; + + sscanf (&version[10], "%d.%d", &maj, &min); + + if (maj <= 0 || min < 0) + goto next; + + if (maj == 1) { + ret = GST_VAAPI_GL_API_GLES1; + break; + } else if (maj == 2 || maj == 3) { + ret = GST_VAAPI_GL_API_GLES2; + break; + } + + goto next; + } else { + sscanf (version, "%d.%d", &maj, &min); + + if (maj <= 0 || min < 0) + goto next; + + if (maj > 3 || (maj == 3 && min > 1)) { + GLuint context_flags = 0; + + ret = GST_VAAPI_GL_API_NONE; + if (!gl_get_param (GL_CONTEXT_PROFILE_MASK, &context_flags)) + break; + + if (context_flags & GL_CONTEXT_CORE_PROFILE_BIT) + ret |= GST_VAAPI_GL_API_OPENGL3; + if (context_flags & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + ret |= GST_VAAPI_GL_API_OPENGL; + break; + } + + ret = GST_VAAPI_GL_API_OPENGL; + break; + } + + next: + /* iterate through the apis */ + ret >>= 1; + } + + if (ret == GST_VAAPI_GL_API_NONE) + return GST_VAAPI_GL_API_NONE; + + if (major) + *major = maj; + if (minor) + *minor = min; + + return ret; +} diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.h b/gst-libs/gst/vaapi/gstvaapiutils_glx.h index d78b3ee7..42e047f5 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.h @@ -210,4 +210,18 @@ G_GNUC_INTERNAL gboolean gl_unbind_framebuffer_object (GLFramebufferObject * fbo); +typedef enum { + GST_VAAPI_GL_API_NONE = 0, + GST_VAAPI_GL_API_OPENGL = (1 << 0), + GST_VAAPI_GL_API_OPENGL3 = (1 << 1), + GST_VAAPI_GL_API_GLES1 = (1 << 15), + GST_VAAPI_GL_API_GLES2 = (1 << 16), + + GST_VAAPI_GL_API_ANY = G_MAXUINT32 +} GstVaapiGLApi; + +G_GNUC_INTERNAL +GstVaapiGLApi +gl_get_current_api (guint * major, guint * minor); + #endif /* GST_VAAPI_UTILS_GLX_H */ -- cgit v1.2.1