From d6e460095fb2cbafbe14775661ff3a6046854617 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Thu, 12 Mar 2015 16:46:44 +0000 Subject: [PATCH] glcolorconvert: cache indices in a buffer object --- gst-libs/gst/gl/gstglcolorconvert.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c index 8f1e499dda..86906bb21c 100644 --- a/gst-libs/gst/gl/gstglcolorconvert.c +++ b/gst-libs/gst/gl/gstglcolorconvert.c @@ -415,6 +415,9 @@ static const GLfloat vertices[] = { -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; + +static const GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + /* *INDENT-ON* */ struct ConvertInfo @@ -441,6 +444,7 @@ struct _GstGLColorConvertPrivate GLuint vao; GLuint vertex_buffer; + GLuint vbo_indices; GLuint attr_position; GLuint attr_texture; }; @@ -531,6 +535,11 @@ _reset_gl (GstGLContext * context, GstGLColorConvert * convert) gl->DeleteBuffers (1, &convert->priv->vertex_buffer); convert->priv->vertex_buffer = 0; } + + if (convert->priv->vbo_indices) { + gl->DeleteBuffers (1, &convert->priv->vbo_indices); + convert->priv->vbo_indices = 0; + } } static void @@ -1335,6 +1344,15 @@ _init_convert (GstGLColorConvert * convert) gl->BindBuffer (GL_ARRAY_BUFFER, 0); } + if (!convert->priv->vbo_indices) { + gl->GenBuffers (1, &convert->priv->vbo_indices); + gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, convert->priv->vbo_indices); + gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices, + GL_STATIC_DRAW); + gl->BindBuffer (GL_ARRAY_BUFFER, 0); + } + + gl->BindTexture (GL_TEXTURE_2D, 0); convert->initted = TRUE; @@ -1621,8 +1639,6 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert) GLint viewport_dim[4]; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; - GLenum multipleRT[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, @@ -1679,7 +1695,8 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert) g_free (scale_name); } - gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); + gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, convert->priv->vbo_indices); + gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); if (gl->BindVertexArray) gl->BindVertexArray (0); @@ -1689,6 +1706,8 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert) if (gl->DrawBuffer) gl->DrawBuffer (GL_NONE); + gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); + /* we are done with the shader */ gst_gl_context_clear_shader (context);