2 * Copyright © 2009 Intel Corporation
3 * Copyright (c) 2010 VMware, Inc.
4 * Copyright © 2012 Red Hat Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 /** @file fbo-cubemap-array.c
32 * Tests that drawing to each level of an cubemap array texture FBO and then
33 * drawing views * of those individual layerfaces to the window system framebuffer succeeds.
34 * based on fbo-array.c
37 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 10;
46 config
.window_width
= 200;
47 config
.window_height
= 100;
48 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
56 float layer_color
[NUM_LAYERS
* NUM_FACES
][4] = {
79 int num_layers
= NUM_LAYERS
* NUM_FACES
;
81 static const char *prog
= "fbo-cubemap-array";
83 static const char *frag_shader_cube_array_text
=
85 "#extension GL_ARB_texture_cube_map_array : enable \n"
86 "uniform samplerCubeArray tex; \n"
89 " gl_FragColor = texture(tex, gl_TexCoord[0]); \n"
92 static GLuint program_cube_array
;
95 create_array_fbo(void)
101 glGenTextures(1, &tex
);
102 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, tex
);
103 if (!piglit_check_gl_error(GL_NO_ERROR
))
104 piglit_report_result(PIGLIT_FAIL
);
106 /* allocate empty array texture */
107 glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, 0, GL_RGBA
,
108 BUF_WIDTH
, BUF_HEIGHT
, num_layers
,
110 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
111 if (!piglit_check_gl_error(GL_NO_ERROR
))
112 piglit_report_result(PIGLIT_FAIL
);
114 glGenFramebuffersEXT(1, &fb
);
115 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
117 /* draw something into each layer of the array texture */
118 for (layer
= 0; layer
< num_layers
; layer
++) {
119 glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT
,
120 GL_COLOR_ATTACHMENT0_EXT
,
125 if (!piglit_check_gl_error(GL_NO_ERROR
))
126 piglit_report_result(PIGLIT_FAIL
);
128 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
129 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
130 fprintf(stderr
, "%s: FBO incomplete\n", prog
);
131 piglit_report_result(PIGLIT_SKIP
);
134 glViewport(0, 0, BUF_WIDTH
, BUF_HEIGHT
);
135 piglit_ortho_projection(BUF_WIDTH
, BUF_HEIGHT
, GL_FALSE
);
137 /* solid color quad */
138 glColor4fv(layer_color
[layer
]);
139 piglit_draw_rect(-2, -2, BUF_WIDTH
+ 2, BUF_HEIGHT
+ 2);
142 glDeleteFramebuffersEXT(1, &fb
);
146 GLfloat a_cube_face_texcoords
[6][4][4];
148 void setup_texcoords(void)
151 for (i
= 0; i
< 6; i
++) {
152 for (j
= 0; j
< 4; j
++) {
153 memcpy(a_cube_face_texcoords
[i
][j
], cube_face_texcoords
[i
][j
], 3 * sizeof(GLfloat
));
158 /* Draw a textured quad, sampling only the given layerface of the
162 draw_layer(int x
, int y
, int layerface
)
164 GLint face
= layerface
% 6;
165 GLint layer
= layerface
/ 6;
168 glUseProgram(program_cube_array
);
169 loc
= glGetUniformLocation(program_cube_array
, "tex");
170 glUniform1i(loc
, 0); /* texture unit p */
172 glViewport(0, 0, piglit_width
, piglit_height
);
173 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
175 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
177 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
178 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
179 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
180 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
181 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
182 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_ARB
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
185 a_cube_face_texcoords
[face
][0][3] = layer
;
186 a_cube_face_texcoords
[face
][1][3] = layer
;
187 a_cube_face_texcoords
[face
][2][3] = layer
;
188 a_cube_face_texcoords
[face
][3][3] = layer
;
190 glTexCoord4fv(a_cube_face_texcoords
[face
][0]);
193 glTexCoord4fv(a_cube_face_texcoords
[face
][1]);
194 glVertex2f(x
+ BUF_WIDTH
, y
);
196 glTexCoord4fv(a_cube_face_texcoords
[face
][2]);
197 glVertex2f(x
+ BUF_WIDTH
, y
+ BUF_HEIGHT
);
199 glTexCoord4fv(a_cube_face_texcoords
[face
][3]);
200 glVertex2f(x
, y
+ BUF_HEIGHT
);
207 static GLboolean
test_layer_drawing(int start_x
, int start_y
, float *expected
)
209 return piglit_probe_rect_rgb(start_x
, start_y
, BUF_WIDTH
, BUF_HEIGHT
,
216 GLboolean pass
= GL_TRUE
;
221 glClearColor(1.0, 1.0, 1.0, 1.0);
222 glClear(GL_COLOR_BUFFER_BIT
);
224 tex
= create_array_fbo();
227 for (layer
= 0; layer
< num_layers
; layer
++) {
228 int x
= 1 + (layer
% 6) * (BUF_WIDTH
+ 1);
231 draw_layer(x
, y
* BUF_HEIGHT
, layer
);
236 for (layer
= 0; layer
< num_layers
; layer
++) {
237 int x
= 1 + (layer
% 6) * (BUF_WIDTH
+ 1);
240 pass
&= test_layer_drawing(x
, y
* BUF_HEIGHT
, layer_color
[layer
]);
243 glDeleteTextures(1, &tex
);
245 piglit_present_results();
247 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
250 void piglit_init(int argc
, char **argv
)
252 piglit_require_extension("GL_ARB_texture_cube_map_array");
255 piglit_build_simple_program(NULL
, frag_shader_cube_array_text
);