2 * GL_ARB_shader_objects & GL_ARB_vertex_shader interface test application.
3 * Neither compiler nor executor is being tested here, although some simple shader
4 * compilation tests are performed.
6 * Perfectly valid behaviour produces output that does not have a line
7 * beginning with three stars (***).
12 #include "framework.h"
17 TT_GETERROR_INVALIDVALUE
,
18 TT_GETERROR_INVALIDOPERATION
,
23 static enum TEST_TYPE current_test
;
25 static void begintest (enum TEST_TYPE type
, const char *name
)
28 printf ("\n BEGIN TEST: %s\n", name
);
29 while (glGetError () != GL_NO_ERROR
)
33 static void endtest1 (GLuint param1
)
35 const char *msg
= NULL
;
39 case TT_GETERROR_NOERROR
:
40 if (glGetError () != GL_NO_ERROR
)
41 msg
= "glGetError () does not return GL_NO_ERROR";
43 case TT_GETERROR_INVALIDVALUE
:
44 if (glGetError () != GL_INVALID_VALUE
)
45 msg
= "glGetError () does not return GL_INVALID_VALUE";
47 case TT_GETERROR_INVALIDOPERATION
:
48 if (glGetError () != GL_INVALID_OPERATION
)
49 msg
= "glGetError () does not return GL_INVALID_OPERATION";
53 msg
= "The parameter is not zero";
55 case TT_PARAM1_NONZERO
:
57 msg
= "The parameter is not non-zero";
66 printf ("*** %s\n", msg
);
68 while (glGetError () != GL_NO_ERROR
)
72 static void endtest ()
77 static GLhandleARB vert
= 0;
78 static GLhandleARB frag
= 0;
79 static GLhandleARB prog
= 0;
81 static GLhandleARB
find_invalid_handle ()
85 for (handle
= 1; handle
< 16; handle
++)
86 if (handle
!= vert
&& handle
!= frag
&& handle
!= prog
)
92 static const char *invsynvertsrc
=
94 " gl_Position = gl_ModelViewMatrix ! gl_Vertex;\n" /* unexpected token */
98 static const char *invsemvertsrc
=
100 " gl_Position = gl_ModelviewMatrix * gl_Vertex;\n" /* undeclared identifier */
104 static const char *uniforms
=
105 "uniform vec4 CommonUniform;\n"
108 static const char *validvertsrc
=
109 "uniform vec4 VertexUniform;\n"
110 "attribute vec4 FirstAttrib;\n"
111 "attribute vec4 SecondAttrib;\n"
113 " gl_Position = gl_ModelViewMatrix * gl_Vertex + CommonUniform + VertexUniform\n"
114 " + FirstAttrib + SecondAttrib;\n"
118 static const char *invsynfragsrc
=
120 " gl_FragColor = gl_Color\n" /* missing ; */
124 static const char *invsemfragsrc
=
126 " gl_FragColor = gl_FrontColor;\n" /* gl_FrontColor only in vertex shader */
130 static const char *validfragsrc
=
131 "uniform vec4 FragmentUniform;\n"
133 " gl_FragColor = gl_Color + CommonUniform + FragmentUniform;\n"
137 void InitScene (void)
143 * GL should silently ignore calls that delete object 0.
145 begintest (TT_GETERROR_NOERROR
, "glDeleteObject(0)");
146 glDeleteObjectARB (0);
150 * GL generates an error on invalid object handle.
152 begintest (TT_GETERROR_INVALIDVALUE
, "Pass invalid non-zero object handle");
153 glDeleteObjectARB (find_invalid_handle ());
155 glUseProgramObjectARB (find_invalid_handle ());
159 * Create object. GL should return unique non-zero values.
161 begintest (TT_PARAM1_NONZERO
, "Create object");
162 vert
= glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB
);
164 frag
= glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB
);
166 prog
= glCreateProgramObjectARB ();
168 endtest1 (vert
!= frag
&& frag
!= prog
&& prog
!= vert
);
171 * Link empty program.
173 begintest (TT_PARAM1_NONZERO
, "Link empty program");
174 glLinkProgramARB (prog
);
175 endtest1 (CheckObjectStatus (prog
));
178 * Use empty program object. Empty program objects are valid.
180 begintest (TT_GETERROR_NOERROR
, "Use empty program object");
181 glUseProgramObjectARB (prog
);
185 * Attach invalid object handles. Program object 0 should not be accepted.
187 begintest (TT_GETERROR_INVALIDVALUE
, "Attach invalid object handle");
188 glAttachObjectARB (0, find_invalid_handle ());
190 glAttachObjectARB (0, frag
);
192 glAttachObjectARB (find_invalid_handle (), find_invalid_handle ());
194 glAttachObjectARB (find_invalid_handle (), frag
);
196 glAttachObjectARB (prog
, find_invalid_handle ());
200 * Attach valid object handles with wrong semantics.
202 begintest (TT_GETERROR_INVALIDOPERATION
, "Attach object badly");
203 glAttachObjectARB (vert
, frag
);
205 glAttachObjectARB (vert
, prog
);
207 glAttachObjectARB (prog
, prog
);
211 * Detach non-attached object.
213 begintest (TT_GETERROR_INVALIDOPERATION
, "Detach non-attached object");
214 glDetachObjectARB (prog
, vert
);
216 glDetachObjectARB (prog
, frag
);
222 begintest (TT_GETERROR_NOERROR
, "Attach shader to program object");
223 glAttachObjectARB (prog
, vert
);
225 glAttachObjectARB (prog
, frag
);
229 * Attach object twice.
231 begintest (TT_GETERROR_INVALIDOPERATION
, "Attach object twice");
232 glAttachObjectARB (prog
, vert
);
234 glAttachObjectARB (prog
, frag
);
238 * Detach attached object.
240 begintest (TT_GETERROR_NOERROR
, "Detach attached object");
241 glDetachObjectARB (prog
, vert
);
243 glDetachObjectARB (prog
, frag
);
247 * Attach shader again.
249 begintest (TT_GETERROR_NOERROR
, "Attach shader again");
250 glAttachObjectARB (prog
, vert
);
252 glAttachObjectARB (prog
, frag
);
256 * Delete attached object.
258 begintest (TT_GETERROR_NOERROR
, "Delete attached object");
259 glDeleteObjectARB (vert
);
261 glDeleteObjectARB (frag
);
265 * Query delete status. It should return TRUE. Object handles are still valid
266 * as they are referenced by program object container.
268 begintest (TT_PARAM1_NONZERO
, "Query delete status");
269 glGetObjectParameterivARB (vert
, GL_OBJECT_DELETE_STATUS_ARB
, params
);
270 endtest1 (params
[0]);
271 glGetObjectParameterivARB (frag
, GL_OBJECT_DELETE_STATUS_ARB
, params
);
272 endtest1 (params
[0]);
275 * Delete already deleted attached object. The behaviour is undefined, but we
276 * check for no errors. The object still exists, so the handle value is okay.
277 * In other words, these calls should be silently ignored by GL.
279 begintest (TT_GETERROR_NOERROR
, "Delete already deleted attached object");
280 glDeleteObjectARB (vert
);
282 glDeleteObjectARB (frag
);
286 * Compile shader source with syntax error.
288 begintest (TT_PARAM1_ZERO
, "Compile shader source with syntax error");
289 glShaderSourceARB (vert
, 1, &invsynvertsrc
, NULL
);
290 glCompileShaderARB (vert
);
291 endtest1 (CheckObjectStatus (vert
));
292 glShaderSourceARB (frag
, 1, &invsynfragsrc
, NULL
);
293 glCompileShaderARB (frag
);
294 endtest1 (CheckObjectStatus (frag
));
297 * Compile shader source with semantic error.
299 begintest (TT_PARAM1_ZERO
, "Compile shader source with semantic error");
300 glShaderSourceARB (vert
, 1, &invsemvertsrc
, NULL
);
301 glCompileShaderARB (vert
);
302 endtest1 (CheckObjectStatus (vert
));
303 glShaderSourceARB (frag
, 1, &invsemfragsrc
, NULL
);
304 glCompileShaderARB (frag
);
305 endtest1 (CheckObjectStatus (frag
));
308 * Link ill-formed vertex-fragment program.
310 begintest (TT_PARAM1_ZERO
, "Link ill-formed vertex-fragment program");
311 glLinkProgramARB (prog
);
312 endtest1 (CheckObjectStatus (prog
));
315 * Use badly linked program object.
317 begintest (TT_GETERROR_INVALIDOPERATION
, "Use badly linked program object");
318 glUseProgramObjectARB (prog
);
322 * Compile well-formed shader source. Check if multi-string sources can be handled.
324 begintest (TT_PARAM1_NONZERO
, "Compile well-formed shader source");
326 tab
[1] = validvertsrc
;
327 glShaderSourceARB (vert
, 2, tab
, NULL
);
328 glCompileShaderARB (vert
);
329 endtest1 (CheckObjectStatus (vert
));
331 tab
[1] = validfragsrc
;
332 glShaderSourceARB (frag
, 2, tab
, NULL
);
333 glCompileShaderARB (frag
);
334 endtest1 (CheckObjectStatus (frag
));
337 * Link vertex-fragment program.
339 begintest (TT_PARAM1_NONZERO
, "Link vertex-fragment program");
340 glLinkProgramARB (prog
);
341 endtest1 (CheckObjectStatus (prog
));
344 * Use valid linked program object.
346 begintest (TT_GETERROR_NOERROR
, "Use linked program object");
347 glUseProgramObjectARB (prog
);
351 * Get current program.
353 begintest (TT_PARAM1_NONZERO
, "Get current program");
354 endtest1 (glGetHandleARB (GL_PROGRAM_OBJECT_ARB
) == prog
);
357 * Use 0 program object.
359 begintest (TT_GETERROR_NOERROR
, "Use 0 program object");
360 glUseProgramObjectARB (0);
364 * Query uniform location. Uniforms with gl_ prefix cannot be queried.
366 begintest (TT_PARAM1_NONZERO
, "Query uniform location");
367 endtest1 (glGetUniformLocationARB (prog
, "gl_ModelViewMatrix") == -1);
368 endtest1 (glGetUniformLocationARB (prog
, "UniformThatDoesNotExist") == -1);
369 endtest1 (glGetUniformLocationARB (prog
, "") == -1);
370 endtest1 (glGetUniformLocationARB (prog
, "CommonUniform") != -1);
371 endtest1 (glGetUniformLocationARB (prog
, "VertexUniform") != -1);
372 endtest1 (glGetUniformLocationARB (prog
, "FragmentUniform") != -1);
375 * Query attrib location. Attribs with gl_ prefix cannot be queried.
376 * When gl_Vertex is used, none of the generic attribs can have index 0.
378 begintest (TT_PARAM1_NONZERO
, "Query attrib location");
379 endtest1 (glGetAttribLocationARB (prog
, "gl_Vertex") == -1);
380 endtest1 (glGetAttribLocationARB (prog
, "AttribThatDoesNotExist") == -1);
381 endtest1 (glGetAttribLocationARB (prog
, "") == -1);
382 endtest1 (glGetAttribLocationARB (prog
, "FirstAttrib") > 0);
383 endtest1 (glGetAttribLocationARB (prog
, "SecondAttrib") > 0);
386 * Bind attrib locations, link and check if locations are correct.
388 begintest (TT_PARAM1_NONZERO
, "Bind attrib location #1");
389 glBindAttribLocationARB (prog
, 1, "FirstAttrib");
390 glBindAttribLocationARB (prog
, 2, "SecondAttrib");
391 glLinkProgramARB (prog
);
392 endtest1 (CheckObjectStatus (prog
));
393 endtest1 (glGetAttribLocationARB (prog
, "FirstAttrib") == 1);
394 endtest1 (glGetAttribLocationARB (prog
, "SecondAttrib") == 2);
397 * Bind attrib locations in different order. Link and check if locations are correct.
399 begintest (TT_PARAM1_NONZERO
, "Bind attrib location #2");
400 glBindAttribLocationARB (prog
, 1, "SecondAttrib");
401 glBindAttribLocationARB (prog
, 2, "FirstAttrib");
402 glLinkProgramARB (prog
);
403 endtest1 (CheckObjectStatus (prog
));
404 endtest1 (glGetAttribLocationARB (prog
, "SecondAttrib") == 1);
405 endtest1 (glGetAttribLocationARB (prog
, "FirstAttrib") == 2);
408 * Detach deleted object.
410 begintest (TT_GETERROR_NOERROR
, "Detach deleted object");
411 glDetachObjectARB (prog
, vert
);
413 glDetachObjectARB (prog
, frag
);
417 * Delete deleted detached object.
419 begintest (TT_GETERROR_INVALIDVALUE
, "Delete deleted detached object");
420 glDeleteObjectARB (vert
);
422 glDeleteObjectARB (frag
);
428 void RenderScene (void)
434 int main (int argc
, char *argv
[])
436 InitFramework (&argc
, argv
);