gl: element buffers are part of vao state

Use them as such.  They are also required for GL3 core profile support
with glDrawElements on OS X.
This commit is contained in:
Matthew Waters 2015-05-01 12:04:28 +10:00
parent ba5130fe01
commit 7f7a9dd3ec
13 changed files with 174 additions and 70 deletions

View file

@ -293,6 +293,11 @@ gst_gl_filter_cube_reset_gl (GstGLFilter * filter)
cube_filter->vertex_buffer = 0;
}
if (cube_filter->vbo_indices) {
gl->DeleteBuffers (1, &cube_filter->vbo_indices);
cube_filter->vbo_indices = 0;
}
if (cube_filter->shader) {
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context,
cube_filter->shader);
@ -380,6 +385,21 @@ static const GLfloat vertices[] = {
-1.0, 1.0, -1.0, 0.0, 1.0,
-1.0, 1.0, 1.0, 0.0, 0.0
};
static const GLushort indices[] = {
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23
};
/* *INDENT-ON* */
static void
@ -387,6 +407,7 @@ _bind_buffer (GstGLFilterCube * cube_filter)
{
const GstGLFuncs *gl = GST_GL_BASE_FILTER (cube_filter)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, cube_filter->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, cube_filter->vertex_buffer);
cube_filter->attr_position =
@ -412,6 +433,7 @@ _unbind_buffer (GstGLFilterCube * cube_filter)
{
const GstGLFuncs *gl = GST_GL_BASE_FILTER (cube_filter)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (cube_filter->attr_position);
@ -429,21 +451,6 @@ _callback (gpointer stuff)
static GLfloat yrot = 0;
static GLfloat zrot = 0;
GLushort indices[] = {
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23
};
const GLfloat matrix[] = {
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
@ -478,10 +485,18 @@ _callback (gpointer stuff)
gl->BufferData (GL_ARRAY_BUFFER, 6 * 4 * 5 * sizeof (GLfloat), vertices,
GL_STATIC_DRAW);
gl->GenBuffers (1, &cube_filter->vbo_indices);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, cube_filter->vbo_indices);
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
if (gl->GenVertexArrays) {
_bind_buffer (cube_filter);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindVertexArray (0);
}
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
}
if (gl->GenVertexArrays)
@ -489,7 +504,7 @@ _callback (gpointer stuff)
else
_bind_buffer (cube_filter);
gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
if (gl->GenVertexArrays)
gl->BindVertexArray (0);

View file

@ -54,6 +54,7 @@ struct _GstGLFilterCube
guint in_tex;
GLuint vao;
GLuint vbo_indices;
GLuint vertex_buffer;
GLint attr_position;
GLint attr_texture;

View file

