arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-incomplete-invalid-texture.c
blobf5acf27fa3b416eefa3d462b82b03ce3b87fe7dd
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
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.
24 /**
25 * \file fbo-incomplete-invalid-texture.c
26 * Try reproducing a segfault in Mesa by attaching a "broken" texture to an
27 * FBO, the unbind and rebind the FBO.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
36 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
37 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
39 PIGLIT_GL_TEST_CONFIG_END
41 enum piglit_result
42 piglit_display(void)
44 return PIGLIT_FAIL;
47 void
48 piglit_init(int argc, char **argv)
50 bool pass = true;
51 GLuint tex;
52 GLuint fbo;
53 GLenum status;
55 piglit_require_extension("GL_ARB_framebuffer_object");
56 piglit_require_extension("GL_ARB_depth_texture");
58 glGenTextures(1, &tex);
59 glBindTexture(GL_TEXTURE_2D, tex);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
62 glGenFramebuffers(1, &fbo);
63 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
65 /* The format of the pixel data is invalid for the specified
66 * internalFormat. This should fail and generate
67 * GL_INVALID_OPERATION. This leaves the texture in a weird, broken
68 * state.
70 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 4, 4, 0,
71 GL_RGBA, GL_FLOAT, NULL);
72 if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
73 pass = false;
74 goto cleanup;
77 /* Attach the broken texture to the FBO.
79 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
80 GL_TEXTURE_2D, tex, 0);
81 if (!piglit_check_gl_error(GL_NO_ERROR)) {
82 pass = false;
83 goto cleanup;
86 /* Unbind and rebind the FBO. At one point on Mesa this triggered a
87 * segfault down inside the glBindFramebuffer code.
89 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
90 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
92 status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
93 if (status != GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
94 fprintf(stderr,
95 "status was %s (0x%04x), expected %s (0x%04x).\n",
96 piglit_get_gl_enum_name(status),
97 status,
98 "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT",
99 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
100 pass = false;
101 goto cleanup;
104 cleanup:
105 glBindTexture(GL_TEXTURE_2D, 0);
106 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
108 glDeleteTextures(1, &tex);
109 glDeleteFramebuffers(1, &fbo);
111 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);