2 * Copyright © 2009 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 fbo-cubemap.c
30 * Tests that drawing to each face of a cube map FBO and then drawing views
31 * of those faces to the window system framebuffer succeeds.
34 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
43 config
.window_width
= 200;
44 config
.window_height
= 100;
45 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
50 float face_color
[7][4] = {
60 static float *get_face_color(int face
, int level
)
62 return face_color
[(face
+ 2 * level
) % 7];
72 glGenTextures(1, &tex
);
73 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
75 for (face
= 0; face
< 6; face
++) {
78 for (dim
= BUF_WIDTH
; dim
> 0; dim
/= 2) {
79 glTexImage2D(cube_face_targets
[face
], level
, GL_RGBA
,
82 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
86 if (!piglit_check_gl_error(GL_NO_ERROR
))
87 piglit_report_result(PIGLIT_FAIL
);
89 glGenFramebuffersEXT(1, &fb
);
90 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
92 for (face
= 0; face
< 6; face
++) {
95 for (dim
= BUF_WIDTH
; dim
> 0; dim
/= 2) {
96 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
97 GL_COLOR_ATTACHMENT0_EXT
,
98 cube_face_targets
[face
],
102 if (!piglit_check_gl_error(GL_NO_ERROR
))
103 piglit_report_result(PIGLIT_FAIL
);
105 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
106 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
107 fprintf(stderr
, "FBO incomplete\n");
111 glViewport(0, 0, dim
, dim
);
112 piglit_ortho_projection(dim
, dim
, GL_FALSE
);
114 glColor4fv(get_face_color(face
, level
));
115 /* Draw a little outside the bounds to make
116 * sure clipping's working.
118 piglit_draw_rect(-2, -2, dim
+ 2, dim
+ 2);
126 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
127 glDeleteFramebuffersEXT(1, &fb
);
133 draw_face(int x
, int y
, int dim
, int face
)
135 glViewport(0, 0, piglit_width
, piglit_height
);
136 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
138 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
140 glEnable(GL_TEXTURE_CUBE_MAP
);
141 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
142 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
);
143 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
147 glTexCoord3fv(cube_face_texcoords
[face
][0]);
150 glTexCoord3fv(cube_face_texcoords
[face
][1]);
151 glVertex2f(x
+ dim
, y
);
153 glTexCoord3fv(cube_face_texcoords
[face
][2]);
154 glVertex2f(x
+ dim
, y
+ dim
);
156 glTexCoord3fv(cube_face_texcoords
[face
][3]);
157 glVertex2f(x
, y
+ dim
);
161 glDisable(GL_TEXTURE_CUBE_MAP
);
164 static GLboolean
test_face_drawing(int start_x
, int start_y
, int dim
,
167 return piglit_probe_rect_rgb(start_x
, start_y
, dim
, dim
, expected
);
173 GLboolean pass
= GL_TRUE
;
177 glClearColor(0.5, 0.5, 0.5, 0.5);
178 glClear(GL_COLOR_BUFFER_BIT
);
180 tex
= create_cube_fbo();
182 for (face
= 0; face
< 6; face
++) {
183 int x
= 1 + face
* (BUF_WIDTH
+ 1);
186 for (dim
= BUF_WIDTH
; dim
> 0; dim
/= 2) {
187 draw_face(x
, y
, dim
, face
);
192 for (face
= 0; face
< 6; face
++) {
193 int x
= 1 + face
* (BUF_WIDTH
+ 1);
197 for (dim
= BUF_WIDTH
; dim
> 2; dim
>>= 1) {
198 pass
&= test_face_drawing(x
, y
, dim
,
199 get_face_color(face
, level
));
205 glDeleteTextures(1, &tex
);
207 piglit_present_results();
209 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
212 void piglit_init(int argc
, char **argv
)
214 piglit_require_extension("GL_EXT_framebuffer_object");
215 piglit_require_extension("GL_ARB_texture_cube_map");