mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
glcolorconvert: add support for gl3
This commit is contained in:
parent
f0d2346c52
commit
a32f29f2ce
2 changed files with 91 additions and 23 deletions
|
@ -392,6 +392,12 @@ static const gchar text_vertex_shader[] =
|
||||||
" v_texcoord = a_texcoord; \n"
|
" v_texcoord = a_texcoord; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
|
static const GLfloat vertices[] = {
|
||||||
|
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 0.0f, 1.0f, 1.0f
|
||||||
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
struct ConvertInfo
|
struct ConvertInfo
|
||||||
|
@ -415,6 +421,11 @@ struct _GstGLColorConvertPrivate
|
||||||
|
|
||||||
GstGLMemory *in_tex[GST_VIDEO_MAX_PLANES];
|
GstGLMemory *in_tex[GST_VIDEO_MAX_PLANES];
|
||||||
GstGLMemory *out_tex[GST_VIDEO_MAX_PLANES];
|
GstGLMemory *out_tex[GST_VIDEO_MAX_PLANES];
|
||||||
|
|
||||||
|
GLuint vao;
|
||||||
|
GLuint vertex_buffer;
|
||||||
|
GLuint attr_position;
|
||||||
|
GLuint attr_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_gl_color_convert_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_color_convert_debug);
|
||||||
|
@ -486,6 +497,22 @@ gst_gl_color_convert_finalize (GObject * object)
|
||||||
G_OBJECT_CLASS (gst_gl_color_convert_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_gl_color_convert_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_reset_gl (GstGLContext * context, GstGLColorConvert * convert)
|
||||||
|
{
|
||||||
|
const GstGLFuncs *gl = context->gl_vtable;
|
||||||
|
|
||||||
|
if (convert->priv->vao) {
|
||||||
|
gl->DeleteVertexArrays (1, &convert->priv->vao);
|
||||||
|
convert->priv->vao = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (convert->priv->vertex_buffer) {
|
||||||
|
gl->DeleteBuffers (1, &convert->priv->vertex_buffer);
|
||||||
|
convert->priv->vertex_buffer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_color_convert_reset (GstGLColorConvert * convert)
|
gst_gl_color_convert_reset (GstGLColorConvert * convert)
|
||||||
{
|
{
|
||||||
|
@ -511,6 +538,11 @@ gst_gl_color_convert_reset (GstGLColorConvert * convert)
|
||||||
gst_object_unref (convert->shader);
|
gst_object_unref (convert->shader);
|
||||||
convert->shader = NULL;
|
convert->shader = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (convert->context) {
|
||||||
|
gst_gl_context_thread_add (convert->context,
|
||||||
|
(GstGLContextThreadFunc) _reset_gl, convert);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -998,6 +1030,36 @@ _GRAY_to_RGB (GstGLColorConvert * convert)
|
||||||
g_free (pixel_order);
|
g_free (pixel_order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_bind_buffer (GstGLColorConvert * convert)
|
||||||
|
{
|
||||||
|
const GstGLFuncs *gl = convert->context->gl_vtable;
|
||||||
|
|
||||||
|
gl->BindBuffer (GL_ARRAY_BUFFER, convert->priv->vertex_buffer);
|
||||||
|
|
||||||
|
/* Load the vertex position */
|
||||||
|
gl->VertexAttribPointer (convert->priv->attr_position, 3, GL_FLOAT, GL_FALSE,
|
||||||
|
5 * sizeof (GLfloat), (void *) 0);
|
||||||
|
|
||||||
|
/* Load the texture coordinate */
|
||||||
|
gl->VertexAttribPointer (convert->priv->attr_texture, 2, GL_FLOAT, GL_FALSE,
|
||||||
|
5 * sizeof (GLfloat), (void *) (3 * sizeof (GLfloat)));
|
||||||
|
|
||||||
|
gl->EnableVertexAttribArray (convert->priv->attr_position);
|
||||||
|
gl->EnableVertexAttribArray (convert->priv->attr_texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_unbind_buffer (GstGLColorConvert * convert)
|
||||||
|
{
|
||||||
|
const GstGLFuncs *gl = convert->context->gl_vtable;
|
||||||
|
|
||||||
|
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
gl->DisableVertexAttribArray (convert->priv->attr_position);
|
||||||
|
gl->DisableVertexAttribArray (convert->priv->attr_texture);
|
||||||
|
}
|
||||||
|
|
||||||
/* Called in the gl thread */
|
/* Called in the gl thread */
|
||||||
static gboolean
|
static gboolean
|
||||||
_init_convert (GstGLColorConvert * convert)
|
_init_convert (GstGLColorConvert * convert)
|
||||||
|
@ -1080,9 +1142,9 @@ _init_convert (GstGLColorConvert * convert)
|
||||||
if (!res)
|
if (!res)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
convert->shader_attr_position_loc =
|
convert->priv->attr_position =
|
||||||
gst_gl_shader_get_attribute_location (convert->shader, "a_position");
|
gst_gl_shader_get_attribute_location (convert->shader, "a_position");
|
||||||
convert->shader_attr_texture_loc =
|
convert->priv->attr_texture =
|
||||||
gst_gl_shader_get_attribute_location (convert->shader, "a_texcoord");
|
gst_gl_shader_get_attribute_location (convert->shader, "a_texcoord");
|
||||||
|
|
||||||
gst_gl_shader_use (convert->shader);
|
gst_gl_shader_use (convert->shader);
|
||||||
|
@ -1121,6 +1183,25 @@ _init_convert (GstGLColorConvert * convert)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!convert->priv->vertex_buffer) {
|
||||||
|
if (gl->GenVertexArrays) {
|
||||||
|
gl->GenVertexArrays (1, &convert->priv->vao);
|
||||||
|
gl->BindVertexArray (convert->priv->vao);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl->GenBuffers (1, &convert->priv->vertex_buffer);
|
||||||
|
gl->BindBuffer (GL_ARRAY_BUFFER, convert->priv->vertex_buffer);
|
||||||
|
gl->BufferData (GL_ARRAY_BUFFER, 4 * 5 * sizeof (GLfloat), vertices,
|
||||||
|
GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
if (gl->GenVertexArrays) {
|
||||||
|
_bind_buffer (convert);
|
||||||
|
gl->BindVertexArray (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl->BindBuffer (GL_ARRAY_BUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
convert->initted = TRUE;
|
convert->initted = TRUE;
|
||||||
|
@ -1405,16 +1486,6 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert)
|
||||||
|
|
||||||
GLint viewport_dim[4];
|
GLint viewport_dim[4];
|
||||||
|
|
||||||
const GLfloat vVertices[] = { 1.0f, -1.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
-1.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
-1.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
||||||
|
|
||||||
GLenum multipleRT[] = {
|
GLenum multipleRT[] = {
|
||||||
|
@ -1453,13 +1524,10 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert)
|
||||||
|
|
||||||
gst_gl_shader_use (convert->shader);
|
gst_gl_shader_use (convert->shader);
|
||||||
|
|
||||||
gl->VertexAttribPointer (convert->shader_attr_position_loc, 3,
|
if (gl->BindVertexArray)
|
||||||
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
gl->BindVertexArray (convert->priv->vao);
|
||||||
gl->VertexAttribPointer (convert->shader_attr_texture_loc, 2,
|
else
|
||||||
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
_bind_buffer (convert);
|
||||||
|
|
||||||
gl->EnableVertexAttribArray (convert->shader_attr_position_loc);
|
|
||||||
gl->EnableVertexAttribArray (convert->shader_attr_texture_loc);
|
|
||||||
|
|
||||||
for (i = c_info->in_n_textures - 1; i >= 0; i--) {
|
for (i = c_info->in_n_textures - 1; i >= 0; i--) {
|
||||||
gchar *scale_name = g_strdup_printf ("tex_scale%u", i);
|
gchar *scale_name = g_strdup_printf ("tex_scale%u", i);
|
||||||
|
@ -1480,8 +1548,10 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert)
|
||||||
|
|
||||||
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
||||||
|
|
||||||
gl->DisableVertexAttribArray (convert->shader_attr_position_loc);
|
if (gl->BindVertexArray)
|
||||||
gl->DisableVertexAttribArray (convert->shader_attr_texture_loc);
|
gl->BindVertexArray (0);
|
||||||
|
else
|
||||||
|
_unbind_buffer (convert);
|
||||||
|
|
||||||
if (gl->DrawBuffer)
|
if (gl->DrawBuffer)
|
||||||
gl->DrawBuffer (GL_NONE);
|
gl->DrawBuffer (GL_NONE);
|
||||||
|
|
|
@ -61,8 +61,6 @@ struct _GstGLColorConvert
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
GLuint depth_buffer;
|
GLuint depth_buffer;
|
||||||
GstGLShader *shader;
|
GstGLShader *shader;
|
||||||
GLint shader_attr_position_loc;
|
|
||||||
GLint shader_attr_texture_loc;
|
|
||||||
|
|
||||||
/* <private> */
|
/* <private> */
|
||||||
GstGLColorConvertPrivate *priv;
|
GstGLColorConvertPrivate *priv;
|
||||||
|
|
Loading…
Reference in a new issue