[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
@ -216,7 +216,8 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
|
|||||||
display->ouput_texture_height = 0;
|
display->ouput_texture_height = 0;
|
||||||
|
|
||||||
//action gen and del shader
|
//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->gen_shader = NULL;
|
||||||
display->del_shader = NULL;
|
display->del_shader = NULL;
|
||||||
|
|
||||||
@ -1566,7 +1567,7 @@ gst_gl_display_thread_use_fbo (GstGLDisplay *display)
|
|||||||
|
|
||||||
glDrawBuffer(GL_NONE);
|
glDrawBuffer(GL_NONE);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
@ -1606,11 +1607,28 @@ gst_gl_display_thread_gen_shader (GstGLDisplay* display)
|
|||||||
glutSetWindow (display->glutWinId);
|
glutSetWindow (display->glutWinId);
|
||||||
if (GLEW_ARB_fragment_shader)
|
if (GLEW_ARB_fragment_shader)
|
||||||
{
|
{
|
||||||
|
gboolean isAlive = TRUE;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
display->gen_shader = gst_gl_shader_new ();
|
display->gen_shader = gst_gl_shader_new ();
|
||||||
|
|
||||||
if (!gst_gl_shader_compile_and_check (display->gen_shader,
|
if (display->gen_shader_vertex_source)
|
||||||
display->gen_text_shader,
|
gst_gl_shader_set_vertex_source(display->gen_shader, display->gen_shader_vertex_source);
|
||||||
GST_GL_SHADER_FRAGMENT_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;
|
display->isAlive = FALSE;
|
||||||
g_object_unref (G_OBJECT (display->gen_shader));
|
g_object_unref (G_OBJECT (display->gen_shader));
|
||||||
@ -2254,13 +2272,20 @@ gst_gl_display_del_fbo (GstGLDisplay* display, GLuint fbo,
|
|||||||
|
|
||||||
/* Called by glfilter */
|
/* Called by glfilter */
|
||||||
void
|
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);
|
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);
|
gst_gl_display_post_message (GST_GL_DISPLAY_ACTION_GEN_SHADER, display);
|
||||||
g_cond_wait (display->cond_gen_shader, display->mutex);
|
g_cond_wait (display->cond_gen_shader, display->mutex);
|
||||||
*shader = display->gen_shader;
|
*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);
|
gst_gl_display_unlock (display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,8 @@ struct _GstGLDisplay {
|
|||||||
GLuint ouput_texture_height;
|
GLuint ouput_texture_height;
|
||||||
|
|
||||||
//action gen and del shader
|
//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* gen_shader;
|
||||||
GstGLShader* del_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,
|
void gst_gl_display_del_fbo (GstGLDisplay* display, GLuint fbo,
|
||||||
GLuint depth_buffer);
|
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_del_shader (GstGLDisplay* display, GstGLShader* shader);
|
||||||
|
|
||||||
void gst_gl_display_set_window_id (GstGLDisplay* display, gulong winId);
|
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);
|
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
|
GQuark
|
||||||
gst_gl_shader_error_quark (void)
|
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_1f (GstGLShader *shader, const gchar *name, gfloat value);
|
||||||
void gst_gl_shader_set_uniform_1fv (GstGLShader *shader, const gchar *name, guint count, 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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_GL_SHADER_H__ */
|
#endif /* __GST_GL_SHADER_H__ */
|
||||||
|
@ -25,6 +25,8 @@ libgstopengl_la_SOURCES = \
|
|||||||
gltestsrc.h \
|
gltestsrc.h \
|
||||||
gstgltestsrc.c \
|
gstgltestsrc.c \
|
||||||
gstgltestsrc.h \
|
gstgltestsrc.h \
|
||||||
|
gstglbumper.c \
|
||||||
|
gstglbumber.h \
|
||||||
gstgleffects.c \
|
gstgleffects.c \
|
||||||
gstgleffects.h \
|
gstgleffects.h \
|
||||||
effects/gstgleffectssources.c \
|
effects/gstgleffectssources.c \
|
||||||
|
@ -220,10 +220,10 @@ gst_gl_filterblur_init_shader (GstGLFilter* filter)
|
|||||||
GstGLFilterBlur* blur_filter = GST_GL_FILTERBLUR (filter);
|
GstGLFilterBlur* blur_filter = GST_GL_FILTERBLUR (filter);
|
||||||
|
|
||||||
//blocking call, wait the opengl thread has compiled the shader
|
//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
|
//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
|
static void
|
||||||
|
@ -150,7 +150,7 @@ gst_gl_filter_laplacian_init_shader (GstGLFilter* filter)
|
|||||||
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
|
GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
|
||||||
|
|
||||||
//blocking call, wait the opengl thread has compiled the shader
|
//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
|
static gboolean
|
||||||
|
@ -291,7 +291,7 @@ static void init_pixbuf_texture (GstGLDisplay *display, gpointer data)
|
|||||||
glGenTextures (1, &pixbufoverlay->pbuftexture);
|
glGenTextures (1, &pixbufoverlay->pbuftexture);
|
||||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixbufoverlay->pbuftexture);
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixbufoverlay->pbuftexture);
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
|
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,
|
gdk_pixbuf_get_has_alpha (pixbufoverlay->pixbuf) ? GL_RGBA : GL_RGB,
|
||||||
GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (pixbufoverlay->pixbuf));
|
GL_UNSIGNED_BYTE, gdk_pixbuf_get_pixels (pixbufoverlay->pixbuf));
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,10 @@
|
|||||||
#include "gstglimagesink.h"
|
#include "gstglimagesink.h"
|
||||||
#include "gstglcolorscale.h"
|
#include "gstglcolorscale.h"
|
||||||
#include "gstgleffects.h"
|
#include "gstgleffects.h"
|
||||||
|
#include "gstglbumper.h"
|
||||||
|
|
||||||
GType gst_gl_effects_get_type (void);
|
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_app_get_type (void);
|
||||||
GType gst_gl_filter_cube_get_type (void);
|
GType gst_gl_filter_cube_get_type (void);
|
||||||
GType gst_gl_filterblur_get_type (void);
|
GType gst_gl_filterblur_get_type (void);
|
||||||
@ -83,6 +85,11 @@ plugin_init (GstPlugin * plugin)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gst_element_register (plugin, "glbumper",
|
||||||
|
GST_RANK_NONE, gst_gl_bumper_get_type())) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!gst_element_register (plugin, "glfilterblur",
|
if (!gst_element_register (plugin, "glfilterblur",
|
||||||
GST_RANK_NONE, gst_gl_filterblur_get_type())) {
|
GST_RANK_NONE, gst_gl_filterblur_get_type())) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user