ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_seamless_cube_map / three-faces-average.c
blobb4c794f2b5d4884d50c39ce27def11c899840844
1 /*
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
41 * that value."
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
55 const char *vs_text =
57 "#version 130\n"
58 "\n"
59 "in vec2 vertex;\n"
60 "\n"
61 "void main() {\n"
62 " gl_Position = vec4(vertex.xy, 0, 1);\n"
63 "}\n"
66 const char *fs_text =
68 "#version 130\n"
69 "\n"
70 "uniform samplerCube cubeTex;\n"
71 "uniform vec3 cubeVec;\n"
72 "\n"
73 "void main() {\n"
74 " gl_FragColor = texture(cubeTex, cubeVec);\n"
75 "}\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. };
82 static GLuint prog;
83 static GLuint vao;
84 static GLuint vbo;
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] =
102 { -1., -1. },
103 { -1., 0. },
104 { 0., 0. },
105 { 0., -1. }
108 static GLfloat quad_02[4][2] =
110 { 0., 0. },
111 { 0., 1. },
112 { 1., 1. },
113 { 1., 0. }
116 void piglit_init( int argc, char **argv)
118 GLint i;
119 GLuint vertex_index;
121 if(piglit_get_gl_version() < 32) {
122 piglit_require_extension("GL_ARB_seamless_cube_map");
123 piglit_require_GLSL_version(130);
126 /* create program */
127 prog = piglit_build_simple_program(vs_text, fs_text);
128 glUseProgram(prog);
130 /* create buffers */
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),
136 &quad_01);
137 glBufferSubData(GL_ARRAY_BUFFER, sizeof(quad_01), sizeof(quad_02),
138 &quad_02);
140 glGenVertexArrays(1, &vao);
141 glBindVertexArray(vao);
143 vertex_index = glGetAttribLocation(prog, "vertex");
145 /* vertex attribs */
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,
157 green);
158 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
159 GL_LINEAR);
160 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
161 GL_LINEAR);
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,
166 GL_FLOAT, red);
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,
172 GL_FLOAT, blue);
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)
185 bool pass = true;
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);
199 /* expect red */
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);
206 /* expect blue */
207 pass = piglit_probe_rect_rgb(w, h, w, h, blue) && pass;
209 piglit_present_results();
211 return pass ? PIGLIT_PASS : PIGLIT_FAIL;