[128/906] add GstGLShader stuffs in the vs8 project, fix laplacian fragment code to make it compile on ATI, and fix check function about Opengl and Glew version

This commit is contained in:
Julien Isorce 2008-07-18 21:55:00 +02:00 committed by Matthew Waters
parent aeadf6bc0e
commit 44ec9c01dd
2 changed files with 36 additions and 17 deletions

View file

@ -670,24 +670,22 @@ gst_gl_display_thread_create_context (GstGLDisplay *display)
GString* opengl_version = g_string_truncate (g_string_new ((gchar*) glGetString (GL_VERSION)), 3); GString* opengl_version = g_string_truncate (g_string_new ((gchar*) glGetString (GL_VERSION)), 3);
gint opengl_version_major = 0; gint opengl_version_major = 0;
gint opengl_version_minor = 0; gint opengl_version_minor = 0;
GString* glew_version = g_string_truncate (g_string_new ((gchar*) glewGetString (GLEW_VERSION)), 3);
gint glew_version_major = 0;
gint glew_version_minor = 0;
sscanf(opengl_version->str, "%d.%d", &opengl_version_major, &opengl_version_minor); sscanf(opengl_version->str, "%d.%d", &opengl_version_major, &opengl_version_minor);
sscanf(glew_version->str, "%d.%d", &glew_version_major, &glew_version_minor);
g_print ("GL_VERSION: %s\n", glGetString (GL_VERSION)); g_print ("GL_VERSION: %s\n", glGetString (GL_VERSION));
g_print ("GLEW_VERSION: %s\n", glewGetString (GLEW_VERSION)); g_print ("GLEW_VERSION: %s\n", glewGetString (GLEW_VERSION));
g_print ("GL_SHADING_LANGUAGE_VERSION: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));
g_print ("GL_VENDOR: %s\n", glGetString (GL_VENDOR)); g_print ("GL_VENDOR: %s\n", glGetString (GL_VENDOR));
g_print ("GL_RENDERER: %s\n", glGetString (GL_RENDERER)); g_print ("GL_RENDERER: %s\n", glGetString (GL_RENDERER));
g_string_free (opengl_version, TRUE); g_string_free (opengl_version, TRUE);
g_string_free (glew_version, TRUE);
if ((opengl_version_major < 1 && opengl_version_minor < 4) || if ((opengl_version_major < 1) ||
(glew_version_major < 1 && glew_version_minor < 4) ) (GLEW_VERSION_MAJOR < 1) ||
(opengl_version_major < 2 && opengl_version_major >= 1 && opengl_version_minor < 4) ||
(GLEW_VERSION_MAJOR < 2 && GLEW_VERSION_MAJOR >= 1 && GLEW_VERSION_MINOR < 4) )
{ {
//turn off the pipeline, the old drivers are not yet supported //turn off the pipeline, the old drivers are not yet supported
g_print ("Required OpenGL >= 1.4.0 and Glew >= 1.4.0\n"); g_print ("Required OpenGL >= 1.4.0 and Glew >= 1.4.0\n");

View file

@ -62,10 +62,11 @@ static const gchar *convolution_fragment_source =
"uniform float norm_offset;" "uniform float norm_offset;"
"uniform float kernel[9];" "uniform float kernel[9];"
"void main () {" "void main () {"
" vec2 offset[9];" " const int N = 9;"
" offset = vec2[] ( vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0)," " const vec2 offset[N] = vec2[N] ("
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0)," " vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );" " vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
" vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) );"
" vec2 texturecoord = gl_TexCoord[0].st;" " vec2 texturecoord = gl_TexCoord[0].st;"
" int i;" " int i;"
" vec4 sum = vec4 (0.0);" " vec4 sum = vec4 (0.0);"
@ -111,8 +112,19 @@ gst_gl_filter_laplacian_reset (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 destroyed the shader program //I commented the following line to avoid a crash for now
g_object_unref (G_OBJECT (laplacian_filter->shader)); //It crashs because when unreferencing the GstGLShader
//if ref is down to 0 it causes a finalize then a gst_gl_shader_release
//then a glDeleteObjectARB
//and this glDeleteObjectARB must be executed in by (in) the gl thread
//How to do that so ? Easy, using the gst_gl_display_del_shader method
//but I have not modified it yet (*1*) to use GstGLShader
//I'll do that soon so just comment the following line for now
//g_object_unref (G_OBJECT (laplacian_filter->shader));
//blocking call, wait the opengl thread has destroyed the GstGLShader
//Commented for the reason *1*
//gst_gl_display_del_shader (filter->display, laplacian_filter->shader);
} }
static void static void
@ -149,6 +161,11 @@ gst_gl_filter_laplacian_init_shader (GstGLFilter* filter)
// GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter); // GstGLFilterLaplacian* laplacian_filter = GST_GL_FILTER_LAPLACIAN (filter);
// at the moment I do everything in the laplacian_callback // at the moment I do everything in the laplacian_callback
// ok, then for the same reason *1* explained in the
// gst_gl_filter_laplacian_reset method I comment the following line
//blocking call, wait the opengl thread has destroyed the shader program
//gst_gl_display_del_shader (filter->display, laplacian_filter->shader);
} }
static gboolean static gboolean
@ -181,12 +198,16 @@ gst_gl_filter_laplacian_callback (gint width, gint height, guint texture, gpoint
glLoadIdentity (); glLoadIdentity ();
/* compile and link the shader (if not done previously) */ /* compile and link the shader (if not done previously) */
//FIXME: do it in the gst_gl_filter_laplacian_init_shader method
if (!laplacian_filter->shader) if (!laplacian_filter->shader)
{
laplacian_filter->shader = gst_gl_shader_new (); laplacian_filter->shader = gst_gl_shader_new ();
g_return_if_fail ( g_return_if_fail (
gst_gl_shader_compile_and_check (laplacian_filter->shader, convolution_fragment_source, gst_gl_shader_compile_and_check (laplacian_filter->shader, convolution_fragment_source,
GST_GL_SHADER_FRAGMENT_SOURCE)); GST_GL_SHADER_FRAGMENT_SOURCE));
}
gst_gl_shader_use (laplacian_filter->shader); gst_gl_shader_use (laplacian_filter->shader);
glActiveTexture (GL_TEXTURE0); glActiveTexture (GL_TEXTURE0);