gl/tests: add some simple shader testing

Making sure that the default shaders compile and are usable
This commit is contained in:
Matthew Waters 2017-11-07 15:21:43 +11:00
parent bbbe9ef2ce
commit 1cef7a261f
3 changed files with 346 additions and 0 deletions

View file

@ -212,6 +212,8 @@ check_gl=libs/gstglcontext \
libs/gstglmatrix \
libs/gstglquery \
libs/gstglsl \
libs/gstglslstage \
libs/gstglshader \
libs/gstglheaders \
elements/glimagesink \
pipelines/simple-launch-lines
@ -621,6 +623,24 @@ libs_gstglsl_CFLAGS = \
-DGST_USE_UNSTABLE_API \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS)
libs_gstglslstage_LDADD = \
$(top_builddir)/gst-libs/gst/gl/libgstgl-@GST_API_VERSION@.la \
$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD)
libs_gstglslstage_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
-DGST_USE_UNSTABLE_API \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS)
libs_gstglshader_LDADD = \
$(top_builddir)/gst-libs/gst/gl/libgstgl-@GST_API_VERSION@.la \
$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD)
libs_gstglshader_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
-DGST_USE_UNSTABLE_API \
$(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS)
libs_gstglheaders_LDADD = \
$(top_builddir)/gst-libs/gst/gl/libgstgl-@GST_API_VERSION@.la \
$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD)

View file

