mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-10 03:19:40 +00:00
libs: add gl_get_current_api()
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 <victorx.jaquez@intel.com> https://bugzilla.gnome.org/show_bug.cgi?id=753099
This commit is contained in:
parent
d7bd0a4c10
commit
03fed576f0
2 changed files with 103 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue