glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / glsl-fs-texturecube-2.c
blobc6543e06d841503a8c6e82569f6f683bc3ce44a5
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-fs-texturecube-2.c
30 * Tests that cubemap coordinates are appropriately normalized for
31 * sampling.
34 #include "piglit-util-gl.h"
36 #define SIZE 32
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config.supports_gl_compat_version = 10;
42 config.window_width = SIZE*6;
43 config.window_height = SIZE;
44 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
46 PIGLIT_GL_TEST_CONFIG_END
48 static GLint prog;
50 static GLfloat colors[][3] = {
51 {1.0, 1.0, 1.0},
52 {1.0, 1.0, 0.0},
53 {1.0, 0.0, 0.0},
54 {1.0, 0.0, 1.0},
55 {0.0, 0.0, 1.0},
56 {0.0, 1.0, 1.0},
57 {0.0, 1.0, 0.0},
61 static void
62 set_face_image(GLenum face, int color)
64 GLfloat *color1 = colors[color];
65 GLfloat *color2 = colors[(color + 1) % ARRAY_SIZE(colors)];
66 GLfloat *tex;
67 int x, y;
69 tex = malloc(SIZE * SIZE * 3 * sizeof(GLfloat));
71 /* Set the texture for this face the edge pixels being color1
72 * and everything else being color2.
74 for (y = 0; y < SIZE; y++) {
75 for (x = 0; x < SIZE; x++) {
76 GLfloat *chosen_color;
78 if (x == 0 || x == SIZE - 1 || y == 0 || y == SIZE - 1)
79 chosen_color = color1;
80 else
81 chosen_color = color2;
83 tex[(y * SIZE + x) * 3 + 0] = chosen_color[0];
84 tex[(y * SIZE + x) * 3 + 1] = chosen_color[1];
85 tex[(y * SIZE + x) * 3 + 2] = chosen_color[2];
89 glTexImage2D(face, 0, GL_RGB, SIZE, SIZE, 0, GL_RGB, GL_FLOAT, tex);
91 free(tex);
95 enum piglit_result
96 piglit_display(void)
98 GLboolean pass = GL_TRUE;
99 GLuint tex;
100 int face;
101 static GLboolean scale = GL_TRUE;
103 /* Rescale the coordinates to catch failure on hw that needs
104 * normalization of coords.
106 if (scale) {
107 for (face = 0; face < 6; face++) {
108 int i;
110 for (i = 0; i < 4; i++) {
111 float s = 4;
112 cube_face_texcoords[face][i][0] *= s;
113 cube_face_texcoords[face][i][1] *= s;
114 cube_face_texcoords[face][i][2] *= s;
117 scale = GL_FALSE;
120 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
122 /* Create the texture. */
123 glGenTextures(1, &tex);
124 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, tex);
126 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
127 GL_TEXTURE_MIN_FILTER, GL_NEAREST);
128 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
129 GL_TEXTURE_MAG_FILTER, GL_NEAREST);
130 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
131 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
132 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
133 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
135 /* Fill in faces on each level */
136 for (face = 0; face < 6; face++) {
137 set_face_image(cube_face_targets[face], face);
140 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
142 for (face = 0; face < 6; face++) {
143 int x1 = piglit_width * face / 6;
144 int x2 = piglit_width * (face + 1) / 6;
145 int y1 = 0;
146 int y2 = piglit_height;
148 glBegin(GL_QUADS);
150 glTexCoord3fv(cube_face_texcoords[face][0]);
151 glVertex2f(x1, y1);
153 glTexCoord3fv(cube_face_texcoords[face][1]);
154 glVertex2f(x2, y1);
156 glTexCoord3fv(cube_face_texcoords[face][2]);
157 glVertex2f(x2, y2);
159 glTexCoord3fv(cube_face_texcoords[face][3]);
160 glVertex2f(x1, y2);
162 glEnd();
165 for (face = 0; face < 6; face++) {
166 GLfloat *color1 = colors[face];
167 GLfloat *color2 = colors[(face + 1) % ARRAY_SIZE(colors)];
168 int fx = face * SIZE;
169 int x, y;
171 if (piglit_width != SIZE * 6 || piglit_height != SIZE)
172 break;
174 for (y = 0; y < SIZE; y++) {
175 for (x = 0; x < SIZE; x++) {
176 float *color;
178 if (x == 0 || y == 0 ||
179 x == SIZE - 1 || y == SIZE - 1) {
180 color = color1;
181 } else {
182 color = color2;
185 pass = pass && piglit_probe_pixel_rgb(fx + x,
187 color);
192 glDeleteTextures(1, &tex);
194 piglit_present_results();
196 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
199 void piglit_init(int argc, char **argv)
201 GLint vs, fs;
202 int loc;
203 GLboolean bias = GL_FALSE;
204 char *fs_name;
205 int i = 0;
207 for (i = 0; i < argc; i++) {
208 if (!strcmp(argv[i], "-bias"))
209 bias = GL_TRUE;
212 piglit_require_gl_version(20);
213 piglit_require_extension("GL_ARB_texture_cube_map");
215 vs = piglit_compile_shader(GL_VERTEX_SHADER,
216 "shaders/glsl-tex-mvp.vert");
217 if (bias) {
218 fs_name = "shaders/glsl-fs-texturecube-bias.frag";
219 } else {
220 fs_name = "shaders/glsl-fs-texturecube.frag";
222 fs = piglit_compile_shader(GL_FRAGMENT_SHADER, fs_name);
224 prog = piglit_link_simple_program(vs, fs);
225 if (!piglit_link_check_status(prog))
226 piglit_report_result(PIGLIT_FAIL);
228 glUseProgram(prog);
230 loc = glGetUniformLocation(prog, "sampler");
231 glUniform1i(loc, 0);