ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_uniform_buffer_object / dlist.c
blob2ee61e6f740a5db8574a1f8917488db3f346541e
1 /*
2 * Copyright © 2011 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 DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-util-gl.h"
26 /**
27 * @file dlist.c
29 * Tests that conditional rendering appropriately affects commands
30 * inside of display lists. From the GL_ARB_uniform_buffer_object
31 * spec:
33 * "(33) Which uniform buffer object commands must be excluded
34 * from display lists?
36 * RESOLUTION: Resolved
38 * When used with 3.1 (where display lists have been removed
39 * altogether) obviously, this question is moot.
41 * For GL 2.0/3.0, this should be resolved with the following
42 * precedents:
44 * ...
46 * UniformBlockBinding should follow the precedent of glUniform (for
47 * setting samplers) which *does* get included in display lists.
49 * ...
51 * Since we use the BindBufferOffset/BindBufferRange API
52 * introduced by OpenGL 3.0, and those routines are already
53 * excluded, there's no additions to the display list exclusion
54 * list needed."
57 PIGLIT_GL_TEST_CONFIG_BEGIN
59 config.supports_gl_compat_version = 10;
61 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
62 config.khr_no_error_support = PIGLIT_NO_ERRORS;
64 PIGLIT_GL_TEST_CONFIG_END
66 const char *source =
67 "#extension GL_ARB_uniform_buffer_object : enable\n"
68 "uniform A { float a; };\n"
69 "uniform B { float b; };\n"
70 "void main() {\n"
71 " gl_FragColor = vec4(a + b);\n"
72 "}\n";
74 enum piglit_result
75 piglit_display(void)
77 /* UNREACHED */
78 return PIGLIT_FAIL;
81 static bool
82 check_binding(int line, GLuint prog, int index, int binding)
84 GLint current_binding;
86 glGetActiveUniformBlockiv(prog, index, GL_UNIFORM_BLOCK_BINDING,
87 &current_binding);
89 if (current_binding != binding) {
90 printf("%s:%d: Binding %d should be %d, was %d\n",
91 __FILE__, line, index, binding, current_binding);
92 return false;
95 return true;
99 void
100 piglit_init(int argc, char **argv)
102 bool pass = true;
103 GLuint prog;
104 GLuint bo[2];
105 GLint current_bo;
106 GLint list;
108 piglit_require_extension("GL_ARB_uniform_buffer_object");
110 prog = piglit_build_simple_program(NULL, source);
112 /* Test that glUniformBlockBinding() goes into display lists. */
113 glUniformBlockBinding(prog, 0, 0);
114 glUniformBlockBinding(prog, 0, 1);
116 list = glGenLists(1);
117 glNewList(list, GL_COMPILE_AND_EXECUTE);
118 glUniformBlockBinding(prog, 0, 2);
119 glUniformBlockBinding(prog, 1, 3);
120 glEndList();
122 pass = check_binding(__LINE__, prog, 0, 2) && pass;
123 pass = check_binding(__LINE__, prog, 1, 3) && pass;
125 glUniformBlockBinding(prog, 0, 0);
126 glUniformBlockBinding(prog, 0, 1);
128 glCallList(list);
130 pass = check_binding(__LINE__, prog, 0, 2) && pass;
131 pass = check_binding(__LINE__, prog, 1, 3) && pass;
133 /* Test that glBindBufferBase()/glBindBufferRange() fail
134 * inside a display list.
136 glGenBuffers(2, bo);
137 glBindBuffer(GL_UNIFORM_BUFFER, bo[0]);
138 glBufferData(GL_UNIFORM_BUFFER, 4, NULL, GL_STATIC_DRAW);
139 glBindBuffer(GL_UNIFORM_BUFFER, bo[1]);
140 glBufferData(GL_UNIFORM_BUFFER, 4, NULL, GL_STATIC_DRAW);
142 pass = piglit_check_gl_error(0) && pass;
144 glBindBufferBase(GL_UNIFORM_BUFFER, 0, bo[0]);
145 glBindBufferBase(GL_UNIFORM_BUFFER, 1, bo[0]);
147 glNewList(list, GL_COMPILE);
148 glBindBufferBase(GL_UNIFORM_BUFFER, 0, bo[1]);
149 glBindBufferRange(GL_UNIFORM_BUFFER, 1, bo[1], 0, 4);
150 glEndList();
152 glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 0, &current_bo);
153 if (current_bo != bo[1]) {
154 fprintf(stderr, "glBindBufferBase() during display list compile "
155 "set BO to %d, expected %d\n",
156 current_bo, bo[1]);
159 glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 1, &current_bo);
160 if (current_bo != bo[1]) {
161 fprintf(stderr, "glBindBufferRange() during display list "
162 "compile set BO to %d, expected %d\n",
163 current_bo, bo[1]);
167 glBindBufferBase(GL_UNIFORM_BUFFER, 0, bo[0]);
168 glBindBufferBase(GL_UNIFORM_BUFFER, 1, bo[0]);
169 glCallList(list);
171 glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 0, &current_bo);
172 if (current_bo != bo[0]) {
173 fprintf(stderr, "glBindBufferBase() during display list exec "
174 "set BO to %d, expected %d\n",
175 current_bo, bo[0]);
178 glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 1, &current_bo);
179 if (current_bo != bo[0]) {
180 fprintf(stderr, "glBindBufferRange() during display list exec "
181 "set BO to %d, expected %d\n",
182 current_bo, bo[0]);
185 pass = piglit_check_gl_error(0) && pass;
187 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);