1 /*
2  * Copyright © 2010 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 /**
25  * \file fbo-incomplete-texture-03.c
26  * Verify that an FBO with an incomplete texture attached is complete
27  *
28  * This test uses a cube map where one of the faces is specified with the
29  * wrong size.  This test originally wanted the FBO to be incomplete.
30  * However, this just verified incorrect behavior in another vendor's driver.
31  *
32  * \author Ian Romanick <ian.d.romanick@intel.com>
33  */
34 
35 #include "piglit-util-gl.h"
36 
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 
39 	config.supports_gl_compat_version = 10;
40 
41 	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
42 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 
44 PIGLIT_GL_TEST_CONFIG_END
45 
46 enum piglit_result
piglit_display(void)47 piglit_display(void)
48 {
49 	return PIGLIT_FAIL;
50 }
51 
52 void
piglit_init(int argc,char ** argv)53 piglit_init(int argc, char **argv)
54 {
55 	GLuint tex;
56 	GLuint fb;
57 	GLenum status;
58 	const float color[] = {1.0,0.0,0.0,1.0};
59 
60 	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
61 
62 	piglit_require_extension("GL_ARB_framebuffer_object");
63 	piglit_require_extension("GL_ARB_texture_cube_map");
64 
65 	/* This texture will be incomplete because one of the cubemap faces
66 	 * has the wrong size.
67 	 */
68 	glGenTextures(1, &tex);
69 	glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
70 	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 32, 32, 0,
71 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
72 	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 32, 32, 0,
73 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
74 	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 32, 32, 0,
75 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
76 	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 32, 32, 0,
77 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
78 	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 32, 32, 0,
79 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
80 	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 64, 64, 0,
81 		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
82 
83 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
84 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
85 
86 	glGenFramebuffers(1, &fb);
87 	glBindFramebuffer(GL_FRAMEBUFFER, fb);
88 	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
89 			       GL_TEXTURE_CUBE_MAP_POSITIVE_X, tex, 0);
90 
91 	if (!piglit_check_gl_error(GL_NO_ERROR))
92 		piglit_report_result(PIGLIT_FAIL);
93 
94 	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
95 	if (status != GL_FRAMEBUFFER_COMPLETE) {
96 		fprintf(stderr, "FBO erroneously incomplete: 0x%04x\n",
97 			status);
98 		piglit_report_result(PIGLIT_FAIL);
99 	}
100 
101 	glClearColor(color[0], color[1], color[2], color[3]);
102 	glClear(GL_COLOR_BUFFER_BIT);
103 
104 	if (!piglit_check_gl_error(GL_NO_ERROR))
105 		piglit_report_result(PIGLIT_FAIL);
106 
107 	if (!piglit_probe_texel_rect_rgba(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,
108 					  0, 0, 32, 32, color)) {
109 		fprintf(stderr, "FBO clear didn't work\n");
110 		piglit_report_result(PIGLIT_FAIL);
111 	}
112 
113 	piglit_report_result(PIGLIT_PASS);
114 }
115