2 * Copyright © 2012 VMware, Inc.
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
25 * Test that FBO memory is initialized to a constant color and not stale
26 * data that may show old contents of VRAM.
28 * To pass this test an OpenGL implementation should initialize the
29 * contents of the new buffer to some fixed value (like all zeros).
30 * But since that's not spec'd by OpenGL, we only return WARN instead of
31 * FAIL if that's not the case.
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
43 config
.window_width
= 512;
44 config
.window_height
= 512;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
47 PIGLIT_GL_TEST_CONFIG_END
50 static GLuint fbo
, rb
;
56 GLfloat firstPixel
[4];
59 /* read from fbo, draw to window */
60 glBindFramebuffer(GL_READ_FRAMEBUFFER
, fbo
);
61 glReadBuffer(GL_COLOR_ATTACHMENT0
);
62 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
63 glDrawBuffer(GL_BACK
);
65 /* init color buffer to red */
66 glClearColor(1, 0, 0, 1);
67 glClear(GL_COLOR_BUFFER_BIT
);
69 /* copy (undefined) fbo image to window */
71 glCopyPixels(0, 0, piglit_width
, piglit_height
, GL_COLOR
);
73 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
74 glReadBuffer(GL_BACK
);
76 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_FLOAT
, firstPixel
);
77 pass
= piglit_probe_rect_rgb(0, 0, piglit_width
, piglit_height
,
80 piglit_present_results();
82 return pass
? PIGLIT_PASS
: PIGLIT_WARN
;
87 piglit_init(int argc
, char **argv
)
89 piglit_require_extension("GL_ARB_framebuffer_object");
91 glGenFramebuffers(1, &fbo
);
92 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
93 glGenRenderbuffers(1, &rb
);
94 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
95 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA
,
96 piglit_width
, piglit_height
);
97 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
100 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
101 printf("fbo creation error\n");
102 piglit_report_result(PIGLIT_FAIL
);
106 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
107 GL_FRAMEBUFFER_COMPLETE
) {
108 printf("fbo incomplete\n");
109 piglit_report_result(PIGLIT_FAIL
);
113 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
114 glViewport(0, 0, piglit_width
, piglit_height
);