2 * Copyright © 2013 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 shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Test verifies that when sampling from three adjoining faces in a cube map,
24 * samples will be averaged. If they share the same value, that value must be
25 * guaranteed to be the result of the average. Resulting color should not
26 * include border color contamination.
30 * ARB_seamless_cube_map Section 3.8.7 says:
31 * "If LINEAR filtering is done within a miplevel, always apply wrap mode
32 * CLAMP_TO_BORDER. Then, ...
34 * If a texture sample location would lie in the texture border in
35 * both u and v (in one of the corners of the cube), there is no
36 * unique neighboring face from which to extract one texel. The
37 * recommended method is to average the values of the three
38 * available samples. However, implementations are free to
39 * construct this fourth texel in another way, so long as, when the
40 * three available samples have the same value, this texel also has
44 #include "piglit-util-gl.h"
46 PIGLIT_GL_TEST_CONFIG_BEGIN
48 config
.supports_gl_compat_version
= 10;
49 config
.supports_gl_core_version
= 31;
51 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
53 PIGLIT_GL_TEST_CONFIG_END
62 " gl_Position = vec4(vertex.xy, 0, 1);\n"
70 "uniform samplerCube cubeTex;\n"
71 "uniform vec3 cubeVec;\n"
74 " gl_FragColor = texture(cubeTex, cubeVec);\n"
78 static const float red
[3] = { 1., 0., 0. };
79 static const float blue
[3] = { 0., 0., 1. };
80 static const float green
[3] = { 0., 1.0, 0. };
85 static GLuint cubeMap
;
87 static GLint cubeVec_loc
;
88 static GLfloat cubeVecPositive
[3] = { 0.5, 0.5, 0.5 };
89 static GLfloat cubeVecNegative
[3] = { -0.5, -0.5, -0.5 };
91 static const GLenum targets
[6] = {
92 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
,
93 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
,
94 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
,
95 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
,
96 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
,
97 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
100 static GLfloat quad_01
[4][2] =
108 static GLfloat quad_02
[4][2] =
116 void piglit_init( int argc
, char **argv
)
121 if(piglit_get_gl_version() < 32) {
122 piglit_require_extension("GL_ARB_seamless_cube_map");
123 piglit_require_GLSL_version(130);
127 prog
= piglit_build_simple_program(vs_text
, fs_text
);
131 glGenBuffers(1, &vbo
);
132 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
133 glBufferData(GL_ARRAY_BUFFER
, sizeof(quad_01
) + sizeof(quad_02
),
134 NULL
, GL_STATIC_DRAW
);
135 glBufferSubData(GL_ARRAY_BUFFER
, 0, sizeof(quad_01
),
137 glBufferSubData(GL_ARRAY_BUFFER
, sizeof(quad_01
), sizeof(quad_02
),
140 glGenVertexArrays(1, &vao
);
141 glBindVertexArray(vao
);
143 vertex_index
= glGetAttribLocation(prog
, "vertex");
146 glEnableVertexAttribArray(vertex_index
);
148 glVertexAttribPointer(vertex_index
, 2, GL_FLOAT
, GL_FALSE
, 0, 0);
150 glGenTextures(1, &cubeMap
);
151 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, cubeMap
);
153 /* set filter to linear, hardware should behave as if wrap modes are
154 * set to CLAMP_TO_BORDER
156 glTexParameterfv(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_BORDER_COLOR
,
158 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
,
160 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
,
163 /* texture positive axes/faces red */
164 for(i
= 0; i
< 3; i
++) {
165 glTexImage2D(targets
[i
], 0, GL_RGBA8
, 1, 1, 0, GL_RGB
,
169 /* texuture negative axes/faces blue */
170 for(i
= 3; i
< 6; i
++) {
171 glTexImage2D(targets
[i
], 0, GL_RGBA8
, 1, 1, 0, GL_RGB
,
175 /* uniform texcoord input */
176 cubeVec_loc
= glGetUniformLocation(prog
, "cubeVec");
178 if(!piglit_check_gl_error(GL_NO_ERROR
))
179 piglit_report_result(PIGLIT_FAIL
);
183 enum piglit_result
piglit_display(void)
186 int w
= piglit_width
/ 2;
187 int h
= piglit_height
/ 2;
189 glViewport(0, 0, piglit_width
, piglit_height
);
191 glClear(GL_COLOR_BUFFER_BIT
);
193 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS
);
195 /* texcoords should target vector to upper corner */
196 glUniform3fv(cubeVec_loc
, 1, cubeVecPositive
);
197 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
200 pass
= piglit_probe_rect_rgb(0, 0, w
, h
, red
) && pass
;
202 /* texcoords should target vector to bottom corner */
203 glUniform3fv(cubeVec_loc
, 1, cubeVecNegative
);
204 glDrawArrays(GL_TRIANGLE_FAN
, 4, 4);
207 pass
= piglit_probe_rect_rgb(w
, h
, w
, h
, blue
) && pass
;
209 piglit_present_results();
211 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;