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
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 * Eric Anholt <eric@anholt.net>
28 /** @file glsl-fs-texturecube-2.c
30 * Tests that cubemap coordinates are appropriately normalized for
34 #include "piglit-util-gl.h"
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
50 static GLfloat colors
[][3] = {
62 set_face_image(GLenum face
, int color
)
64 GLfloat
*color1
= colors
[color
];
65 GLfloat
*color2
= colors
[(color
+ 1) % ARRAY_SIZE(colors
)];
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
;
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
);
98 GLboolean pass
= GL_TRUE
;
101 static GLboolean scale
= GL_TRUE
;
103 /* Rescale the coordinates to catch failure on hw that needs
104 * normalization of coords.
107 for (face
= 0; face
< 6; face
++) {
110 for (i
= 0; i
< 4; i
++) {
112 cube_face_texcoords
[face
][i
][0] *= s
;
113 cube_face_texcoords
[face
][i
][1] *= s
;
114 cube_face_texcoords
[face
][i
][2] *= s
;
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;
146 int y2
= piglit_height
;
150 glTexCoord3fv(cube_face_texcoords
[face
][0]);
153 glTexCoord3fv(cube_face_texcoords
[face
][1]);
156 glTexCoord3fv(cube_face_texcoords
[face
][2]);
159 glTexCoord3fv(cube_face_texcoords
[face
][3]);
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
;
171 if (piglit_width
!= SIZE
* 6 || piglit_height
!= SIZE
)
174 for (y
= 0; y
< SIZE
; y
++) {
175 for (x
= 0; x
< SIZE
; x
++) {
178 if (x
== 0 || y
== 0 ||
179 x
== SIZE
- 1 || y
== SIZE
- 1) {
185 pass
= pass
&& piglit_probe_pixel_rgb(fx
+ x
,
192 glDeleteTextures(1, &tex
);
194 piglit_present_results();
196 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
199 void piglit_init(int argc
, char **argv
)
203 GLboolean bias
= GL_FALSE
;
207 for (i
= 0; i
< argc
; i
++) {
208 if (!strcmp(argv
[i
], "-bias"))
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");
218 fs_name
= "shaders/glsl-fs-texturecube-bias.frag";
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
);
230 loc
= glGetUniformLocation(prog
, "sampler");