ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_uniform_buffer_object / getprogramiv.c
blob25fa425412f764e0bdbd2a32e0880cf8aede55c0
1 /*
2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /** @file getprogramiv.c
26 * From the GL_ARB_uniform_buffer_object spec:
28 * "If <pname> is ACTIVE_UNIFORM_BLOCKS the number of uniform
29 * blocks for <program> containing active uniforms is returned.
31 * If <pname> is ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, the length
32 * of the longest active uniform block name, including the null
33 * terminator, is returned."
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config.supports_gl_compat_version = 10;
41 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 struct {
47 const char *source;
48 int blocks;
49 int namelen;
50 } tests[] = {
52 "#extension GL_ARB_uniform_buffer_object : enable\n"
53 "uniform a { float u1; };\n"
54 "void main() {\n"
55 " gl_FragColor = vec4(u1);\n"
56 "}\n",
57 1, 2,
60 "#extension GL_ARB_uniform_buffer_object : enable\n"
61 "uniform a { float u1; };\n"
62 "uniform b { float u2; };\n"
63 "void main() {\n"
64 " gl_FragColor = vec4(u1 + u2);\n"
65 "}\n",
66 2, 2,
69 "#extension GL_ARB_uniform_buffer_object : enable\n"
70 "uniform a { float u1; };\n"
71 "uniform bb { float u2; };\n"
72 "void main() {\n"
73 " gl_FragColor = vec4(u1 + u2);\n"
74 "}\n",
75 2, 3,
78 "#extension GL_ARB_uniform_buffer_object : enable\n"
79 "uniform aa { float u1; };\n"
80 "uniform b { float u2; };\n"
81 "void main() {\n"
82 " gl_FragColor = vec4(u1 + u2);\n"
83 "}\n",
84 2, 3,
88 static bool
89 test_shader(int test)
91 GLuint prog;
92 const char *source = tests[test].source;
93 int namelen = 9999, blocks = 9999;
95 prog = piglit_build_simple_program(NULL, source);
97 glGetProgramiv(prog, GL_ACTIVE_UNIFORM_BLOCKS, &blocks);
98 if (blocks != tests[test].blocks) {
99 fprintf(stderr,
100 "%d: Bad GL_ACTIVE_UNIFORM_BLOCKS "
101 "%d, expected %d. Source:\n%s",
102 test, blocks, tests[test].blocks, source);
103 return false;
106 glGetProgramiv(prog, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &namelen);
107 if (namelen != tests[test].namelen) {
108 fprintf(stderr,
109 "%d: Bad GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH "
110 "%d, expected %d. Source:\n%s",
111 test, namelen, tests[test].namelen, source);
112 return false;
115 glDeleteProgram(prog);
117 return true;
120 void
121 piglit_init(int argc, char **argv)
123 bool pass = true;
124 int i;
126 piglit_require_extension("GL_ARB_uniform_buffer_object");
128 for (i = 0; i < ARRAY_SIZE(tests); i++) {
129 pass = test_shader(i) && pass;
132 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
135 enum piglit_result piglit_display(void)
137 /* UNREACHED */
138 return PIGLIT_FAIL;