Commit 9294e843 authored by Anton Obzhirov's avatar Anton Obzhirov Committed by Tim-Philipp Müller

gleffects: port all effects to GLES2.0

https://bugzilla.gnome.org/show_bug.cgi?id=745955
parent 79d34000
......@@ -17,6 +17,17 @@ libgstopengl_la_SOURCES = \
effects/gstgleffectidentity.c \
effects/gstgleffectmirror.c \
effects/gstgleffectsqueeze.c \
effects/gstgleffectstretch.c \
effects/gstgleffectfisheye.c \
effects/gstgleffecttwirl.c \
effects/gstgleffectbulge.c \
effects/gstgleffecttunnel.c \
effects/gstgleffectsquare.c \
effects/gstgleffectlumatocurve.c \
effects/gstgleffectrgbtocurve.c \
effects/gstgleffectsin.c \
effects/gstgleffectxray.c \
effects/gstgleffectglow.c \
gstglcolorscale.c \
gstglmixer.c \
gstglvideomixer.c \
......@@ -52,18 +63,7 @@ libgstopengl_la_SOURCES += \
gstgldeinterlace.c \
gltestsrc.c \
gstgltestsrc.c \
gstglmosaic.c \
effects/gstgleffectstretch.c \
effects/gstgleffecttunnel.c \
effects/gstgleffectfisheye.c \
effects/gstgleffecttwirl.c \
effects/gstgleffectbulge.c \
effects/gstgleffectsquare.c \
effects/gstgleffectlumatocurve.c \
effects/gstgleffectrgbtocurve.c \
effects/gstgleffectsin.c \
effects/gstgleffectglow.c \
effects/gstgleffectxray.c
gstglmosaic.c
noinst_HEADERS += \
gstglfilterblur.h \
......
......@@ -33,23 +33,18 @@ gst_gl_effects_bulge_callback (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "bulge0");
shader = gst_gl_effects_get_fragment_shader (effects, "bulge",
bulge_fragment_source_gles2, bulge_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "bulge0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
bulge_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize bulge shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -59,9 +54,6 @@ gst_gl_effects_bulge_callback (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......
......@@ -33,23 +33,18 @@ gst_gl_effects_fisheye_callback (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "fisheye0");
shader = gst_gl_effects_get_fragment_shader (effects, "fisheye",
fisheye_fragment_source_gles2, fisheye_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "fisheye0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
fisheye_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize fisheye shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -59,9 +54,6 @@ gst_gl_effects_fisheye_callback (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......
......@@ -36,24 +36,19 @@ gst_gl_effects_glow_step_one (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "glow0");
shader = gst_gl_effects_get_fragment_shader (effects, "luma_threshold",
luma_threshold_fragment_source_gles2,
luma_threshold_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "glow0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
luma_threshold_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context,
"Failed to initialize luma threshold shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -76,28 +71,22 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "glow1");
shader = gst_gl_effects_get_fragment_shader (effects, "hconv7",
hconv7_fragment_source_gles2, hconv7_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "glow1", shader);
}
if (!shader)
return;
if (!kernel_ready) {
fill_gaussian_kernel (gauss_kernel, 7, 10.0);
kernel_ready = TRUE;
}
if (!gst_gl_shader_compile_and_check (shader,
hconv7_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize hconv7 shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
return;
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#endif
gst_gl_shader_use (shader);
......@@ -108,7 +97,7 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (shader, "tex", 1);
gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel);
gst_gl_shader_set_uniform_1f (shader, "height", height);
gst_gl_shader_set_uniform_1f (shader, "gauss_width", height);
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......@@ -123,23 +112,18 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "glow2");
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "glow2", shader);
}
shader = gst_gl_effects_get_fragment_shader (effects, "vconv7",
vconv7_fragment_source_gles2, vconv7_fragment_source_opengl);
if (!gst_gl_shader_compile_and_check (shader,
vconv7_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize vcon7 shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -150,7 +134,7 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (shader, "tex", 1);
gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel);
gst_gl_shader_set_uniform_1f (shader, "width", width);
gst_gl_shader_set_uniform_1f (shader, "gauss_height", width);
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......@@ -165,23 +149,18 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "glow3");
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "glow3", shader);
}
shader = gst_gl_effects_get_fragment_shader (effects, "sum",
sum_fragment_source_gles2, sum_fragment_source_opengl);
if (!gst_gl_shader_compile_and_check (shader,
sum_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize sum shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -190,7 +169,7 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture,
gl->BindTexture (GL_TEXTURE_2D, effects->intexture);
gl->Disable (GL_TEXTURE_2D);
gst_gl_shader_set_uniform_1f (shader, "alpha", 1.0);
gst_gl_shader_set_uniform_1f (shader, "alpha", 1.0f);
gst_gl_shader_set_uniform_1i (shader, "base", 2);
gl->ActiveTexture (GL_TEXTURE1);
......@@ -212,11 +191,14 @@ gst_gl_effects_glow (GstGLEffects * effects)
/* threshold */
gst_gl_filter_render_to_target (filter, TRUE, effects->intexture,
effects->midtexture[0], gst_gl_effects_glow_step_one, effects);
/* blur */
gst_gl_filter_render_to_target (filter, FALSE, effects->midtexture[0],
effects->midtexture[1], gst_gl_effects_glow_step_two, effects);
gst_gl_filter_render_to_target (filter, FALSE, effects->midtexture[1],
effects->midtexture[2], gst_gl_effects_glow_step_three, effects);
/* add blurred luma to intexture */
gst_gl_filter_render_to_target (filter, FALSE, effects->midtexture[2],
effects->outtexture, gst_gl_effects_glow_step_four, effects);
......
......@@ -23,12 +23,6 @@
#include "../gstgleffects.h"
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
static void
gst_gl_effects_identity_callback (gint width, gint height, guint texture,
gpointer data)
......
......@@ -34,41 +34,53 @@ gst_gl_effects_luma_to_curve (GstGLEffects * effects,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "lumamap0");
shader = gst_gl_effects_get_fragment_shader (effects, "luma_to_curve",
luma_to_curve_fragment_source_gles2,
luma_to_curve_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "lumamap0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
luma_to_curve_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context,
"Failed to initialize luma to curve shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
if (effects->curve[curve_index] == 0) {
/* this parameters are needed to have a right, predictable, mapping */
gl->GenTextures (1, &effects->curve[curve_index]);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
gl->TexImage1D (GL_TEXTURE_1D, 0, curve->bytes_per_pixel,
curve->width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
gl->Disable (GL_TEXTURE_1D);
gl->TexImage1D (GL_TEXTURE_1D, 0, curve->bytes_per_pixel,
curve->width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
gl->Disable (GL_TEXTURE_1D);
}
#endif
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
curve->width, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
gl->Disable (GL_TEXTURE_2D);
}
}
gl->ActiveTexture (GL_TEXTURE2);
......@@ -79,13 +91,26 @@ gst_gl_effects_luma_to_curve (GstGLEffects * effects,
gl->Disable (GL_TEXTURE_2D);
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gl->Disable (GL_TEXTURE_1D);
gl->Disable (GL_TEXTURE_1D);
}
#endif
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gl->Disable (GL_TEXTURE_2D);
}
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......
......@@ -23,12 +23,6 @@
#include "../gstgleffects.h"
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
static void
gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
gpointer data)
......@@ -39,37 +33,12 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "mirror0");
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "mirror0", shader);
shader = gst_gl_effects_get_fragment_shader (effects, "mirror",
mirror_fragment_source_gles2, mirror_fragment_source_opengl);
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
if (!gst_gl_shader_compile_with_default_v_and_check (shader,
mirror_fragment_source_gles2, &filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) {
/* gst gl context error is already set */
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("Failed to initialize squeeze shader, %s",
gst_gl_context_get_error ()), (NULL));
return;
}
}
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
if (!gst_gl_shader_compile_and_check (shader,
mirror_fragment_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context,
"Failed to initialize mirror shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
return;
}
if (!shader)
return;
}
#endif
}
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
......
......@@ -34,41 +34,51 @@ gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "rgbmap0");
shader = gst_gl_effects_get_fragment_shader (effects, "rgb_to_curve",
rgb_to_curve_fragment_source_gles2, rgb_to_curve_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "rgbmap0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
rgb_to_curve_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context,
"Failed to initialize rgb to curve shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
if (effects->curve[curve_index] == 0) {
/* this parameters are needed to have a right, predictable, mapping */
gl->GenTextures (1, &effects->curve[curve_index]);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
gl->TexImage1D (GL_TEXTURE_1D, 0, curve->bytes_per_pixel,
curve->width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
gl->Disable (GL_TEXTURE_1D);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl->TexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
gl->TexImage1D (GL_TEXTURE_1D, 0, GL_RGB,
curve->width, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
gl->Disable (GL_TEXTURE_1D);
}
#endif
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
curve->width, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
gl->Disable (GL_TEXTURE_2D);
}
}
gl->ActiveTexture (GL_TEXTURE0);
......@@ -79,13 +89,26 @@ gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
gl->Disable (GL_TEXTURE_2D);
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_1D);
gl->BindTexture (GL_TEXTURE_1D, effects->curve[curve_index]);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gl->Disable (GL_TEXTURE_1D);
gl->Disable (GL_TEXTURE_1D);
}
#endif
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
gl->ActiveTexture (GL_TEXTURE1);
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
gst_gl_shader_set_uniform_1i (shader, "curve", 1);
gl->Disable (GL_TEXTURE_2D);
}
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......
......@@ -33,23 +33,18 @@ gst_gl_effects_sin_callback (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "sin0");
shader = gst_gl_effects_get_fragment_shader (effects, "sin",
sin_fragment_source_gles2, sin_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "sin0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
sin_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize sin shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......
......@@ -33,23 +33,18 @@ gst_gl_effects_square_callback (gint width, gint height, guint texture,
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
GstGLFuncs *gl = context->gl_vtable;
shader = g_hash_table_lookup (effects->shaderstable, "square0");
shader = gst_gl_effects_get_fragment_shader (effects, "square",
square_fragment_source_gles2, square_fragment_source_opengl);
if (!shader) {
shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "square0", shader);
}
if (!gst_gl_shader_compile_and_check (shader,
square_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize square shader");
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL));
if (!shader)
return;
}
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) {
gl->MatrixMode (GL_PROJECTION);
gl->LoadIdentity ();
}
#endif
gst_gl_shader_use (shader);
......@@ -59,9 +54,6 @@ gst_gl_effects_square_callback (gint width, gint height, guint texture,
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
gst_gl_filter_draw_texture (filter, texture, width, height);
}
......