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
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
24 * Eric Anholt <eric@anholt.net>
25 * Ian Romanick <idr@freedesktop.org>
29 /** @file glsl-fs-loop-nested.c
31 * Tests that nested loops in the fragment shader work.
33 * Since a value from an attribute is used as a loop counter, the compiler
34 * cannot simply unroll the loop. This verifies that GLSL loops can be
35 * correctly generated in the fragment shader.
37 * This was conceived as a test case for freedesktop.org bug #25173.
40 #include "piglit-util.h"
42 int piglit_width
= 100, piglit_height
= 100;
43 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
45 static int color_location
;
51 GLboolean pass
= GL_TRUE
;
53 float color
[] = {1.0, 0.0, 0.0, 0.0};
58 glClearColor(0.5, 0.5, 0.5, 0.5);
59 glClear(GL_COLOR_BUFFER_BIT
);
61 for (i
= 0; i
< 3; i
++) {
64 unsigned x
= 5 + (25 * i
);
66 for (j
= 0; j
< 3; j
++) {
67 unsigned y
= 5 + (25 * j
);
70 memcpy(line_color
, color
, sizeof(line_color
));
71 for (rotate
= 0; rotate
< i
* j
; rotate
++) {
73 line_color
[2] = line_color
[1];
74 line_color
[1] = line_color
[0];
77 line_color
[3] = (float) i
* 4 + j
;
79 glUniform4fv(color_location
, 1, line_color
);
80 piglit_draw_rect(x
, y
, 20, 20);
82 pass
&= piglit_probe_pixel_rgb(x
+ 5, y
+ 5, color
);
94 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
98 piglit_init(int argc
, char **argv
)
102 /* Set up projection matrix so we can just draw using window
105 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
107 if (!GLEW_VERSION_2_0
) {
108 printf("Requires OpenGL 2.0\n");
109 piglit_report_result(PIGLIT_SKIP
);
112 vs
= piglit_compile_shader(GL_VERTEX_SHADER
,
113 "shaders/glsl-mvp.vert");
114 fs
= piglit_compile_shader(GL_FRAGMENT_SHADER
,
115 "shaders/glsl-fs-loop-nested.frag");
117 prog
= piglit_link_simple_program(vs
, fs
);
121 color_location
= glGetUniformLocation(prog
, "color");