framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / glsl-orangebook-ch06-bump.c
blob5ae748246baa4adf8a196be8ea730a377cf49ec1
1 /*
2 * Copyright © 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>
28 /** @file glsl-orangebook-ch06-bump.c
30 * Tests that the Orange Book's chapter 6 shader for procedural bumpmapping
31 * works correctly.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
42 PIGLIT_GL_TEST_CONFIG_END
44 /* Test size - note that the pixel probing below is very specific */
45 #define WIDTH 100
46 #define HEIGHT 100
49 static int bump_density_location, bump_size_location;
50 static int specular_factor_location, surface_color_location;
51 static int light_position_location, tangent_attrib;
52 static GLint prog;
54 enum piglit_result
55 piglit_display(void)
57 GLboolean pass = GL_TRUE;
58 static const float surface_color[3] = {0.7, 0.6, 0.18};
59 static const float test_specular[3] = {0.976, 0.894, 0.549};
60 static const float test_nonspecular[3] = {0.572, 0.490, 0.145};
61 static const float test_bump_dark[3] = {0.411, 0.352, 0.105};
62 static const float test_bump_light[3] = {1.0, 0.961, 0.557};
63 float light_position[3] = {-1.0, -1.0, 2.0};
64 float w = WIDTH;
65 float h = HEIGHT;
66 float bump_x = w * 3 / 8;
67 float bump_y = h * 3 / 8;
68 float x, y;
70 if (piglit_width < WIDTH || piglit_height < HEIGHT) {
71 printf("window is too small.\n");
72 return PIGLIT_SKIP;
75 piglit_ortho_projection(1, 1, GL_FALSE);
77 glViewport(0, 0, WIDTH, HEIGHT);
78 glClearColor(0.5, 0.5, 0.5, 0.5);
79 glClear(GL_COLOR_BUFFER_BIT);
81 glUniform1f(bump_density_location, 4);
82 glUniform1f(bump_size_location, 0.15);
83 glUniform1f(specular_factor_location, 0.5);
84 glUniform3fv(surface_color_location, 1, surface_color);
85 glUniform3fv(light_position_location, 1, light_position);
87 glTranslatef(0, 0, -0.5);
88 glNormal3f(0.0, 0.0, 1.0);
89 glVertexAttrib3f(tangent_attrib, 1.0, 0.0, 0.0);
90 for (x = 0.0; x < 1.0; x += 0.1) {
91 for (y = 0.0; y < 1.0; y += 0.1) {
92 piglit_draw_rect_tex(x, y, 0.1, 0.1,
93 x, y, 0.1, 0.1);
97 /* Corners of the image: A highly specular point, and a
98 * non-specular point.
100 pass &= piglit_probe_pixel_rgb(0, 0, test_specular);
101 pass &= piglit_probe_pixel_rgb(WIDTH - 1, HEIGHT - 1,
102 test_nonspecular);
104 /* Look at a bump -- does it have a lit part and an unlit part? */
105 pass &= piglit_probe_pixel_rgb(bump_x + w / 16, bump_y + h / 16,
106 test_bump_dark);
107 pass &= piglit_probe_pixel_rgb(bump_x - w / 16, bump_y - h / 16,
108 test_bump_light);
110 piglit_present_results();
112 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
115 void
116 piglit_init(int argc, char **argv)
118 GLint vs, fs;
120 piglit_require_gl_version(20);
122 vs = piglit_compile_shader(GL_VERTEX_SHADER,
123 "shaders/glsl-orangebook-ch06-bump.vert");
124 fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
125 "shaders/glsl-orangebook-ch06-bump.frag");
127 prog = piglit_link_simple_program(vs, fs);
129 glUseProgram(prog);
131 bump_density_location = glGetUniformLocation(prog, "BumpDensity");
132 bump_size_location = glGetUniformLocation(prog, "BumpSize");
133 specular_factor_location = glGetUniformLocation(prog, "SpecularFactor");
134 surface_color_location = glGetUniformLocation(prog, "SurfaceColor");
135 light_position_location = glGetUniformLocation(prog, "LightPosition");
136 assert(bump_density_location != -1);
137 assert(bump_size_location != -1);
138 assert(specular_factor_location != -1);
139 assert(surface_color_location != -1);
140 assert(light_position_location != -1);
142 tangent_attrib = glGetAttribLocation(prog, "Tangent");
143 assert(tangent_attrib != -1);