mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-13 02:45:35 +00:00
[874/906] filter: implement draw_texture for GLES2
(taken from gleffects)
This commit is contained in:
parent
2eb7938db9
commit
8daa7693cf
2 changed files with 70 additions and 36 deletions
|
@ -1089,8 +1089,8 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize,
|
||||||
in_height = out_height;
|
in_height = out_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_LOG ("rendering to target. in:%ux%u out:%ux%u", in_width, in_height,
|
GST_LOG ("rendering to target. in %u, %ux%u out %u, %ux%u", input, in_width,
|
||||||
out_width, out_height);
|
in_height, target, out_width, out_height);
|
||||||
|
|
||||||
gst_gl_context_use_fbo (filter->context,
|
gst_gl_context_use_fbo (filter->context,
|
||||||
out_width, out_height,
|
out_width, out_height,
|
||||||
|
@ -1099,22 +1099,23 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize,
|
||||||
in_width, 0, in_height, GST_GL_DISPLAY_PROJECTION_ORTHO2D, data);
|
in_width, 0, in_height, GST_GL_DISPLAY_PROJECTION_ORTHO2D, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GST_GL_HAVE_OPENGL
|
|
||||||
static void
|
static void
|
||||||
_draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff)
|
_draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff)
|
||||||
{
|
{
|
||||||
GstGLFilter *filter = GST_GL_FILTER (stuff);
|
GstGLFilter *filter = GST_GL_FILTER (stuff);
|
||||||
GstGLFuncs *gl = filter->context->gl_vtable;
|
GstGLFuncs *gl = filter->context->gl_vtable;
|
||||||
|
|
||||||
gl->MatrixMode (GL_PROJECTION);
|
#if GST_GL_HAVE_OPENGL
|
||||||
gl->LoadIdentity ();
|
if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_OPENGL) {
|
||||||
|
gl->MatrixMode (GL_PROJECTION);
|
||||||
|
gl->LoadIdentity ();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
gst_gl_shader_use (filter->default_shader);
|
gst_gl_shader_use (filter->default_shader);
|
||||||
|
|
||||||
gl->ActiveTexture (GL_TEXTURE1);
|
gl->ActiveTexture (GL_TEXTURE1);
|
||||||
gl->Enable (GL_TEXTURE_2D);
|
|
||||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||||
gl->Disable (GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1);
|
gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1);
|
||||||
gst_gl_shader_set_uniform_1f (filter->default_shader, "width", width);
|
gst_gl_shader_set_uniform_1f (filter->default_shader, "width", width);
|
||||||
|
@ -1143,9 +1144,6 @@ void
|
||||||
gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
|
gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter,
|
||||||
gboolean resize, GLuint input, GLuint target, GstGLShader * shader)
|
gboolean resize, GLuint input, GLuint target, GstGLShader * shader)
|
||||||
{
|
{
|
||||||
g_return_if_fail (gst_gl_context_get_gl_api (filter->context) &
|
|
||||||
GST_GL_API_OPENGL);
|
|
||||||
|
|
||||||
filter->default_shader = shader;
|
filter->default_shader = shader;
|
||||||
gst_gl_filter_render_to_target (filter, resize, input, target,
|
gst_gl_filter_render_to_target (filter, resize, input, target,
|
||||||
_draw_with_shader_cb, filter);
|
_draw_with_shader_cb, filter);
|
||||||
|
@ -1164,36 +1162,69 @@ void
|
||||||
gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
|
gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
|
||||||
guint width, guint height)
|
guint width, guint height)
|
||||||
{
|
{
|
||||||
GstGLFuncs *gl = filter->context->gl_vtable;
|
GstGLContext *context = filter->context;
|
||||||
|
GstGLFuncs *gl = context->gl_vtable;
|
||||||
GLfloat verts[] = { -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
-1.0f, 1.0f
|
|
||||||
};
|
|
||||||
GLfloat texcoords[] = { 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
GST_DEBUG ("drawing texture:%u dimensions:%ux%u", texture, width, height);
|
GST_DEBUG ("drawing texture:%u dimensions:%ux%u", texture, width, height);
|
||||||
|
|
||||||
gl->ActiveTexture (GL_TEXTURE0);
|
#if GST_GL_HAVE_OPENGL
|
||||||
gl->Enable (GL_TEXTURE_2D);
|
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
|
||||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
GLfloat verts[] = { -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f
|
||||||
|
};
|
||||||
|
GLfloat texcoords[] = { 0.0f, 0.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
0.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
gl->ClientActiveTexture (GL_TEXTURE0);
|
gl->ActiveTexture (GL_TEXTURE0);
|
||||||
|
|
||||||
gl->EnableClientState (GL_VERTEX_ARRAY);
|
gl->Enable (GL_TEXTURE_2D);
|
||||||
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
gl->ClientActiveTexture (GL_TEXTURE0);
|
||||||
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
|
|
||||||
|
|
||||||
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
||||||
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
gl->DisableClientState (GL_VERTEX_ARRAY);
|
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
||||||
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
|
||||||
|
|
||||||
|
gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
|
||||||
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
||||||
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if GST_GL_HAVE_GLES2
|
||||||
|
if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) {
|
||||||
|
const GLfloat vVertices[] = {
|
||||||
|
-1.0f, -1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
1.0, -1.0f, 0.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
||||||
|
|
||||||
|
/* glClear (GL_COLOR_BUFFER_BIT); */
|
||||||
|
|
||||||
|
/* Load the vertex position */
|
||||||
|
gl->VertexAttribPointer (filter->draw_attr_position_loc, 3, GL_FLOAT,
|
||||||
|
GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
||||||
|
|
||||||
|
/* Load the texture coordinate */
|
||||||
|
gl->VertexAttribPointer (filter->draw_attr_texture_loc, 2, GL_FLOAT,
|
||||||
|
GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
||||||
|
|
||||||
|
gl->EnableVertexAttribArray (filter->draw_attr_position_loc);
|
||||||
|
gl->EnableVertexAttribArray (filter->draw_attr_texture_loc);
|
||||||
|
|
||||||
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* GST_GL_HAVE_OPENGL */
|
|
||||||
|
|
|
@ -82,6 +82,11 @@ struct _GstGLFilter
|
||||||
|
|
||||||
GstGLContext *context;
|
GstGLContext *context;
|
||||||
GstGLContext *other_context;
|
GstGLContext *other_context;
|
||||||
|
|
||||||
|
#if GST_GL_HAVE_GLES2
|
||||||
|
GLint draw_attr_position_loc;
|
||||||
|
GLint draw_attr_texture_loc;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,12 +130,10 @@ gboolean gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
|
||||||
void gst_gl_filter_render_to_target (GstGLFilter *filter, gboolean resize, GLuint input,
|
void gst_gl_filter_render_to_target (GstGLFilter *filter, gboolean resize, GLuint input,
|
||||||
GLuint target, GLCB func, gpointer data);
|
GLuint target, GLCB func, gpointer data);
|
||||||
|
|
||||||
#if GST_GL_HAVE_OPENGL
|
|
||||||
void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize,
|
void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize,
|
||||||
GLuint input, GLuint target, GstGLShader *shader);
|
GLuint input, GLuint target, GstGLShader *shader);
|
||||||
|
|
||||||
void gst_gl_filter_draw_texture (GstGLFilter *filter, GLuint texture, guint width, guint height);
|
void gst_gl_filter_draw_texture (GstGLFilter *filter, GLuint texture, guint width, guint height);
|
||||||
#endif /* GST_GL_HAVE_OPENGL */
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue