2 * Copyright © 2009 Marek Olšák (maraeo@gmail.com)
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 * Marek Olšák <mareao@gmail.com>
30 * Tests "sin" in both vertex and fragment shaders
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static char vs_code
[] =
45 "varying float val;\n"
49 " gl_Position = ftransform();\n"
53 static char fs_code
[] =
55 "varying float val;\n"
59 " gl_FragColor = vec4(val, sin(a), -1.0, 1.0) * 0.5 + 0.5;\n"
62 static GLuint
setup_shaders()
66 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_code
);
67 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_code
);
68 prog
= piglit_link_simple_program(vs
, fs
);
74 static GLboolean
test()
77 GLboolean pass
= GL_TRUE
;
79 float color
[4] = {0, 0, 0, 1};
80 float DEGREES_30
= 0.523598776;
82 prog
= setup_shaders();
83 location
= glGetUniformLocation(prog
, "a");
85 for (i
= 0; i
<= 50; i
++) {
86 glUniform1f(location
, (i
- 25) * DEGREES_30
);
87 piglit_draw_rect((i
% 10) * 10, (i
/ 10) * 10, 10, 10);
89 if (!piglit_check_gl_error(GL_NO_ERROR
))
90 piglit_report_result(PIGLIT_FAIL
);
92 for (i
= 0; i
<= 50; i
++) {
93 color
[0] = color
[1] = sin((i
- 25) * DEGREES_30
) * 0.5 + 0.5;
94 pass
= piglit_probe_pixel_rgb((i
% 10) * 10 + 5, (i
/ 10) * 10 + 5, color
) && pass
;
100 enum piglit_result
piglit_display(void)
104 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
106 glClearColor(0.5, 0.5, 0.5, 0.5);
107 glClear(GL_COLOR_BUFFER_BIT
);
111 piglit_present_results();
113 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
116 void piglit_init(int argc
, char **argv
)
118 piglit_require_gl_version(20);