@ -1348,6 +1348,8 @@ 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* */
static void
@ -1355,9 +1357,8 @@ _bind_buffer (GstGLImageSink * gl_sink)
{
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, gl_sink->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, gl_sink->vertex_buffer);
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
GL_STATIC_DRAW);
/* Load the vertex position */
gl->VertexAttribPointer (gl_sink->attr_position, 3, GL_FLOAT, GL_FALSE,
@ -1376,6 +1377,7 @@ _unbind_buffer (GstGLImageSink * gl_sink)
{
const GstGLFuncs *gl = gl_sink->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (gl_sink->attr_position);
@ -1400,15 +1402,27 @@ gst_glimage_sink_thread_init_redisplay (GstGLImageSink * gl_sink)
gl->BindVertexArray (gl_sink->vao);
}
gl->GenBuffers (1, &gl_sink->vertex_buffer);
_bind_buffer (gl_sink);
if (!gl_sink->vertex_buffer) {
gl->GenBuffers (1, &gl_sink->vertex_buffer);
gl->BindBuffer (GL_ARRAY_BUFFER, gl_sink->vertex_buffer);
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
GL_STATIC_DRAW);
}
if (!gl_sink->vbo_indices) {
gl->GenBuffers (1, &gl_sink->vbo_indices);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, gl_sink->vbo_indices);
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
}
if (gl->GenVertexArrays) {
_bind_buffer (gl_sink);
gl->BindVertexArray (0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
} else {
_unbind_buffer (gl_sink);
}
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
}
static void
@ -1425,6 +1439,11 @@ gst_glimage_sink_cleanup_glthread (GstGLImageSink * gl_sink)
gl->DeleteVertexArrays (1, &gl_sink->vao);
gl_sink->vao = 0;
}
if (gl_sink->vbo_indices) {
gl->DeleteVertexArrays (1, &gl_sink->vbo_indices);
gl_sink->vbo_indices = 0;
}
}
static void
@ -1537,7 +1556,6 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
if (!do_redisplay) {
gfloat alpha = gl_sink->ignore_alpha ? 1.0f : 0.0f;
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
gl->ClearColor (0.0, 0.0, 0.0, alpha);
gl->Clear (GL_COLOR_BUFFER_BIT);
@ -1560,7 +1578,7 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
gl->BindTexture (GL_TEXTURE_2D, gl_sink->redisplay_texture);
gst_gl_shader_set_uniform_1i (gl_sink->redisplay_shader, "tex", 0);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
gst_gl_context_clear_shader (gl_sink->context);

View file

@ -89,6 +89,7 @@ struct _GstGLImageSink
GstGLShader *redisplay_shader;
GLuint vao;
GLuint vbo_indices;
GLuint vertex_buffer;
GLint attr_position;
GLint attr_texture;

View file

@ -158,6 +158,11 @@ gst_gl_overlay_reset_gl_resources (GstGLFilter * filter)
overlay->vbo = 0;
}
if (overlay->vbo_indices) {
gl->DeleteBuffers (1, &overlay->vbo_indices);
overlay->vbo_indices = 0;
}
if (overlay->overlay_vao) {
gl->DeleteVertexArrays (1, &overlay->overlay_vao);
overlay->overlay_vao = 0;
@ -369,6 +374,7 @@ _unbind_buffer (GstGLOverlay * overlay)
{
const GstGLFuncs *gl = GST_GL_BASE_FILTER (overlay)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (overlay->attr_position);
@ -380,6 +386,7 @@ _bind_buffer (GstGLOverlay * overlay, GLuint vbo)
{
const GstGLFuncs *gl = GST_GL_BASE_FILTER (overlay)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, overlay->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, vbo);
gl->EnableVertexAttribArray (overlay->attr_position);
@ -399,6 +406,8 @@ float v_vertices[] = {
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
};
static const GLushort indices[] = { 0, 1, 2, 0, 2, 3, };
/* *INDENT-ON* */
static void
@ -411,11 +420,6 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
gboolean memory_mapped = FALSE;
const GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
GLushort indices[] = {
0, 1, 2,
0, 2, 3,
};
#if GST_GL_HAVE_OPENGL
if (gst_gl_context_get_gl_api (GST_GL_BASE_FILTER (filter)->context) &
GST_GL_API_OPENGL) {
@ -453,8 +457,18 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), v_vertices,
GL_STATIC_DRAW);
if (gl->GenVertexArrays)
gl->GenBuffers (1, &overlay->vbo_indices);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, overlay->vbo_indices);
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
if (gl->GenVertexArrays) {
_bind_buffer (overlay, overlay->vbo);
gl->BindVertexArray (0);
}
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
}
if (gl->GenVertexArrays)
@ -462,7 +476,7 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
else
_bind_buffer (overlay, overlay->vbo);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
if (!overlay->image_memory)
goto out;
@ -482,9 +496,14 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
gl->GenBuffers (1, &overlay->overlay_vbo);
gl->BindBuffer (GL_ARRAY_BUFFER, overlay->overlay_vbo);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, overlay->vbo_indices);
overlay->geometry_change = TRUE;
}
if (gl->GenVertexArrays) {
gl->BindVertexArray (overlay->overlay_vao);
}
if (overlay->geometry_change) {
gint render_width, render_height;
gfloat x, y, image_width, image_height;
@ -524,19 +543,20 @@ gst_gl_overlay_callback (gint width, gint height, guint texture, gpointer stuff)
GL_STATIC_DRAW);
}
if (gl->GenVertexArrays) {
if (overlay->geometry_change)
_bind_buffer (overlay, overlay->overlay_vbo);
gl->BindVertexArray (overlay->overlay_vao);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
} else {
if (!gl->GenVertexArrays || overlay->geometry_change) {
_bind_buffer (overlay, overlay->overlay_vbo);
}
gl->BindTexture (GL_TEXTURE_2D, image_tex);
gst_gl_shader_set_uniform_1f (overlay->shader, "alpha", overlay->alpha);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->Enable (GL_BLEND);
gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl->BlendEquation (GL_FUNC_ADD);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
gl->Disable (GL_BLEND);
out:
if (gl->GenVertexArrays) {

View file

@ -67,6 +67,7 @@ struct _GstGLOverlay
GLuint overlay_vao;
GLuint vbo;
GLuint overlay_vbo;
GLuint vbo_indices;
GLuint attr_position;
GLuint attr_texture;
};

View file

@ -407,6 +407,11 @@ gst_gl_transformation_reset_gl (GstGLFilter * filter)
transformation->vertex_buffer = 0;
}
if (transformation->vbo_indices) {
gl->DeleteBuffers (1, &transformation->vbo_indices);
transformation->vbo_indices = 0;
}
if (transformation->shader) {
gst_object_unref (transformation->shader);
transformation->shader = NULL;
@ -464,6 +469,7 @@ gst_gl_transformation_filter_texture (GstGLFilter * filter, guint in_tex,
return TRUE;
}
static const GLushort indices[] = { 0, 1, 2, 3, 0 };
static void
_upload_vertices (GstGLTransformation * transformation)
@ -492,6 +498,7 @@ _bind_buffer (GstGLTransformation * transformation)
const GstGLFuncs *gl =
GST_GL_BASE_FILTER (transformation)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, transformation->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, transformation->vertex_buffer);
/* Load the vertex position */
@ -512,6 +519,7 @@ _unbind_buffer (GstGLTransformation * transformation)
const GstGLFuncs *gl =
GST_GL_BASE_FILTER (transformation)->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (transformation->attr_position);
@ -525,8 +533,6 @@ gst_gl_transformation_callback (gpointer stuff)
GstGLTransformation *transformation = GST_GL_TRANSFORMATION (filter);
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
GLushort indices[] = { 0, 1, 2, 3, 0 };
GLfloat temp_matrix[16];
gst_gl_context_clear_shader (GST_GL_BASE_FILTER (filter)->context);
@ -559,6 +565,12 @@ gst_gl_transformation_callback (gpointer stuff)
}
gl->GenBuffers (1, &transformation->vertex_buffer);
gl->GenBuffers (1, &transformation->vbo_indices);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, transformation->vbo_indices);
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
transformation->caps_change = TRUE;
}
@ -569,8 +581,11 @@ gst_gl_transformation_callback (gpointer stuff)
_upload_vertices (transformation);
_bind_buffer (transformation);
if (gl->GenVertexArrays)
if (gl->GenVertexArrays) {
gl->BindVertexArray (0);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
}
} else if (!gl->GenVertexArrays) {
_bind_buffer (transformation);
}

