mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
gl: use gles2 shaders everywhere
This effectively limits a glfilter subclass to be > GL(ES) 2.0. rather than a possible GL 1.4.
This commit is contained in:
parent
6589c38d1a
commit
3ba30d42a4
23 changed files with 87 additions and 499 deletions
|
@ -48,7 +48,7 @@ gst_gl_effects_blur_callback_hconv (gint width, gint height, guint texture,
|
|||
GstGLEffects *effects = GST_GL_EFFECTS (data);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "hconv0",
|
||||
hconv7_fragment_source_gles2, hconv7_fragment_source_opengl))) {
|
||||
hconv7_fragment_source_gles2))) {
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
|
@ -82,7 +82,7 @@ gst_gl_effects_blur_callback_vconv (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "vconv0",
|
||||
vconv7_fragment_source_gles2, vconv7_fragment_source_opengl))) {
|
||||
vconv7_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_bulge_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "bulge",
|
||||
bulge_fragment_source_gles2, bulge_fragment_source_opengl);
|
||||
bulge_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_fisheye_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "fisheye",
|
||||
fisheye_fragment_source_gles2, fisheye_fragment_source_opengl);
|
||||
fisheye_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -37,8 +37,7 @@ gst_gl_effects_glow_step_one (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "luma_threshold",
|
||||
luma_threshold_fragment_source_gles2,
|
||||
luma_threshold_fragment_source_opengl);
|
||||
luma_threshold_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -71,7 +70,7 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "hconv7",
|
||||
hconv7_fragment_source_gles2, hconv7_fragment_source_opengl);
|
||||
hconv7_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -110,7 +109,7 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "vconv7",
|
||||
vconv7_fragment_source_gles2, vconv7_fragment_source_opengl);
|
||||
vconv7_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -145,7 +144,7 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "sum",
|
||||
sum_fragment_source_gles2, sum_fragment_source_opengl);
|
||||
sum_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -31,6 +31,7 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
|
||||
GstGLFuncs *gl = context->gl_vtable;
|
||||
GstGLShader *shader;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (USING_OPENGL (context)) {
|
||||
|
@ -38,32 +39,27 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture,
|
|||
gl->LoadIdentity ();
|
||||
}
|
||||
#endif
|
||||
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
|
||||
GstGLShader *shader =
|
||||
g_hash_table_lookup (effects->shaderstable, "identity0");
|
||||
|
||||
if (!shader) {
|
||||
shader = gst_gl_shader_new (context);
|
||||
g_hash_table_insert (effects->shaderstable, (gchar *) "identity0",
|
||||
shader);
|
||||
shader = g_hash_table_lookup (effects->shaderstable, "identity0");
|
||||
if (!shader) {
|
||||
shader = gst_gl_shader_new (context);
|
||||
g_hash_table_insert (effects->shaderstable, (gchar *) "identity0", shader);
|
||||
|
||||
if (!gst_gl_shader_compile_with_default_vf_and_check (shader,
|
||||
&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 identity shader, %s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
if (!gst_gl_shader_compile_with_default_vf_and_check (shader,
|
||||
&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 identity shader, %s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
}
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_laplacian_callback (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "conv0",
|
||||
conv9_fragment_source_gles2, conv9_fragment_source_opengl))) {
|
||||
conv9_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
static gfloat kernel[9] = { 0.0, -1.0, 0.0,
|
||||
-1.0, 4.0, -1.0,
|
||||
|
|
|
@ -35,8 +35,7 @@ gst_gl_effects_luma_to_curve (GstGLEffects * effects,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "luma_to_curve",
|
||||
luma_to_curve_fragment_source_gles2,
|
||||
luma_to_curve_fragment_source_opengl);
|
||||
luma_to_curve_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "mirror",
|
||||
mirror_fragment_source_gles2, mirror_fragment_source_opengl);
|
||||
mirror_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "rgb_to_curve",
|
||||
rgb_to_curve_fragment_source_gles2, rgb_to_curve_fragment_source_opengl);
|
||||
rgb_to_curve_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_sin_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "sin",
|
||||
sin_fragment_source_gles2, sin_fragment_source_opengl);
|
||||
sin_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,8 +34,7 @@ gst_gl_effects_sobel_callback_desaturate (gint width, gint height,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "desat0",
|
||||
desaturate_fragment_source_gles2,
|
||||
desaturate_fragment_source_opengl))) {
|
||||
desaturate_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
|
@ -65,8 +64,7 @@ gst_gl_effects_sobel_callback_hconv (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "hconv0",
|
||||
sep_sobel_hconv3_fragment_source_gles2,
|
||||
sep_sobel_hconv3_fragment_source_opengl))) {
|
||||
sep_sobel_hconv3_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
|
@ -97,8 +95,7 @@ gst_gl_effects_sobel_callback_vconv (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "vconv0",
|
||||
sep_sobel_vconv3_fragment_source_gles2,
|
||||
sep_sobel_vconv3_fragment_source_opengl))) {
|
||||
sep_sobel_vconv3_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
|
@ -129,8 +126,7 @@ gst_gl_effects_sobel_callback_length (gint width, gint height, guint texture,
|
|||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "len0",
|
||||
sep_sobel_length_fragment_source_gles2,
|
||||
sep_sobel_length_fragment_source_opengl))) {
|
||||
sep_sobel_length_fragment_source_gles2))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_square_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "square",
|
||||
square_fragment_source_gles2, square_fragment_source_opengl);
|
||||
square_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "squeeze",
|
||||
squeeze_fragment_source_gles2, squeeze_fragment_source_opengl);
|
||||
squeeze_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -91,19 +91,6 @@ const gchar *mirror_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Squeeze effect */
|
||||
const gchar *squeeze_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
" r = pow(r, 0.40)*1.3;"
|
||||
" normcoord = normcoord / r;"
|
||||
" texturecoord = (normcoord + 0.5);"
|
||||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
const gchar *squeeze_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -120,20 +107,6 @@ const gchar *squeeze_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Stretch Effect */
|
||||
const gchar *stretch_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
" normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
" normcoord *= 2.0 - smoothstep(0.0, 0.35, r);"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord);"
|
||||
" gl_FragColor = color * gl_Color;"
|
||||
"}";
|
||||
|
||||
const gchar *stretch_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -150,22 +123,6 @@ const gchar *stretch_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Light Tunnel effect */
|
||||
const gchar *tunnel_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
/* little trick with normalized coords to obtain a circle with
|
||||
* rect textures */
|
||||
" normcoord = (texturecoord - 0.5);"
|
||||
" float r = length(normcoord);"
|
||||
" normcoord *= clamp (r, 0.0, 0.275) / r;"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord); "
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
const gchar *tunnel_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -184,20 +141,6 @@ const gchar *tunnel_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* FishEye effect */
|
||||
const gchar *fisheye_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
" normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
" normcoord *= r * sqrt(2.0);"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord);"
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
const gchar *fisheye_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -214,27 +157,6 @@ const gchar *fisheye_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Twirl effect */
|
||||
const gchar *twirl_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
" normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
/* calculate rotation angle: maximum (about pi/2) at the origin and
|
||||
* gradually decrease it up to 0.6 of each quadrant */
|
||||
" float phi = (1.0 - smoothstep (0.0, 0.3, r)) * 1.6;"
|
||||
/* precalculate sin phi and cos phi, save some alu */
|
||||
" float s = sin(phi);"
|
||||
" float c = cos(phi);"
|
||||
/* rotate */
|
||||
" normcoord *= mat2(c, s, -s, c);"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord); "
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
const gchar *twirl_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -258,20 +180,6 @@ const gchar *twirl_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Bulge effect */
|
||||
const gchar *bulge_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
" normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
" normcoord *= smoothstep (-0.05, 0.25, r);"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord);"
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
const gchar *bulge_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -288,21 +196,6 @@ const gchar *bulge_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
/* Square Effect */
|
||||
const gchar *square_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].xy;"
|
||||
" vec2 normcoord;"
|
||||
" normcoord = texturecoord - 0.5;"
|
||||
" float r = length (normcoord);"
|
||||
" normcoord *= 1.0 + smoothstep(0.125, 0.25, abs(normcoord));"
|
||||
" normcoord /= 2.0; /* zoom amount */"
|
||||
" texturecoord = normcoord + 0.5;"
|
||||
" vec4 color = texture2D (tex, texturecoord);"
|
||||
" gl_FragColor = color * gl_Color;"
|
||||
"}";
|
||||
|
||||
const gchar *square_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -320,15 +213,6 @@ const gchar *square_fragment_source_gles2 =
|
|||
" gl_FragColor = texture2D (tex, texturecoord);"
|
||||
"}";
|
||||
|
||||
const gchar *luma_threshold_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].st;"
|
||||
" vec4 color = texture2D(tex, texturecoord);"
|
||||
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));" /* BT.709 (from orange book) */
|
||||
" gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
|
||||
"}";
|
||||
|
||||
const gchar *luma_threshold_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -342,19 +226,6 @@ const gchar *luma_threshold_fragment_source_gles2 =
|
|||
" gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_length_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform bool invert;"
|
||||
"void main () {"
|
||||
" vec4 g = texture2D (tex, gl_TexCoord[0].st);"
|
||||
/* restore black background with grey edges */
|
||||
" g -= vec4(0.5, 0.5, 0.0, 0.0);"
|
||||
" float len = length (g);"
|
||||
/* little trick to avoid IF operator */
|
||||
/* TODO: test if a standalone inverting pass is worth */
|
||||
" gl_FragColor = abs(vec4(vec3(float(invert) - len), 1.0));"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_length_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -372,14 +243,6 @@ const gchar *sep_sobel_length_fragment_source_gles2 =
|
|||
" gl_FragColor = abs(vec4(vec3(float(invert) - len), 1.0));"
|
||||
"}";
|
||||
|
||||
const gchar *desaturate_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec4 color = texture2D (tex, gl_TexCoord[0].st);"
|
||||
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
|
||||
" gl_FragColor = vec4(vec3(luma), color.a);"
|
||||
"}";
|
||||
|
||||
const gchar *desaturate_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -392,33 +255,6 @@ const gchar *desaturate_fragment_source_gles2 =
|
|||
" gl_FragColor = vec4(vec3(luma), color.a);"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_hconv3_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform float width;"
|
||||
"void main () {"
|
||||
" float w = 1.0 / width;"
|
||||
" vec2 texturecoord[3];"
|
||||
" texturecoord[1] = gl_TexCoord[0].st;"
|
||||
" texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
|
||||
" texturecoord[2] = texturecoord[1] + vec2(w, 0.0);"
|
||||
" float grad_kern[3];"
|
||||
" grad_kern[0] = 1.0;"
|
||||
" grad_kern[1] = 0.0;"
|
||||
" grad_kern[2] = -1.0;"
|
||||
" float blur_kern[3];"
|
||||
" blur_kern[0] = 0.25;"
|
||||
" blur_kern[1] = 0.5;"
|
||||
" blur_kern[2] = 0.25;"
|
||||
" int i;"
|
||||
" vec4 sum = vec4 (0.0);"
|
||||
" for (i = 0; i < 3; i++) { "
|
||||
" vec4 neighbor = texture2D(tex, texturecoord[i]); "
|
||||
" sum.r = neighbor.r * blur_kern[i] + sum.r;"
|
||||
" sum.g = neighbor.g * grad_kern[i] + sum.g;"
|
||||
" }"
|
||||
" gl_FragColor = sum + vec4(0.0, 0.5, 0.0, 0.0);"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_hconv3_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -450,33 +286,6 @@ const gchar *sep_sobel_hconv3_fragment_source_gles2 =
|
|||
" gl_FragColor = sum + vec4(0.0, 0.5, 0.0, 0.0);"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_vconv3_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform float height;"
|
||||
"void main () {"
|
||||
" float h = 1.0 / height;"
|
||||
" vec2 texturecoord[3];"
|
||||
" texturecoord[1] = gl_TexCoord[0].st;"
|
||||
" texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
|
||||
" texturecoord[2] = texturecoord[1] + vec2(0.0, h);"
|
||||
" float grad_kern[3];"
|
||||
" grad_kern[0] = 1.0;"
|
||||
" grad_kern[1] = 0.0;"
|
||||
" grad_kern[2] = -1.0;"
|
||||
" float blur_kern[3];"
|
||||
" blur_kern[0] = 0.25;"
|
||||
" blur_kern[1] = 0.5;"
|
||||
" blur_kern[2] = 0.25;"
|
||||
" int i;"
|
||||
" vec4 sum = vec4 (0.0);"
|
||||
" for (i = 0; i < 3; i++) { "
|
||||
" vec4 neighbor = texture2D(tex, texturecoord[i]); "
|
||||
" sum.r = neighbor.r * grad_kern[i] + sum.r;"
|
||||
" sum.g = neighbor.g * blur_kern[i] + sum.g;"
|
||||
" }"
|
||||
" gl_FragColor = sum + vec4(0.5, 0.0, 0.0, 0.0);"
|
||||
"}";
|
||||
|
||||
const gchar *sep_sobel_vconv3_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -508,30 +317,6 @@ const gchar *sep_sobel_vconv3_fragment_source_gles2 =
|
|||
" gl_FragColor = sum + vec4(0.5, 0.0, 0.0, 0.0);"
|
||||
"}";
|
||||
|
||||
/* horizontal convolution 7x7 */
|
||||
const gchar *hconv7_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform float kernel[7];"
|
||||
"uniform float gauss_width;"
|
||||
"void main () {"
|
||||
" float w = 1.0 / gauss_width;"
|
||||
" vec2 texturecoord[7];"
|
||||
" texturecoord[3] = gl_TexCoord[0].st;"
|
||||
" texturecoord[2] = texturecoord[3] - vec2(w, 0.0);"
|
||||
" texturecoord[1] = texturecoord[2] - vec2(w, 0.0);"
|
||||
" texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
|
||||
" texturecoord[4] = texturecoord[3] + vec2(w, 0.0);"
|
||||
" texturecoord[5] = texturecoord[4] + vec2(w, 0.0);"
|
||||
" texturecoord[6] = texturecoord[5] + vec2(w, 0.0);"
|
||||
" int i;"
|
||||
" vec4 sum = vec4 (0.0);"
|
||||
" for (i = 0; i < 7; i++) { "
|
||||
" vec4 neighbor = texture2D(tex, texturecoord[i]); "
|
||||
" sum += neighbor * kernel[i];"
|
||||
" }"
|
||||
" gl_FragColor = sum;"
|
||||
"}";
|
||||
|
||||
const gchar *hconv7_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -560,29 +345,6 @@ const gchar *hconv7_fragment_source_gles2 =
|
|||
"}";
|
||||
|
||||
/* vertical convolution 7x7 */
|
||||
const gchar *vconv7_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform float kernel[7];"
|
||||
"uniform float gauss_height;"
|
||||
"void main () {"
|
||||
" float h = 1.0 / gauss_height;"
|
||||
" vec2 texturecoord[7];"
|
||||
" texturecoord[3] = gl_TexCoord[0].st;"
|
||||
" texturecoord[2] = texturecoord[3] - vec2(0.0, h);"
|
||||
" texturecoord[1] = texturecoord[2] - vec2(0.0, h);"
|
||||
" texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
|
||||
" texturecoord[4] = texturecoord[3] + vec2(0.0, h);"
|
||||
" texturecoord[5] = texturecoord[4] + vec2(0.0, h);"
|
||||
" texturecoord[6] = texturecoord[5] + vec2(0.0, h);"
|
||||
" int i;"
|
||||
" vec4 sum = vec4 (0.0);"
|
||||
" for (i = 0; i < 7; i++) { "
|
||||
" vec4 neighbor = texture2D(tex, texturecoord[i]);"
|
||||
" sum += neighbor * kernel[i];"
|
||||
" }"
|
||||
" gl_FragColor = sum;"
|
||||
"}";
|
||||
|
||||
const gchar *vconv7_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -611,17 +373,6 @@ const gchar *vconv7_fragment_source_gles2 =
|
|||
"}";
|
||||
|
||||
/* TODO: support several blend modes */
|
||||
const gchar *sum_fragment_source_opengl =
|
||||
"uniform sampler2D base;"
|
||||
"uniform sampler2D blend;"
|
||||
"uniform float alpha;"
|
||||
"uniform float beta;"
|
||||
"void main () {"
|
||||
" vec4 basecolor = texture2D (base, gl_TexCoord[0].st);"
|
||||
" vec4 blendcolor = texture2D (blend, gl_TexCoord[0].st);"
|
||||
" gl_FragColor = alpha * basecolor + beta * blendcolor;"
|
||||
"}";
|
||||
|
||||
const gchar *sum_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -637,16 +388,6 @@ const gchar *sum_fragment_source_gles2 =
|
|||
" gl_FragColor = alpha * basecolor + beta * blendcolor;"
|
||||
"}";
|
||||
|
||||
const gchar *multiply_fragment_source_opengl =
|
||||
"uniform sampler2D base;"
|
||||
"uniform sampler2D blend;"
|
||||
"uniform float alpha;"
|
||||
"void main () {"
|
||||
" vec4 basecolor = texture2D (base, gl_TexCoord[0].st);"
|
||||
" vec4 blendcolor = texture2D (blend, gl_TexCoord[0].st);"
|
||||
" gl_FragColor = (1.0 - alpha) * basecolor + alpha * basecolor * blendcolor;"
|
||||
"}";
|
||||
|
||||
const gchar *multiply_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -662,17 +403,6 @@ const gchar *multiply_fragment_source_gles2 =
|
|||
"}";
|
||||
|
||||
/* lut operations, map luma to tex1d, see orange book (chapter 19) */
|
||||
const gchar *luma_to_curve_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform sampler1D curve;"
|
||||
"void main () {"
|
||||
" vec2 texturecoord = gl_TexCoord[0].st;"
|
||||
" vec4 color = texture2D (tex, texturecoord);"
|
||||
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
|
||||
" color = texture1D(curve, luma);"
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
const gchar *luma_to_curve_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -689,19 +419,6 @@ const gchar *luma_to_curve_fragment_source_gles2 =
|
|||
"}";
|
||||
|
||||
/* lut operations, map rgb to tex1d, see orange book (chapter 19) */
|
||||
const gchar *rgb_to_curve_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform sampler1D curve;"
|
||||
"void main () {"
|
||||
" vec4 color = texture2D (tex, gl_TexCoord[0].st);"
|
||||
" vec4 outcolor;"
|
||||
" outcolor.r = texture1D(curve, color.r).r;"
|
||||
" outcolor.g = texture1D(curve, color.g).g;"
|
||||
" outcolor.b = texture1D(curve, color.b).b;"
|
||||
" outcolor.a = color.a;"
|
||||
" gl_FragColor = outcolor;"
|
||||
"}";
|
||||
|
||||
const gchar *rgb_to_curve_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -719,31 +436,6 @@ const gchar *rgb_to_curve_fragment_source_gles2 =
|
|||
" gl_FragColor = outcolor;"
|
||||
"}";
|
||||
|
||||
const gchar *sin_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"void main () {"
|
||||
" vec4 color = texture2D (tex, vec2(gl_TexCoord[0].st));"
|
||||
" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
|
||||
/* calculate hue with the Preucil formula */
|
||||
" float cosh = color.r - 0.5*(color.g + color.b);"
|
||||
/* sqrt(3)/2 = 0.866 */
|
||||
" float sinh = 0.866*(color.g - color.b);"
|
||||
/* hue = atan2 h */
|
||||
" float sch = (1.0-sinh)*cosh;"
|
||||
/* ok this is a little trick I came up because I didn't find any
|
||||
* detailed proof of the Preucil formula. The issue is that tan(h) is
|
||||
* pi-periodic so the smoothstep thing gives both reds (h = 0) and
|
||||
* cyans (h = 180). I don't want to use atan since it requires
|
||||
* branching and doesn't work on i915. So take only the right half of
|
||||
* the circle where cosine is positive */
|
||||
/* take a slightly purple color trying to get rid of human skin reds */
|
||||
/* tanh = +-1.0 for h = +-45, where yellow=60, magenta=-60 */
|
||||
" float a = smoothstep (0.3, 1.0, sch);"
|
||||
" float b = smoothstep (-0.4, -0.1, sinh);"
|
||||
" float mix = a * b;"
|
||||
" gl_FragColor = color * mix + luma * (1.0 - mix);"
|
||||
"}";
|
||||
|
||||
const gchar *sin_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
@ -808,33 +500,6 @@ const gchar *difference_fragment_source =
|
|||
when this shader will be used in production be careful to hard code
|
||||
kernel into the shader and remove unneeded zero multiplications in
|
||||
the convolution */
|
||||
const gchar *conv9_fragment_source_opengl =
|
||||
"uniform sampler2D tex;"
|
||||
"uniform float kernel[9];"
|
||||
"uniform float width, height;"
|
||||
"uniform bool invert;"
|
||||
"void main () {"
|
||||
" float w = 1.0 / width;"
|
||||
" float h = 1.0 / height;"
|
||||
" vec2 texturecoord[9];"
|
||||
" texturecoord[4] = gl_TexCoord[0].st;" /* 0 0 */
|
||||
" texturecoord[5] = texturecoord[4] + vec2(w, 0.0);" /* 1 0 */
|
||||
" texturecoord[2] = texturecoord[5] - vec2(0.0, h);" /* 1 -1 */
|
||||
" texturecoord[1] = texturecoord[2] - vec2(w, 0.0);" /* 0 -1 */
|
||||
" texturecoord[0] = texturecoord[1] - vec2(w, 0.0);" /* -1 -1 */
|
||||
" texturecoord[3] = texturecoord[0] + vec2(0.0, h);" /* -1 0 */
|
||||
" texturecoord[6] = texturecoord[3] + vec2(0.0, h);" /* -1 1 */
|
||||
" texturecoord[7] = texturecoord[6] + vec2(w, 0.0);" /* 0 1 */
|
||||
" texturecoord[8] = texturecoord[7] + vec2(w, 0.0);" /* 1 1 */
|
||||
" int i;"
|
||||
" vec3 sum = vec3 (0.0);"
|
||||
" for (i = 0; i < 9; i++) { "
|
||||
" vec4 neighbor = texture2D (tex, texturecoord[i]);"
|
||||
" sum += neighbor.xyz * kernel[i];"
|
||||
" }"
|
||||
" gl_FragColor = vec4 (abs(sum - vec3(float(invert))), 1.0);"
|
||||
"}";
|
||||
|
||||
const gchar *conv9_fragment_source_gles2 =
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
|
|
|
@ -21,28 +21,6 @@
|
|||
#ifndef __GST_GL_EFFECTS_SOURCES_H__
|
||||
#define __GST_GL_EFFECTS_SOURCES_H__
|
||||
|
||||
extern const gchar *mirror_fragment_source_opengl;
|
||||
extern const gchar *squeeze_fragment_source_opengl;
|
||||
extern const gchar *stretch_fragment_source_opengl;
|
||||
extern const gchar *fisheye_fragment_source_opengl;
|
||||
extern const gchar *twirl_fragment_source_opengl;
|
||||
extern const gchar *bulge_fragment_source_opengl;
|
||||
extern const gchar *tunnel_fragment_source_opengl;
|
||||
extern const gchar *square_fragment_source_opengl;
|
||||
extern const gchar *luma_threshold_fragment_source_opengl;
|
||||
extern const gchar *hconv7_fragment_source_opengl;
|
||||
extern const gchar *vconv7_fragment_source_opengl;
|
||||
extern const gchar *sum_fragment_source_opengl;
|
||||
extern const gchar *luma_to_curve_fragment_source_opengl;
|
||||
extern const gchar *rgb_to_curve_fragment_source_opengl;
|
||||
extern const gchar *sin_fragment_source_opengl;
|
||||
extern const gchar *desaturate_fragment_source_opengl;
|
||||
extern const gchar *sep_sobel_hconv3_fragment_source_opengl;
|
||||
extern const gchar *sep_sobel_vconv3_fragment_source_opengl;
|
||||
extern const gchar *sep_sobel_length_fragment_source_opengl;
|
||||
extern const gchar *multiply_fragment_source_opengl;
|
||||
extern const gchar *conv9_fragment_source_opengl;
|
||||
|
||||
extern const gchar *mirror_fragment_source_gles2;
|
||||
extern const gchar *squeeze_fragment_source_gles2;
|
||||
extern const gchar *stretch_fragment_source_gles2;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_stretch_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "stretch",
|
||||
stretch_fragment_source_gles2, stretch_fragment_source_opengl);
|
||||
stretch_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_tunnel_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "tunnel",
|
||||
tunnel_fragment_source_gles2, tunnel_fragment_source_opengl);
|
||||
tunnel_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -34,7 +34,7 @@ gst_gl_effects_twirl_callback (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "twirl",
|
||||
twirl_fragment_source_gles2, twirl_fragment_source_opengl);
|
||||
twirl_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -49,7 +49,7 @@ gst_gl_effects_xray_step_two (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "hconv7",
|
||||
hconv7_fragment_source_gles2, hconv7_fragment_source_opengl);
|
||||
hconv7_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -88,7 +88,7 @@ gst_gl_effects_xray_step_three (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "vconv7",
|
||||
vconv7_fragment_source_gles2, vconv7_fragment_source_opengl);
|
||||
vconv7_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -124,7 +124,7 @@ gst_gl_effects_xray_desaturate (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "desaturate",
|
||||
desaturate_fragment_source_gles2, desaturate_fragment_source_opengl);
|
||||
desaturate_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -156,8 +156,7 @@ gst_gl_effects_xray_sobel_hconv (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "sobel_hconv3",
|
||||
sep_sobel_hconv3_fragment_source_gles2,
|
||||
sep_sobel_hconv3_fragment_source_opengl);
|
||||
sep_sobel_hconv3_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -191,8 +190,7 @@ gst_gl_effects_xray_sobel_vconv (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "sobel_vconv3",
|
||||
sep_sobel_vconv3_fragment_source_gles2,
|
||||
sep_sobel_vconv3_fragment_source_opengl);
|
||||
sep_sobel_vconv3_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -226,8 +224,7 @@ gst_gl_effects_xray_sobel_length (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "sobel_length",
|
||||
sep_sobel_length_fragment_source_gles2,
|
||||
sep_sobel_length_fragment_source_opengl);
|
||||
sep_sobel_length_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
@ -262,7 +259,7 @@ gst_gl_effects_xray_step_five (gint width, gint height, guint texture,
|
|||
GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
shader = gst_gl_effects_get_fragment_shader (effects, "multiply",
|
||||
multiply_fragment_source_gles2, multiply_fragment_source_opengl);
|
||||
multiply_fragment_source_gles2);
|
||||
|
||||
if (!shader)
|
||||
return;
|
||||
|
|
|
@ -96,39 +96,43 @@ gst_gl_differencematte_init_gl_resources (GstGLFilter * filter)
|
|||
gst_gl_shader_new (GST_GL_BASE_FILTER (filter)->context);
|
||||
}
|
||||
|
||||
if (!gst_gl_shader_compile_and_check (differencematte->shader[0],
|
||||
difference_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (differencematte->shader
|
||||
[0], difference_fragment_source, &filter->draw_attr_position_loc,
|
||||
&filter->draw_attr_texture_loc)) {
|
||||
gst_gl_context_set_error (GST_GL_BASE_FILTER (differencematte)->context,
|
||||
"Failed to initialize difference shader");
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND,
|
||||
("%s", gst_gl_context_get_error ()), (NULL));
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gst_gl_shader_compile_and_check (differencematte->shader[1],
|
||||
hconv7_fragment_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) {
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (differencematte->shader
|
||||
[1], hconv7_fragment_source_gles2, &filter->draw_attr_position_loc,
|
||||
&filter->draw_attr_texture_loc)) {
|
||||
gst_gl_context_set_error (GST_GL_BASE_FILTER (differencematte)->context,
|
||||
"Failed to initialize hconv7 shader");
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND,
|
||||
("%s", gst_gl_context_get_error ()), (NULL));
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gst_gl_shader_compile_and_check (differencematte->shader[2],
|
||||
vconv7_fragment_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) {
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (differencematte->shader
|
||||
[2], vconv7_fragment_source_gles2, &filter->draw_attr_position_loc,
|
||||
&filter->draw_attr_texture_loc)) {
|
||||
gst_gl_context_set_error (GST_GL_BASE_FILTER (differencematte)->context,
|
||||
"Failed to initialize vconv7 shader");
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND,
|
||||
("%s", gst_gl_context_get_error ()), (NULL));
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gst_gl_shader_compile_and_check (differencematte->shader[3],
|
||||
texture_interp_fragment_source, GST_GL_SHADER_FRAGMENT_SOURCE)) {
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (differencematte->shader
|
||||
[3], texture_interp_fragment_source, &filter->draw_attr_position_loc,
|
||||
&filter->draw_attr_texture_loc)) {
|
||||
gst_gl_context_set_error (GST_GL_BASE_FILTER (differencematte)->context,
|
||||
"Failed to initialize interp shader");
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND,
|
||||
("%s", gst_gl_context_get_error ()), (NULL));
|
||||
GST_ELEMENT_ERROR (differencematte, RESOURCE, NOT_FOUND, ("%s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +194,8 @@ gst_gl_differencematte_class_init (GstGLDifferenceMatteClass * klass)
|
|||
"Saves a background frame and replace it with a pixbuf",
|
||||
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
||||
|
||||
GST_GL_BASE_FILTER_CLASS (klass)->supported_gl_api = GST_GL_API_OPENGL;
|
||||
GST_GL_BASE_FILTER_CLASS (klass)->supported_gl_api =
|
||||
GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -536,8 +536,7 @@ gst_gl_effects_filter_texture (GstGLFilter * filter, guint in_tex,
|
|||
|
||||
GstGLShader *
|
||||
gst_gl_effects_get_fragment_shader (GstGLEffects * effects,
|
||||
const gchar * shader_name, const gchar * shader_source_gles2,
|
||||
const gchar * shader_source_opengl)
|
||||
const gchar * shader_name, const gchar * shader_source_gles2)
|
||||
{
|
||||
GstGLShader *shader = NULL;
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
@ -546,40 +545,24 @@ gst_gl_effects_get_fragment_shader (GstGLEffects * effects,
|
|||
shader = g_hash_table_lookup (effects->shaderstable, shader_name);
|
||||
|
||||
if (!shader) {
|
||||
if (!shader && (USING_GLES2 (context) || USING_OPENGL3 (context))) {
|
||||
shader = gst_gl_shader_new (context);
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (shader,
|
||||
shader_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 %s shader, %s",
|
||||
shader_name, gst_gl_context_get_error ()), (NULL));
|
||||
gst_object_unref (shader);
|
||||
shader = NULL;
|
||||
}
|
||||
shader = gst_gl_shader_new (context);
|
||||
if (!gst_gl_shader_compile_with_default_v_and_check (shader,
|
||||
shader_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 %s shader, %s",
|
||||
shader_name, gst_gl_context_get_error ()), (NULL));
|
||||
gst_object_unref (shader);
|
||||
shader = NULL;
|
||||
}
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (!shader && USING_OPENGL (context)) {
|
||||
shader = gst_gl_shader_new (context);
|
||||
if (!gst_gl_shader_compile_and_check (shader,
|
||||
shader_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) {
|
||||
gst_gl_context_set_error (context, "Failed to initialize %s shader",
|
||||
shader_name);
|
||||
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s",
|
||||
gst_gl_context_get_error ()), (NULL));
|
||||
gst_object_unref (shader);
|
||||
shader = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!shader)
|
||||
return NULL;
|
||||
|
||||
g_hash_table_insert (effects->shaderstable, (gchar *) shader_name, shader);
|
||||
}
|
||||
|
||||
if (!shader)
|
||||
return NULL;
|
||||
|
||||
g_hash_table_insert (effects->shaderstable, (gchar *) shader_name, shader);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ struct _GstGLEffectsClass
|
|||
GType gst_gl_effects_get_type (void);
|
||||
gboolean gst_gl_effects_register_filters (GstPlugin *, GstRank);
|
||||
GstGLShader* gst_gl_effects_get_fragment_shader (GstGLEffects *effects,
|
||||
const gchar * shader_name, const gchar * shader_source_gles2, const gchar * shader_source_opengl);
|
||||
const gchar * shader_name, const gchar * shader_source_gles2);
|
||||
|
||||
void gst_gl_effects_identity (GstGLEffects *effects);
|
||||
void gst_gl_effects_mirror (GstGLEffects *effects);
|
||||
|
|
|
@ -1124,37 +1124,7 @@ gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture,
|
|||
|
||||
GST_DEBUG ("drawing texture:%u dimensions:%ux%u", texture, width, height);
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) {
|
||||
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->ActiveTexture (GL_TEXTURE0);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
|
||||
gl->EnableClientState (GL_VERTEX_ARRAY);
|
||||
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
||||
|
||||
gl->ClientActiveTexture (GL_TEXTURE0);
|
||||
gl->EnableClientState (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_context_get_gl_api (context) & (GST_GL_API_GLES2 |
|
||||
GST_GL_API_OPENGL3)) {
|
||||
{
|
||||
if (!filter->vertex_buffer) {
|
||||
if (gl->GenVertexArrays) {
|
||||
gl->GenVertexArrays (1, &filter->vao);
|
||||
|
|
Loading…
Reference in a new issue