1 /* GStreamer
2 * Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include <gst/check/gstcheck.h>
25
26 #include <gst/gl/gl.h>
27
28 #include <stdio.h>
29
30 static GstGLDisplay *display;
31 static GstGLContext *context;
32
33 static void
setup(void)34 setup (void)
35 {
36 GError *error = NULL;
37
38 display = gst_gl_display_new ();
39 context = gst_gl_context_new (display);
40
41 gst_gl_context_create (context, NULL, &error);
42
43 fail_if (error != NULL, "Error creating context: %s\n",
44 error ? error->message : "Unknown Error");
45 }
46
47 static void
teardown(void)48 teardown (void)
49 {
50 gst_object_unref (display);
51 gst_object_unref (context);
52 }
53
54 static void
_test_compile_attach_gl(GstGLContext * context,gpointer data)55 _test_compile_attach_gl (GstGLContext * context, gpointer data)
56 {
57 GstGLShader *shader;
58 GstGLSLStage *vert;
59 GError *error = NULL;
60
61 shader = gst_gl_shader_new (context);
62 vert = gst_glsl_stage_new_default_vertex (context);
63
64 fail_unless (gst_gl_shader_compile_attach_stage (shader, vert, &error));
65
66 gst_object_unref (shader);
67 }
68
GST_START_TEST(test_compile_attach)69 GST_START_TEST (test_compile_attach)
70 {
71 gst_gl_context_thread_add (context,
72 (GstGLContextThreadFunc) _test_compile_attach_gl, NULL);
73 }
74
75 GST_END_TEST;
76
77 static void
_test_separate_compile_attach_gl(GstGLContext * context,gpointer data)78 _test_separate_compile_attach_gl (GstGLContext * context, gpointer data)
79 {
80 GstGLShader *shader;
81 GstGLSLStage *vert;
82 GError *error = NULL;
83
84 shader = gst_gl_shader_new (context);
85 vert = gst_glsl_stage_new_default_vertex (context);
86
87 fail_unless (gst_glsl_stage_compile (vert, &error));
88 fail_unless (gst_gl_shader_attach (shader, vert));
89 fail_unless (gst_gl_shader_attach (shader, vert));
90
91 gst_object_unref (shader);
92 }
93
GST_START_TEST(test_separate_compile_attach)94 GST_START_TEST (test_separate_compile_attach)
95 {
96 gst_gl_context_thread_add (context,
97 (GstGLContextThreadFunc) _test_separate_compile_attach_gl, NULL);
98 }
99
100 GST_END_TEST;
101
102 static void
_test_detach_gl(GstGLContext * context,gpointer data)103 _test_detach_gl (GstGLContext * context, gpointer data)
104 {
105 GstGLShader *shader;
106 GstGLSLStage *vert;
107 GError *error = NULL;
108
109 shader = gst_gl_shader_new (context);
110 vert = gst_glsl_stage_new_default_vertex (context);
111
112 fail_unless (gst_glsl_stage_compile (vert, &error));
113 fail_unless (gst_gl_shader_attach (shader, vert));
114 gst_gl_shader_detach (shader, vert);
115
116 gst_object_unref (shader);
117 }
118
GST_START_TEST(test_detach)119 GST_START_TEST (test_detach)
120 {
121 gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _test_detach_gl,
122 NULL);
123 }
124
125 GST_END_TEST;
126
127 static void
_test_link_gl(GstGLContext * context,gpointer data)128 _test_link_gl (GstGLContext * context, gpointer data)
129 {
130 GstGLShader *shader;
131 GstGLSLStage *vert, *frag;
132 GError *error = NULL;
133
134 shader = gst_gl_shader_new (context);
135 vert = gst_glsl_stage_new_default_vertex (context);
136 frag = gst_glsl_stage_new_default_fragment (context);
137
138 fail_unless (gst_gl_shader_compile_attach_stage (shader, vert, &error));
139 fail_unless (gst_gl_shader_compile_attach_stage (shader, frag, &error));
140 fail_unless (gst_gl_shader_link (shader, &error));
141 fail_unless (gst_gl_shader_is_linked (shader));
142
143 gst_object_unref (shader);
144 }
145
GST_START_TEST(test_link)146 GST_START_TEST (test_link)
147 {
148 gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _test_link_gl,
149 NULL);
150 }
151
152 GST_END_TEST;
153
154 static void
_test_default_shader_gl(GstGLContext * context,gpointer data)155 _test_default_shader_gl (GstGLContext * context, gpointer data)
156 {
157 GstGLShader *shader;
158 GError *error = NULL;
159
160 shader = gst_gl_shader_new_default (context, &error);
161 fail_unless (shader != NULL);
162 fail_unless (error == NULL);
163
164 gst_gl_shader_use (shader);
165 gst_gl_context_clear_shader (context);
166
167 gst_object_unref (shader);
168 }
169
GST_START_TEST(test_default_shader)170 GST_START_TEST (test_default_shader)
171 {
172 gst_gl_context_thread_add (context,
173 (GstGLContextThreadFunc) _test_default_shader_gl, NULL);
174 }
175
176 GST_END_TEST;
177
178 static void
_test_get_attribute_location_gl(GstGLContext * context,gpointer data)179 _test_get_attribute_location_gl (GstGLContext * context, gpointer data)
180 {
181 GstGLShader *shader;
182 GError *error = NULL;
183 gint loc;
184
185 shader = gst_gl_shader_new_default (context, &error);
186
187 gst_gl_shader_use (shader);
188
189 loc = gst_gl_shader_get_attribute_location (shader, "a_position");
190 fail_unless (loc != -1);
191 loc = gst_gl_shader_get_attribute_location (shader, "a_texcoord");
192 fail_unless (loc != -1);
193 loc = gst_gl_shader_get_attribute_location (shader, "unused_value_1928374");
194 fail_unless (loc == -1);
195
196 gst_object_unref (shader);
197 }
198
GST_START_TEST(test_get_attribute_location)199 GST_START_TEST (test_get_attribute_location)
200 {
201 gst_gl_context_thread_add (context,
202 (GstGLContextThreadFunc) _test_get_attribute_location_gl, NULL);
203 }
204
205 GST_END_TEST;
206
207 static Suite *
gst_gl_shader_suite(void)208 gst_gl_shader_suite (void)
209 {
210 Suite *s = suite_create ("GstGLShader");
211 TCase *tc_chain = tcase_create ("glshader");
212
213 suite_add_tcase (s, tc_chain);
214 tcase_add_checked_fixture (tc_chain, setup, teardown);
215 tcase_add_test (tc_chain, test_compile_attach);
216 tcase_add_test (tc_chain, test_separate_compile_attach);
217 tcase_add_test (tc_chain, test_detach);
218 tcase_add_test (tc_chain, test_link);
219 tcase_add_test (tc_chain, test_default_shader);
220 tcase_add_test (tc_chain, test_get_attribute_location);
221
222 return s;
223 }
224
225 GST_CHECK_MAIN (gst_gl_shader);
226