View file

@ -42,6 +42,7 @@ struct _GstGLTransformation
GstGLShader *shader;
GLuint vao;
GLuint vbo_indices;
GLuint vertex_buffer;
GLint attr_position;
GLint attr_texture;

View file

@ -733,6 +733,11 @@ _reset_gl (GstGLContext * context, GstGLVideoMixer * video_mixer)
video_mixer->vao = 0;
}
if (video_mixer->vbo_indices) {
gl->DeleteBuffers (1, &video_mixer->vbo_indices);
video_mixer->vbo_indices = 0;
}
gst_aggregator_iterate_sinkpads (GST_AGGREGATOR (video_mixer), _reset_pad_gl,
NULL);
}
@ -790,6 +795,21 @@ gst_gl_video_mixer_process_textures (GstGLMixer * mix, GPtrArray * frames,
return TRUE;
}
static const GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
static void
_init_vbo_indices (GstGLVideoMixer * mixer)
{
const GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable;
if (!mixer->vbo_indices) {
gl->GenBuffers (1, &mixer->vbo_indices);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, mixer->vbo_indices);
gl->BufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
}
}
static gboolean
_draw_checker_background (GstGLVideoMixer * video_mixer)
{
@ -797,10 +817,6 @@ _draw_checker_background (GstGLVideoMixer * video_mixer)
const GstGLFuncs *gl = GST_GL_BASE_MIXER (mixer)->context->gl_vtable;
gint attr_position_loc = 0;
const GLushort indices[] = {
0, 1, 2,
0, 2, 3
};
/* *INDENT-OFF* */
gfloat v_vertices[] = {
-1.0,-1.0,-1.0f,
@ -820,12 +836,15 @@ _draw_checker_background (GstGLVideoMixer * video_mixer)
attr_position_loc =
gst_gl_shader_get_attribute_location (video_mixer->checker, "a_position");
_init_vbo_indices (video_mixer);
if (!video_mixer->checker_vbo) {
gl->GenBuffers (1, &video_mixer->checker_vbo);
gl->BindBuffer (GL_ARRAY_BUFFER, video_mixer->checker_vbo);
gl->BufferData (GL_ARRAY_BUFFER, 4 * 3 * sizeof (GLfloat), v_vertices,
GL_STATIC_DRAW);
} else {
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, video_mixer->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, video_mixer->checker_vbo);
}
@ -834,9 +853,10 @@ _draw_checker_background (GstGLVideoMixer * video_mixer)
gl->EnableVertexAttribArray (attr_position_loc);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
gl->DisableVertexAttribArray (attr_position_loc);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
return TRUE;
@ -884,11 +904,6 @@ gst_gl_video_mixer_callback (gpointer stuff)
GLint attr_texture_loc = 0;
guint out_width, out_height;
const GLushort indices[] = {
0, 1, 2,
0, 2, 3
};
guint count = 0;
out_width = GST_VIDEO_INFO_WIDTH (&vagg->info);
@ -958,6 +973,8 @@ gst_gl_video_mixer_callback (gpointer stuff)
in_tex = frame->texture;
_init_vbo_indices (video_mixer);
if (pad->geometry_change || !pad->vertex_buffer) {
gint pad_width, pad_height;
gfloat w, h;
@ -993,6 +1010,7 @@ gst_gl_video_mixer_callback (gpointer stuff)
} else {
gl->BindBuffer (GL_ARRAY_BUFFER, pad->vertex_buffer);
}
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, video_mixer->vbo_indices);
gl->BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl->BlendEquation (GL_FUNC_ADD);
@ -1011,7 +1029,7 @@ gst_gl_video_mixer_callback (gpointer stuff)
gl->VertexAttribPointer (attr_texture_loc, 2, GL_FLOAT,
GL_FALSE, 5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat)));
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
++count;
}
@ -1022,6 +1040,7 @@ gst_gl_video_mixer_callback (gpointer stuff)
if (gl->GenVertexArrays)
gl->BindVertexArray (0);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindTexture (GL_TEXTURE_2D, 0);