@ -0,0 +1,225 @@
/* GStreamer
* Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gst/check/gstcheck.h>
#include <gst/gl/gl.h>
#include <stdio.h>
static GstGLDisplay *display;
static GstGLContext *context;
static void
setup (void)
{
GError *error = NULL;
display = gst_gl_display_new ();
context = gst_gl_context_new (display);
gst_gl_context_create (context, NULL, &error);
fail_if (error != NULL, "Error creating context: %s\n",
error ? error->message : "Unknown Error");
}
static void
teardown (void)
{
gst_object_unref (display);
gst_object_unref (context);
}
static void
_test_compile_attach_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GstGLSLStage *vert;
GError *error = NULL;
shader = gst_gl_shader_new (context);
vert = gst_glsl_stage_new_default_vertex (context);
fail_unless (gst_gl_shader_compile_attach_stage (shader, vert, &error));
gst_object_unref (shader);
}
GST_START_TEST (test_compile_attach)
{
gst_gl_context_thread_add (context,
(GstGLContextThreadFunc) _test_compile_attach_gl, NULL);
}
GST_END_TEST;
static void
_test_separate_compile_attach_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GstGLSLStage *vert;
GError *error = NULL;
shader = gst_gl_shader_new (context);
vert = gst_glsl_stage_new_default_vertex (context);
fail_unless (gst_glsl_stage_compile (vert, &error));
fail_unless (gst_gl_shader_attach (shader, vert));
fail_unless (gst_gl_shader_attach (shader, vert));
gst_object_unref (shader);
}
GST_START_TEST (test_separate_compile_attach)
{
gst_gl_context_thread_add (context,
(GstGLContextThreadFunc) _test_separate_compile_attach_gl, NULL);
}
GST_END_TEST;
static void
_test_detach_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GstGLSLStage *vert;
GError *error = NULL;
shader = gst_gl_shader_new (context);
vert = gst_glsl_stage_new_default_vertex (context);
fail_unless (gst_glsl_stage_compile (vert, &error));
fail_unless (gst_gl_shader_attach (shader, vert));
gst_gl_shader_detach (shader, vert);
gst_object_unref (shader);
}
GST_START_TEST (test_detach)
{
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _test_detach_gl,
NULL);
}
GST_END_TEST;
static void
_test_link_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GstGLSLStage *vert, *frag;
GError *error = NULL;
shader = gst_gl_shader_new (context);
vert = gst_glsl_stage_new_default_vertex (context);
frag = gst_glsl_stage_new_default_fragment (context);
fail_unless (gst_gl_shader_compile_attach_stage (shader, vert, &error));
fail_unless (gst_gl_shader_compile_attach_stage (shader, frag, &error));
fail_unless (gst_gl_shader_link (shader, &error));
fail_unless (gst_gl_shader_is_linked (shader));
gst_object_unref (shader);
}
GST_START_TEST (test_link)
{
gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _test_link_gl,
NULL);
}
GST_END_TEST;
static void
_test_default_shader_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GError *error = NULL;
shader = gst_gl_shader_new_default (context, &error);
fail_unless (shader != NULL);
fail_unless (error == NULL);
gst_gl_shader_use (shader);
gst_gl_context_clear_shader (context);
gst_object_unref (shader);
}
GST_START_TEST (test_default_shader)
{
gst_gl_context_thread_add (context,
(GstGLContextThreadFunc) _test_default_shader_gl, NULL);
}
GST_END_TEST;
static void
_test_get_attribute_location_gl (GstGLContext * context, gpointer data)
{
GstGLShader *shader;
GError *error = NULL;
gint loc;
shader = gst_gl_shader_new_default (context, &error);
gst_gl_shader_use (shader);
loc = gst_gl_shader_get_attribute_location (shader, "a_position");
fail_unless (loc != -1);
loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord");
fail_unless (loc != -1);
loc = gst_gl_shader_get_attribute_location (shader, "unused_value_1928374");
fail_unless (loc == -1);
gst_object_unref (shader);
}
GST_START_TEST (test_get_attribute_location)
{
gst_gl_context_thread_add (context,
(GstGLContextThreadFunc) _test_get_attribute_location_gl, NULL);
}
GST_END_TEST;
static Suite *
gst_gl_shader_suite (void)
{
Suite *s = suite_create ("GstGLShader");
TCase *tc_chain = tcase_create ("glshader");
suite_add_tcase (s, tc_chain);
tcase_add_checked_fixture (tc_chain, setup, teardown);
tcase_add_test (tc_chain, test_compile_attach);
tcase_add_test (tc_chain, test_separate_compile_attach);
tcase_add_test (tc_chain, test_detach);
tcase_add_test (tc_chain, test_link);
tcase_add_test (tc_chain, test_default_shader);
tcase_add_test (tc_chain, test_get_attribute_location);
return s;
}
GST_CHECK_MAIN (gst_gl_shader);

View file

@ -0,0 +1,101 @@
/* GStreamer
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gst/check/gstcheck.h>
#include <gst/gl/gl.h>
#include <gst/gl/gstglfuncs.h>
#include <stdio.h>
static GstGLDisplay *display;
static GstGLContext *context;
static void
setup (void)
{
GError *error = NULL;
display = gst_gl_display_new ();
context = gst_gl_context_new (display);
gst_gl_context_create (context, NULL, &error);
fail_if (error != NULL, "Error creating context: %s\n",
error ? error->message : "Unknown Error");
}
static void
teardown (void)
{
gst_object_unref (display);
gst_object_unref (context);
}
GST_START_TEST (test_default_vertex)
{
GstGLSLStage *stage;
GError *error = NULL;
stage = gst_glsl_stage_new_default_vertex (context);
fail_unless (stage != NULL);
fail_unless (GL_VERTEX_SHADER == gst_glsl_stage_get_shader_type (stage));
fail_unless (gst_glsl_stage_compile (stage, &error));
gst_object_unref (stage);
}
GST_END_TEST;
GST_START_TEST (test_default_fragment)
{
GstGLSLStage *stage;
GError *error = NULL;
stage = gst_glsl_stage_new_default_fragment (context);
fail_unless (stage != NULL);
fail_unless (GL_FRAGMENT_SHADER == gst_glsl_stage_get_shader_type (stage));
fail_unless (gst_glsl_stage_compile (stage, &error));
gst_object_unref (stage);
}
GST_END_TEST;
static Suite *
gst_gl_upload_suite (void)
{
Suite *s = suite_create ("GstGLSL");
TCase *tc_chain = tcase_create ("glsl");
suite_add_tcase (s, tc_chain);
tcase_add_checked_fixture (tc_chain, setup, teardown);
tcase_add_test (tc_chain, test_default_vertex);
tcase_add_test (tc_chain, test_default_fragment);
return s;
}
GST_CHECK_MAIN (gst_gl_upload);