glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / glsl-vs-loop-nested.c
blob56fcbf1c9c6012f0638cc17f28858d0c43d634f7
1 /*
2 * Copyright © 2009-2010 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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Ian Romanick <idr@freedesktop.org>
29 /** @file glsl-vs-loop-nested.c
31 * Tests that nested loops in the vertex shader work.
33 * Since a value from an attribute is used for the loop counters, the
34 * compiler cannot simply unroll the loop. This verifies that GLSL
35 * loops can be correctly generated in the vertex shader.
37 * This was conceived as a test case for freedesktop.org bug #25173.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
48 PIGLIT_GL_TEST_CONFIG_END
50 static GLint prog;
52 enum piglit_result
53 piglit_display(void)
55 GLboolean pass = GL_TRUE;
57 float color[] = {1.0, 0.0, 0.0, 0.0};
59 unsigned i;
60 unsigned j;
62 glClearColor(0.5, 0.5, 0.5, 0.5);
63 glClear(GL_COLOR_BUFFER_BIT);
65 for (i = 0; i < 3; i++) {
66 float temp;
67 float line_color[4];
68 unsigned x = 5 + (25 * i);
70 for (j = 0; j < 3; j++) {
71 int y = 5 + (25 * j);
72 int rotate;
74 memcpy(line_color, color, sizeof(line_color));
75 for (rotate = 0; rotate < i * j; rotate++) {
76 temp = line_color[2];
77 line_color[2] = line_color[1];
78 line_color[1] = line_color[0];
79 line_color[0] = temp;
81 line_color[3] = (float) i * 4 + j;
83 glColor4fv(line_color);
84 piglit_draw_rect(x, y, 20, 20);
86 pass &= piglit_probe_pixel_rgb(x + 5, y + 5, color);
89 temp = color[2];
90 color[2] = color[1];
91 color[1] = color[0];
92 color[0] = temp;
96 piglit_present_results();
98 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
101 void
102 piglit_init(int argc, char **argv)
104 GLint vs, fs;
106 /* Set up projection matrix so we can just draw using window
107 * coordinates.
109 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
111 piglit_require_gl_version(20);
113 vs = piglit_compile_shader(GL_VERTEX_SHADER,
114 "shaders/glsl-vs-loop-nested.vert");
115 fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
116 "shaders/glsl-color.frag");
118 prog = piglit_link_simple_program(vs, fs);
120 glUseProgram(prog);