1 /*
2 * GStreamer
3 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "../gstgleffects.h"
25
26 static gboolean kernel_ready = FALSE;
27 static float gauss_kernel[7];
28
29 void
gst_gl_effects_glow(GstGLEffects * effects)30 gst_gl_effects_glow (GstGLEffects * effects)
31 {
32 const GstGLFuncs *gl = GST_GL_BASE_FILTER (effects)->context->gl_vtable;
33 GstGLFilter *filter = GST_GL_FILTER (effects);
34 GstGLShader *shader;
35
36 if (!kernel_ready) {
37 fill_gaussian_kernel (gauss_kernel, 7, 10.0);
38 kernel_ready = TRUE;
39 }
40
41 /* threshold */
42 shader = gst_gl_effects_get_fragment_shader (effects, "luma_threshold",
43 luma_threshold_fragment_source_gles2);
44 gst_gl_filter_render_to_target_with_shader (filter, effects->intexture,
45 effects->midtexture[0], shader);
46
47 /* blur */
48 shader = gst_gl_effects_get_fragment_shader (effects, "hconv7",
49 hconv7_fragment_source_gles2);
50 gst_gl_shader_use (shader);
51 gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel);
52 gst_gl_shader_set_uniform_1f (shader, "gauss_width",
53 GST_VIDEO_INFO_WIDTH (&filter->out_info));
54 gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[0],
55 effects->midtexture[1], shader);
56
57 shader = gst_gl_effects_get_fragment_shader (effects, "vconv7",
58 vconv7_fragment_source_gles2);
59 gst_gl_shader_use (shader);
60 gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel);
61 gst_gl_shader_set_uniform_1f (shader, "gauss_height",
62 GST_VIDEO_INFO_HEIGHT (&filter->out_info));
63 gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[1],
64 effects->midtexture[2], shader);
65
66 /* add blurred luma to intexture */
67 shader = gst_gl_effects_get_fragment_shader (effects, "sum",
68 sum_fragment_source_gles2);
69 gst_gl_shader_use (shader);
70
71 gl->ActiveTexture (GL_TEXTURE2);
72 gl->BindTexture (GL_TEXTURE_2D,
73 gst_gl_memory_get_texture_id (effects->intexture));
74
75 gst_gl_shader_set_uniform_1f (shader, "alpha", 1.0f);
76 gst_gl_shader_set_uniform_1i (shader, "base", 2);
77
78 gl->ActiveTexture (GL_TEXTURE1);
79 gl->BindTexture (GL_TEXTURE_2D,
80 gst_gl_memory_get_texture_id (effects->midtexture[2]));
81
82 gst_gl_shader_set_uniform_1f (shader, "beta", (gfloat) 1 / 3.5f);
83 gst_gl_shader_set_uniform_1i (shader, "blend", 1);
84 gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[2],
85 effects->outtexture, shader);
86 }
87