From cfcec5f772a82a083acf66dc3bbb42a3c6136bc6 Mon Sep 17 00:00:00 2001 From: Yogish Kulkarni Date: Thu, 29 May 2014 10:56:31 +0530 Subject: eglglessink: Disable vertex attribute arrays after drawing Enable vertex attribute arrays which will be used by a GL program and disable them after drawing. If a vertex attribute array not required by a program is enabled, GL will try to read from it, which may crash the application. https://bugzilla.gnome.org/show_bug.cgi?id=730912 --- ext/eglgles/gstegladaptation.c | 12 ------------ ext/eglgles/gsteglglessink.c | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ext/eglgles/gstegladaptation.c b/ext/eglgles/gstegladaptation.c index 3d9cc03bf..45098af4f 100644 --- a/ext/eglgles/gstegladaptation.c +++ b/ext/eglgles/gstegladaptation.c @@ -589,14 +589,6 @@ gst_egl_adaptation_init_surface (GstEglAdaptationContext * ctx, ctx->tex_scale_loc[0][2] = glGetUniformLocation (ctx->glslprogram[0], "tex_scale2"); - glEnableVertexAttribArray (ctx->position_loc[0]); - if (got_gl_error ("glEnableVertexAttribArray")) - goto HANDLE_ERROR; - - glEnableVertexAttribArray (ctx->texpos_loc[0]); - if (got_gl_error ("glEnableVertexAttribArray")) - goto HANDLE_ERROR; - for (i = 0; i < ctx->n_textures; i++) { ctx->tex_loc[0][i] = glGetUniformLocation (ctx->glslprogram[0], texnames[i]); @@ -612,10 +604,6 @@ gst_egl_adaptation_init_surface (GstEglAdaptationContext * ctx, ctx->position_loc[1] = glGetAttribLocation (ctx->glslprogram[1], "position"); - - glEnableVertexAttribArray (ctx->position_loc[1]); - if (got_gl_error ("glEnableVertexAttribArray")) - goto HANDLE_ERROR; } /* Generate textures */ diff --git a/ext/eglgles/gsteglglessink.c b/ext/eglgles/gsteglglessink.c index 6f35cff81..270733096 100644 --- a/ext/eglgles/gsteglglessink.c +++ b/ext/eglgles/gsteglglessink.c @@ -1759,6 +1759,10 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink) GST_DEBUG_OBJECT (eglglessink, "Drawing black border 1"); glUseProgram (eglglessink->egl_context->glslprogram[1]); + glEnableVertexAttribArray (eglglessink->egl_context->position_loc[1]); + if (got_gl_error ("glEnableVertexAttribArray")) + goto HANDLE_ERROR; + glVertexAttribPointer (eglglessink->egl_context->position_loc[1], 3, GL_FLOAT, GL_FALSE, sizeof (coord5), (gpointer) (8 * sizeof (coord5))); if (got_gl_error ("glVertexAttribPointer")) @@ -1778,6 +1782,8 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink) glDrawElements (GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, 0); if (got_gl_error ("glDrawElements")) goto HANDLE_ERROR; + + glDisableVertexAttribArray (eglglessink->egl_context->position_loc[1]); } /* Draw video frame */ @@ -1798,6 +1804,14 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink) goto HANDLE_ERROR; } + glEnableVertexAttribArray (eglglessink->egl_context->position_loc[0]); + if (got_gl_error ("glEnableVertexAttribArray")) + goto HANDLE_ERROR; + + glEnableVertexAttribArray (eglglessink->egl_context->texpos_loc[0]); + if (got_gl_error ("glEnableVertexAttribArray")) + goto HANDLE_ERROR; + if (eglglessink->orientation == GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL) { glVertexAttribPointer (eglglessink->egl_context->position_loc[0], 3, @@ -1829,6 +1843,9 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink) if (got_gl_error ("glDrawElements")) goto HANDLE_ERROR; + glDisableVertexAttribArray (eglglessink->egl_context->position_loc[0]); + glDisableVertexAttribArray (eglglessink->egl_context->texpos_loc[0]); + if (!gst_egl_adaptation_context_swap_buffers (eglglessink->egl_context)) { goto HANDLE_ERROR; } @@ -1838,8 +1855,11 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink) return GST_FLOW_OK; HANDLE_ERROR: - GST_ERROR_OBJECT (eglglessink, "Rendering disabled for this frame"); + glDisableVertexAttribArray (eglglessink->egl_context->position_loc[0]); + glDisableVertexAttribArray (eglglessink->egl_context->texpos_loc[0]); + glDisableVertexAttribArray (eglglessink->egl_context->position_loc[1]); + GST_ERROR_OBJECT (eglglessink, "Rendering disabled for this frame"); return GST_FLOW_ERROR; } -- cgit v1.2.1