Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-orangebook-ch06-bump.c
blob960516e6e27fd85ff67b82824fdd9844d5ed569b
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.h"
36 int piglit_width = 100, piglit_height = 100;
37 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
39 static int bump_density_location, bump_size_location;
40 static int specular_factor_location, surface_color_location;
41 static int light_position_location, tangent_attrib;
42 static GLint prog;
44 enum piglit_result
45 piglit_display(void)
47 GLboolean pass = GL_TRUE;
48 static const float surface_color[3] = {0.7, 0.6, 0.18};
49 static const float test_specular[3] = {0.976, 0.894, 0.549};
50 static const float test_nonspecular[3] = {0.572, 0.490, 0.145};
51 static const float test_bump_dark[3] = {0.411, 0.352, 0.105};
52 static const float test_bump_light[3] = {1.0, 0.961, 0.557};
53 float light_position[3] = {-1.0, -1.0, 2.0};
54 float w = piglit_width;
55 float h = piglit_height;
56 float bump_x = w * 3 / 8;
57 float bump_y = h * 3 / 8;
58 float x, y;
60 piglit_ortho_projection(1, 1, GL_FALSE);
62 glClearColor(0.5, 0.5, 0.5, 0.5);
63 glClear(GL_COLOR_BUFFER_BIT);
65 glUniform1f(bump_density_location, 4);
66 glUniform1f(bump_size_location, 0.15);
67 glUniform1f(specular_factor_location, 0.5);
68 glUniform3fv(surface_color_location, 1, surface_color);
69 glUniform3fv(light_position_location, 1, light_position);
71 glTranslatef(0, 0, -0.5);
72 glNormal3f(0.0, 0.0, 1.0);
73 glVertexAttrib3f(tangent_attrib, 1.0, 0.0, 0.0);
74 for (x = 0.0; x < 1.0; x += 0.1) {
75 for (y = 0.0; y < 1.0; y += 0.1) {
76 piglit_draw_rect_tex(x, y, 0.1, 0.1,
77 x, y, 0.1, 0.1);
81 /* Corners of the image: A highly specular point, and a
82 * non-specular point.
84 pass &= piglit_probe_pixel_rgb(0, 0, test_specular);
85 pass &= piglit_probe_pixel_rgb(piglit_width - 1, piglit_height - 1,
86 test_nonspecular);
88 /* Look at a bump -- does it have a lit part and an unlit part? */
89 pass &= piglit_probe_pixel_rgb(bump_x + w / 16, bump_y + h / 16,
90 test_bump_dark);
91 pass &= piglit_probe_pixel_rgb(bump_x - w / 16, bump_y - h / 16,
92 test_bump_light);
94 glutSwapBuffers();
96 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
99 void
100 piglit_init(int argc, char **argv)
102 GLint vs, fs;
104 if (!GLEW_VERSION_2_0) {
105 printf("Requires OpenGL 2.0\n");
106 piglit_report_result(PIGLIT_SKIP);
109 vs = piglit_compile_shader(GL_VERTEX_SHADER,
110 "shaders/glsl-orangebook-ch06-bump.vert");
111 fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
112 "shaders/glsl-orangebook-ch06-bump.frag");
114 prog = piglit_link_simple_program(vs, fs);
116 glUseProgram(prog);
118 bump_density_location = glGetUniformLocation(prog, "BumpDensity");
119 bump_size_location = glGetUniformLocation(prog, "BumpSize");
120 specular_factor_location = glGetUniformLocation(prog, "SpecularFactor");
121 surface_color_location = glGetUniformLocation(prog, "SurfaceColor");
122 light_position_location = glGetUniformLocation(prog, "LightPosition");
123 assert(bump_density_location != -1);
124 assert(bump_size_location != -1);
125 assert(specular_factor_location != -1);
126 assert(surface_color_location != -1);
127 assert(light_position_location != -1);
129 tangent_attrib = glGetAttribLocation(prog, "Tangent");
130 assert(tangent_attrib != -1);