diff options
author | Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com> | 2015-11-26 10:26:10 +0100 |
---|---|---|
committer | Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com> | 2015-11-30 13:26:22 +0100 |
commit | da835c750838a50ed0708907aff84f0d0661943f (patch) | |
tree | 2ba625a5ecebf5cfe1eff08970b64be4a745129d | |
parent | 03fed576f0d9076d064cd2022099a6cb67df7c7b (diff) |
libs: add gl3_bind_texture_2d()
Since OpenGL3.1 removed the fixed pipelines[1] enabling 2D textures is not
needed. In particular, the Intel's Mesa implementation complains if it is
called.
This patch add a new binding function for 2D textures, without enabling
gl3_bind_texture_2d()[2].
1. https://www.opengl.org/wiki/Fixed_Function_Pipeline
2. https://www.opengl.org/wiki/Common_Mistakes#OOP_and_hidden_binding
Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
https://bugzilla.gnome.org/show_bug.cgi?id=753099
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapiutils_glx.c | 81 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapiutils_glx.h | 4 |
2 files changed, 68 insertions, 17 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c index 974d3a03..37e9375d 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c @@ -465,25 +465,15 @@ gl_swap_buffers (GLContextState * cs) cs->swapped_buffers = TRUE; } -/** - * gl_bind_texture: - * @ts: a #GLTextureState - * @target: the target to which the texture is bound - * @texture: the name of a texture - * - * Binds @texture to the specified @target, while recording the - * previous state in @ts. - * - * Return value: %TRUE on success - */ -gboolean -gl_bind_texture (GLTextureState * ts, GLenum target, GLuint texture) +static inline gboolean +_init_texture_state (GLTextureState * ts, GLenum target, GLuint texture, + gboolean enabled) { GLenum binding; ts->target = target; - if (glIsEnabled (target)) { + if (enabled) { binding = gl_get_texture_binding (target); if (!binding) return FALSE; @@ -491,15 +481,18 @@ gl_bind_texture (GLTextureState * ts, GLenum target, GLuint texture) return FALSE; ts->was_enabled = TRUE; ts->was_bound = texture == ts->old_texture; - if (ts->was_bound) - return TRUE; } else { - glEnable (target); ts->old_texture = 0; ts->was_enabled = FALSE; ts->was_bound = FALSE; } + return TRUE; +} + +static inline gboolean +_bind_enabled_texture (GLenum target, GLuint texture) +{ gl_purge_errors (); glBindTexture (target, texture); if (gl_check_error ()) @@ -508,6 +501,60 @@ gl_bind_texture (GLTextureState * ts, GLenum target, GLuint texture) } /** + * gl_bind_texture: + * @ts: a #GLTextureState + * @target: the target to which the texture is bound + * @texture: the name of a texture + * + * Binds @texture to the specified @target, while recording the + * previous state in @ts. + * + * Return value: %TRUE on success + */ +gboolean +gl_bind_texture (GLTextureState * ts, GLenum target, GLuint texture) +{ + gboolean enabled; + + enabled = (gboolean) glIsEnabled (target); + if (!_init_texture_state (ts, target, texture, enabled)) + return FALSE; + if (ts->was_bound) + return TRUE; + if (!enabled) + glEnable (target); + + return _bind_enabled_texture (target, texture); +} + +/** + * gl3_bind_texture_2d: + * @ts: a #GLTextureState + * @target: the target to which the texture is bound + * @texture: the name of a texture + * + * Binds @texture to the specified @target, while recording the + * previous state in @ts. + * + * This function is for OpenGL3 API and for targets type GL_TEXTURE_2D. + * + * Return value: %TRUE on success + */ +gboolean +gl3_bind_texture_2d (GLTextureState * ts, GLenum target, GLuint texture) +{ + if (target != GL_TEXTURE_2D) + return FALSE; + + if (!_init_texture_state (ts, target, texture, TRUE)) + return FALSE; + if (ts->was_bound) + return TRUE; + + return _bind_enabled_texture (target, texture); +} + +/** * gl_unbind_texture: * @ts: a #GLTextureState * diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.h b/gst-libs/gst/vaapi/gstvaapiutils_glx.h index 42e047f5..3fafe5ec 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.h @@ -121,6 +121,10 @@ gboolean gl_bind_texture (GLTextureState * ts, GLenum target, GLuint texture); G_GNUC_INTERNAL +gboolean +gl3_bind_texture_2d (GLTextureState * ts, GLenum target, GLuint texture); + +G_GNUC_INTERNAL void gl_unbind_texture (GLTextureState * ts); |