cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / shaders / glsl-sin.c
blobc154b22135941299072d6d06ad6e1619d96a3a16
1 /*
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
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 * Marek Olšák <mareao@gmail.com>
28 /** @file glsl-sin.c
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[] =
44 "uniform float a;\n"
45 "varying float val;\n"
47 "void main()\n"
48 "{\n"
49 " gl_Position = ftransform();\n"
50 " val = sin(a);\n"
51 "}\n";
53 static char fs_code[] =
54 "uniform float a;\n"
55 "varying float val;\n"
57 "void main()\n"
58 "{\n"
59 " gl_FragColor = vec4(val, sin(a), -1.0, 1.0) * 0.5 + 0.5;\n"
60 "}\n";
62 static GLuint setup_shaders()
64 GLuint vs, fs, prog;
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);
70 glUseProgram(prog);
71 return prog;
74 static GLboolean test()
76 GLint prog, location;
77 GLboolean pass = GL_TRUE;
78 int i;
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;
97 return pass;
100 enum piglit_result piglit_display(void)
102 GLboolean pass;
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);
109 pass = test();
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);