From 646aaf4cd3b2f7d27e671a3bdd81dc21235e6b33 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Sun, 15 Jun 2008 18:31:12 +0000 Subject: [PATCH] [105/906] up Sobel filter and gl/glew version checker git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@518 93df14bb-0f41-7a43-8087-d3e2a2f0e464 --- gst-libs/gst/gl/gstgldisplay.c | 22 ++++++++-------- gst/gl/gstglfilteredge.c | 46 +++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c index bef4b8d231..5c6545d404 100644 --- a/gst-libs/gst/gl/gstgldisplay.c +++ b/gst-libs/gst/gl/gstgldisplay.c @@ -496,24 +496,26 @@ gst_gl_display_glutCreateWindow (GstGLDisplay *display) else { //OpenGL > 2.1.0 and Glew > 1.5.0 - GString* opengl_version = g_string_new ((gchar*) glGetString (GL_VERSION)); - gboolean check_versions = g_str_has_prefix (opengl_version->str, "2.1"); - GString* glew_version = g_string_new ((gchar*) glewGetString (GLEW_VERSION)); - check_versions = check_versions && g_str_has_prefix (glew_version->str, "1.5"); + GString* opengl_version = g_string_truncate (g_string_new ((gchar*) glGetString (GL_VERSION)), 3); + gfloat opengl_version_f = 0.0f; + GString* glew_version = g_string_truncate (g_string_new ((gchar*) glewGetString (GLEW_VERSION)), 3); + gfloat glew_version_f = 0.0f; + sscanf(opengl_version->str, "%f", &opengl_version_f); + sscanf(glew_version->str, "%f", &glew_version_f); - GST_DEBUG ("GL_VERSION: %s", opengl_version->str); - GST_DEBUG ("GLEW_VERSION: %s", glew_version->str); + GST_DEBUG ("GL_VERSION: %s", glGetString (GL_VERSION)); + GST_DEBUG ("GLEW_VERSION: %s", glewGetString (GLEW_VERSION)); - GST_DEBUG ("GL_VENDOR: %s\n", glGetString (GL_VENDOR)); - GST_DEBUG ("GL_RENDERER: %s\n", glGetString (GL_RENDERER)); + GST_DEBUG ("GL_VENDOR: %s", glGetString (GL_VENDOR)); + GST_DEBUG ("GL_RENDERER: %s", glGetString (GL_RENDERER)); g_string_free (opengl_version, TRUE); g_string_free (glew_version, TRUE); - if (!check_versions) + if (opengl_version_f < 1.4f || glew_version_f < 1.4) { - GST_DEBUG ("Required OpenGL > 2.1.0 and Glew > 1.5.0"); + GST_DEBUG ("Required OpenGL >= 1.4.0 and Glew >= 1.4.0"); g_assert_not_reached (); } } diff --git a/gst/gl/gstglfilteredge.c b/gst/gl/gstglfilteredge.c index 9ee6289eb7..f0d920847b 100644 --- a/gst/gl/gstglfilteredge.c +++ b/gst/gl/gstglfilteredge.c @@ -30,7 +30,7 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); static const GstElementDetails element_details = GST_ELEMENT_DETAILS ("OpenGL edge filter", "Filter/Effect", - "Edge detection", + "Edge detection using GLSL", "Julien Isorce "); enum @@ -86,12 +86,33 @@ gst_gl_filter_edge_init (GstGLFilterEdge* filter, filter->textShader = "uniform sampler2DRect tex;\n" "void main(void) {\n" - " float r,g,b,y;\n" - " vec2 nxy=gl_TexCoord[0].xy;\n" - " r=texture2DRect(tex,nxy).r;\n" - " g=texture2DRect(tex,nxy).g;\n" - " b=texture2DRect(tex,nxy).b;\n" - " gl_FragColor=vec4(b,g,r,1.0);\n" + " const int N = 8;\n" + " const vec2 delta[N] = vec2[N](\n" + " vec2( -1.0, -1.0 ),\n" + " vec2( -1.0 , 0.0 ),\n" + " vec2( -1.0 , 1.0 ),\n" + " vec2( 0.0 , 1.0 ),\n" + " vec2( 1.0 , 1.0 ),\n" + " vec2( 1.0 , 0.0 ),\n" + " vec2( 1.0 , -1.0 ),\n" + " vec2( 0.0 , -1.0 )\n" + " );\n" + " const float filterH[N] = float[N]\n" + " (-1.0, 0.0, 1.0, 2.0, 1.0, 0.0, -1.0, -2.0);\n" + " const float filterV[N] = float[N]\n" + " (-1.0, -2.0, -1.0, 0.0, 1.0, 2.0, 1.0, 0.0);\n" + " float gH = 0.0;\n" + " float gV = 0.0;\n" + " int i;\n" + " vec2 nxy = gl_TexCoord[0].xy;\n" + " for (i = 0; i < N; i++) {\n" + " vec4 vcolor_i = texture2DRect(tex, nxy + delta[i]);\n" + " float gray_i = (vcolor_i.r + vcolor_i.g + vcolor_i.b) / 3.0;\n" + " gH += gH + filterH[i] * gray_i;\n" + " gV += gV + filterV[i] * gray_i;\n" + " }\n" + " float g = sqrt(gH * gH + gV * gV) / 8.0;\n" + " gl_FragColor = vec4(g, g, g, 1.0);\n" "}\n"; } @@ -186,13 +207,14 @@ gst_gl_filter_edge_callback (guint width, guint height, guint texture, GLhandleA glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture); glBegin (GL_QUADS); - glTexCoord2i (width, 0); - glVertex2f (1.0f, 1.0f); glTexCoord2i (0, 0); - glVertex2f (-1.0f, 1.0f); - glTexCoord2i (0, height); glVertex2f (-1.0f, -1.0f); - glTexCoord2i (width, height); + glTexCoord2i (width, 0); glVertex2f (1.0f, -1.0f); + glTexCoord2i (width, height); + glVertex2f (1.0f, 1.0f); + glTexCoord2i (0, height); + glVertex2f (-1.0f, 1.0f); + glEnd (); }