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.c
30 * Tests that we can access cubemaps in the fragment shader.
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_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
41 PIGLIT_GL_TEST_CONFIG_END
45 static GLfloat colors
[][3] = {
57 set_face_image(GLenum face
, int size
, int color
)
59 GLfloat
*color1
= colors
[color
];
60 GLfloat
*color2
= colors
[(color
+ 1) % ARRAY_SIZE(colors
)];
64 tex
= malloc(size
* size
* 3 * sizeof(GLfloat
));
66 /* Set the texture for this face to one corner being color2 and the
67 * rest color1. If the texture is 1x1, then it's all color1.
69 for (y
= 0; y
< size
; y
++) {
70 for (x
= 0; x
< size
; x
++) {
71 GLfloat
*chosen_color
;
73 if (y
>= (size
/ 2) || x
>= (size
/ 2))
74 chosen_color
= color1
;
76 chosen_color
= color2
;
78 tex
[(y
* size
+ x
) * 3 + 0] = chosen_color
[0];
79 tex
[(y
* size
+ x
) * 3 + 1] = chosen_color
[1];
80 tex
[(y
* size
+ x
) * 3 + 2] = chosen_color
[2];
84 glTexImage2D(face
, 0, GL_RGB
, size
, size
, 0, GL_RGB
, GL_FLOAT
, tex
);
93 GLboolean pass
= GL_TRUE
;
97 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
99 /* Create the texture. */
100 glGenTextures(1, &tex
);
101 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, tex
);
103 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
,
104 GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
105 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
,
106 GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
107 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
,
108 GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
109 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
,
110 GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
112 /* Fill in faces on each level */
113 for (face
= 0; face
< 6; face
++) {
114 set_face_image(cube_face_targets
[face
], 32, face
);
117 glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
119 for (face
= 0; face
< 6; face
++) {
120 int x1
= piglit_width
* face
/ 6;
121 int x2
= piglit_width
* (face
+ 1) / 6;
123 int y2
= piglit_height
;
128 GLfloat
*color1
= colors
[face
];
129 GLfloat
*color2
= colors
[face
+ 1];
133 glTexCoord3fv(cube_face_texcoords
[face
][0]);
136 glTexCoord3fv(cube_face_texcoords
[face
][1]);
139 glTexCoord3fv(cube_face_texcoords
[face
][2]);
142 glTexCoord3fv(cube_face_texcoords
[face
][3]);
147 pass
= pass
&& piglit_probe_pixel_rgb(tx1
, ty1
, color2
);
148 pass
= pass
&& piglit_probe_pixel_rgb(tx2
, ty1
, color1
);
149 pass
= pass
&& piglit_probe_pixel_rgb(tx1
, ty2
, color1
);
150 pass
= pass
&& piglit_probe_pixel_rgb(tx2
, ty2
, color1
);
153 glDeleteTextures(1, &tex
);
155 piglit_present_results();
157 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
160 void piglit_init(int argc
, char **argv
)
164 GLboolean bias
= GL_FALSE
;
168 for (i
= 0; i
< argc
; i
++) {
169 if (!strcmp(argv
[i
], "-bias"))
173 piglit_require_gl_version(20);
174 piglit_require_extension("GL_ARB_texture_cube_map");
176 vs
= piglit_compile_shader(GL_VERTEX_SHADER
,
177 "shaders/glsl-tex-mvp.vert");
179 fs_name
= "shaders/glsl-fs-texturecube-bias.frag";
181 fs_name
= "shaders/glsl-fs-texturecube.frag";
183 fs
= piglit_compile_shader(GL_FRAGMENT_SHADER
, fs_name
);
185 prog
= piglit_link_simple_program(vs
, fs
);
186 if (!piglit_link_check_status(prog
))
187 piglit_report_result(PIGLIT_FAIL
);
191 loc
= glGetUniformLocation(prog
, "sampler");