View file

@ -64,6 +64,7 @@ struct _GstGLVideoMixer
GPtrArray *input_frames;
GLuint vao;
GLuint vbo_indices;
GLuint checker_vbo;
};

View file

@ -1219,6 +1219,7 @@ _bind_buffer (GstGLColorConvert * convert)
{
const GstGLFuncs *gl = convert->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, convert->priv->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, convert->priv->vertex_buffer);
/* Load the vertex position */
@ -1238,6 +1239,7 @@ _unbind_buffer (GstGLColorConvert * convert)
{
const GstGLFuncs *gl = convert->context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (convert->priv->attr_position);
@ -1378,23 +1380,20 @@ _init_convert (GstGLColorConvert * convert)
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
GL_STATIC_DRAW);
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);
if (gl->GenVertexArrays) {
_bind_buffer (convert);
gl->BindVertexArray (0);
}
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ELEMENT_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;
@ -1737,7 +1736,6 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert)
g_free (scale_name);
}
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, convert->priv->vbo_indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
if (gl->BindVertexArray)
@ -1748,8 +1746,6 @@ _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);

View file

@ -239,6 +239,11 @@ gst_gl_filter_gl_stop (GstGLBaseFilter * base_filter)
filter->vertex_buffer = 0;
}
if (filter->vbo_indices) {
gl->DeleteBuffers (1, &filter->vbo_indices);
filter->vbo_indices = 0;
}
if (filter->fbo != 0) {
gst_gl_context_del_fbo (context, filter->fbo, filter->depthbuffer);
}
@ -1057,6 +1062,8 @@ static const GLfloat vertices[] = {
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f
};
static const GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
/* *INDENT-ON* */
static void
@ -1065,6 +1072,7 @@ _bind_buffer (GstGLFilter * filter)
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
const GstGLFuncs *gl = context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, filter->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, filter->vertex_buffer);
_get_attributes (filter);
@ -1087,6 +1095,7 @@ _unbind_buffer (GstGLFilter * filter)
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
const GstGLFuncs *gl = context->gl_vtable;
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->DisableVertexAttribArray (filter->draw_attr_position_loc);
@ -1145,8 +1154,6 @@ gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
#endif
if (gst_gl_context_get_gl_api (context) & (GST_GL_API_GLES2 |
GST_GL_API_OPENGL3)) {
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
if (!filter->vertex_buffer) {
if (gl->GenVertexArrays) {
gl->GenVertexArrays (1, &filter->vao);
@ -1158,10 +1165,18 @@ gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
GL_STATIC_DRAW);
gl->GenBuffers (1, &filter->vbo_indices);
gl->BindBuffer (GL_ARRAY_BUFFER, filter->vbo_indices);
gl->BufferData (GL_ARRAY_BUFFER, sizeof (indices), indices,
GL_STATIC_DRAW);
if (gl->GenVertexArrays) {
_bind_buffer (filter);
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindVertexArray (0);
}
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
gl->BindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
}
if (gl->GenVertexArrays)
@ -1169,7 +1184,7 @@ gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
else
_bind_buffer (filter);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
if (gl->GenVertexArrays)
gl->BindVertexArray (0);

View file

@ -75,6 +75,7 @@ struct _GstGLFilter
GstGLShader *default_shader;
GLuint vao;
GLuint vbo_indices;
GLuint vertex_buffer;
GLint draw_attr_position_loc;
GLint draw_attr_texture_loc;