mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
[212/906] add a glbumper (bump mapping filter through GLSL) that exposes how to use both vertex and fragment shaders
This commit is contained in:
parent
e7f1a18965
commit
10853e1c2f
9 changed files with 65 additions and 13 deletions
|
@ -216,7 +216,8 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
|
|||
display->ouput_texture_height = 0;
|
||||
|
||||
//action gen and del shader
|
||||
display->gen_text_shader = NULL;
|
||||
display->gen_shader_fragment_source = NULL;
|
||||
display->gen_shader_vertex_source = NULL;
|
||||
display->gen_shader = NULL;
|
||||
display->del_shader = NULL;
|
||||
|
||||
|
@ -1566,7 +1567,7 @@ gst_gl_display_thread_use_fbo (GstGLDisplay *display)
|
|||
|
||||
glDrawBuffer(GL_NONE);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
@ -1606,11 +1607,28 @@ gst_gl_display_thread_gen_shader (GstGLDisplay* display)
|
|||
glutSetWindow (display->glutWinId);
|
||||
if (GLEW_ARB_fragment_shader)
|
||||
{
|
||||
gboolean isAlive = TRUE;
|
||||
GError *error = NULL;
|
||||
|
||||
display->gen_shader = gst_gl_shader_new ();
|
||||
|
||||
if (!gst_gl_shader_compile_and_check (display->gen_shader,
|
||||
display->gen_text_shader,
|
||||
GST_GL_SHADER_FRAGMENT_SOURCE))
|
||||
if (display->gen_shader_vertex_source)
|
||||
gst_gl_shader_set_vertex_source(display->gen_shader, display->gen_shader_vertex_source);
|
||||
|
||||
if (display->gen_shader_fragment_source)
|
||||
gst_gl_shader_set_fragment_source(display->gen_shader, display->gen_shader_fragment_source);
|
||||
|
||||
gst_gl_shader_compile (display->gen_shader, &error);
|
||||
if (error)
|
||||
{
|
||||
g_warning ("%s", error->message);
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
gst_gl_shader_use (NULL);
|
||||
isAlive = FALSE;
|
||||
}
|
||||
|
||||
if (!isAlive)
|
||||
{
|
||||
display->isAlive = FALSE;
|
||||
g_object_unref (G_OBJECT (display->gen_shader));
|
||||
|
@ -2254,13 +2272,20 @@ gst_gl_display_del_fbo (GstGLDisplay* display, GLuint fbo,
|
|||
|
||||
/* Called by glfilter */
|
||||
void
|
||||
gst_gl_display_gen_shader (GstGLDisplay* display, const gchar* textShader, GstGLShader** shader)
|
||||
gst_gl_display_gen_shader (GstGLDisplay* display,
|
||||
const gchar* shader_vertex_source,
|
||||
const gchar* shader_fragment_source,
|
||||
GstGLShader** shader)
|
||||
{
|
||||
gst_gl_display_lock (display);
|
||||
display->gen_text_shader = textShader;
|
||||
display->gen_shader_vertex_source = shader_vertex_source;
|
||||
display->gen_shader_fragment_source = shader_fragment_source;
|
||||
gst_gl_display_post_message (GST_GL_DISPLAY_ACTION_GEN_SHADER, display);
|
||||
g_cond_wait (display->cond_gen_shader, display->mutex);
|
||||
*shader = display->gen_shader;
|
||||
display->gen_shader = NULL;
|
||||
display->gen_shader_vertex_source = NULL;
|
||||
display->gen_shader_fragment_source = NULL;
|
||||
gst_gl_display_unlock (display);
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,8 @@ struct _GstGLDisplay {
|
|||
GLuint ouput_texture_height;
|
||||
|
||||
//action gen and del shader
|
||||
const gchar* gen_text_shader;
|
||||
const gchar* gen_shader_fragment_source;
|
||||
const gchar* gen_shader_vertex_source;
|
||||
GstGLShader* gen_shader;
|
||||
GstGLShader* del_shader;
|
||||
|
||||
|
@ -300,7 +301,10 @@ gboolean gst_gl_display_use_fbo (GstGLDisplay* display, gint texture_fbo_width,
|
|||
void gst_gl_display_del_fbo (GstGLDisplay* display, GLuint fbo,
|
||||
GLuint depth_buffer);
|
||||
|
||||
void gst_gl_display_gen_shader (GstGLDisplay* display, const gchar* textShader, GstGLShader** shader);
|
||||
void gst_gl_display_gen_shader (GstGLDisplay* display,
|
||||
const gchar* shader_vertex_source,
|
||||
const gchar* shader_fragment_source,
|
||||
GstGLShader** shader);
|
||||
void gst_gl_display_del_shader (GstGLDisplay* display, GstGLShader* shader);
|
||||
|
||||
void gst_gl_display_set_window_id (GstGLDisplay* display, gulong winId);
|
||||
|
|
|
@ -490,6 +490,18 @@ gst_gl_shader_set_uniform_1i (GstGLShader * shader, const gchar * name,
|
|||
glUniform1iARB (location, value);
|
||||
}
|
||||
|
||||
GLint
|
||||
gst_gl_shader_get_attribute_location (GstGLShader * shader, const gchar *name)
|
||||
{
|
||||
GstGLShaderPrivate *priv;
|
||||
|
||||
priv = shader->priv;
|
||||
|
||||
g_return_val_if_fail (priv->program_handle != 0, 0);
|
||||
|
||||
return glGetUniformLocationARB (priv->program_handle, name);
|
||||
}
|
||||
|
||||
GQuark
|
||||
gst_gl_shader_error_quark (void)
|
||||
{
|
||||
|
|
|
@ -89,6 +89,8 @@ void gst_gl_shader_set_uniform_1i (GstGLShader *shader, const gchar *name, gint
|
|||
void gst_gl_shader_set_uniform_1f (GstGLShader *shader, const gchar *name, gfloat value);
|
||||
void gst_gl_shader_set_uniform_1fv (GstGLShader *shader, const gchar *name, guint count, gfloat * value);
|
||||
|
||||
GLint gst_gl_shader_get_attribute_location (GstGLShader *shader, const gchar *name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_GL_SHADER_H__ */
|
||||
|
|
|
@ -25,6 +25,8 @@ libgstopengl_la_SOURCES = \
|
|||
gltestsrc.h \
|
||||
gstgltestsrc.c \
|
||||
gstgltestsrc.h \
|
||||
gstglbumper.c \
|
||||
gstglbumber.h \
|
||||
gstgleffects.c \
|
||||
gstgleffects.h \
|
||||
effects/gstgleffectssources.c \
|
||||
|
|
|
@ -220,10 +220,10 @@ gst_gl_filterblur_init_shader (GstGLFilter* filter)
|
|||
GstGLFilterBlur* blur_filter = GST_GL_FILTERBLUR (filter);
|
||||
|
||||
//blocking call, wait the opengl thread has compiled the shader
|
||||
gst_gl_display_gen_shader (filter->display, hconv9_fragment_source, &blur_filter->shader0);
|
||||
gst_gl_display_gen_shader (filter->display, 0, hconv9_fragment_source, &blur_filter->shader0);
|
||||
|
||||
//blocking call, wait the opengl thread has compiled the shader
|
||||
gst_gl_display_gen_shader (filter->display, vconv9_fragment_source, &blur_filter->shader1);
|
||||
gst_gl_display_gen_shader (filter->display, 0, vconv9_fragment_source, &blur_filter->shader1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -150,7 +150,7 @@ gst_gl_filter_laplacian_init_shader (GstGLFilter* filter)
|
|||
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
|
||||
|
||||
//blocking call, wait the opengl thread has compiled the shader
|
||||
gst_gl_display_gen_shader (filter->display, convolution_fragment_source, &laplacian_filter->shader);
|
||||
gst_gl_display_gen_shader (filter->display, 0, convolution_fragment_source, &laplacian_filter->shader);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -291,7 +291,7 @@ static void init_pixbuf_texture (GstGLDisplay *display, gpointer data)
|
|||
glGenTextures (1, &pixbufoverlay->pbuftexture);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixbufoverlay->pbuftexture);
|
||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
|
||||
pixbufoverlay->width, pixbufoverlay->height, 0,
|
||||
(gint)pixbufoverlay->width, (gint)pixbufoverlay->height, 0,
|
||||
gdk_pixbuf_get_has_alpha (pixbufoverlay->pixbuf) ? GL_RGBA : GL_RGB,
|
||||
GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (pixbufoverlay->pixbuf));
|
||||
}
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
#include "gstglimagesink.h"
|
||||
#include "gstglcolorscale.h"
|
||||
#include "gstgleffects.h"
|
||||
#include "gstglbumper.h"
|
||||
|
||||
GType gst_gl_effects_get_type (void);
|
||||
GType gst_gl_bumper_get_type (void);
|
||||
GType gst_gl_filter_app_get_type (void);
|
||||
GType gst_gl_filter_cube_get_type (void);
|
||||
GType gst_gl_filterblur_get_type (void);
|
||||
|
@ -83,6 +85,11 @@ plugin_init (GstPlugin * plugin)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "glbumper",
|
||||
GST_RANK_NONE, gst_gl_bumper_get_type())) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "glfilterblur",
|
||||
GST_RANK_NONE, gst_gl_filterblur_get_type())) {
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue