2 * Copyright (c) 2013 Bruce Merry
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COYPRIGTH
19 * HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "piglit-util-gl.h"
29 const char *extension
;
31 int buffer
; /* Draw buffer to attach the renderbuffer to */
34 static const format_info formats
[] = {
35 { GL_RGBA8
, NULL
, { 0, 0, 0, 0 } },
36 { GL_R8I
, "GL_ARB_texture_rg", { 1, 0, 0, 0 } },
37 { GL_RG8I
, "GL_ARB_texture_rg", { 1, 1, 0, 0 } },
38 { GL_R8_SNORM
, "GL_EXT_texture_snorm", { 1, 0, 0, 0 } },
39 { GL_LUMINANCE8_SNORM
, "GL_EXT_texture_snorm", { 1, 1, 1, 0 } },
40 { GL_RGBA8UI_EXT
, "GL_EXT_texture_integer", { 0, 0, 0, 0 } },
41 { GL_RGBA16F_ARB
, "GL_ARB_texture_float", { 1, 1, 1, 1 } },
42 { GL_LUMINANCE16F_ARB
, "GL_ARB_texture_float", { 1, 1, 1, 0 } },
43 { GL_RGB9_E5_EXT
, "GL_EXT_texture_shared_exponent", { 0, 0, 0, 0 } },
44 { GL_R11F_G11F_B10F_EXT
, "GL_EXT_packed_float", { 0, 0, 0, 0 } },
45 { GL_RGBA16F_ARB
, "GL_ARB_texture_float", { 0, 0, 0, 0 }, 1 }
48 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config
.supports_gl_compat_version
= 10;
50 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
51 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
52 PIGLIT_GL_TEST_CONFIG_END
57 /* Should never be reached */
61 /* Queries GL_RGBA_SIGNED_COMPONENTS_EXT and compares to expected.
62 * If they do not match, prints an error. Returns true on match.
64 static bool check_rgba_signed(const int *expected
)
67 /* Start with nonsense values, to ensure they are written */
68 GLint actual
[4] = {2, 2, 2, 2};
70 glGetIntegerv(GL_RGBA_SIGNED_COMPONENTS_EXT
, actual
);
71 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
75 for (i
= 0; i
< 4; i
++) {
76 if (expected
[i
] != actual
[i
]) {
77 printf("Expected: (%d, %d, %d, %d)\n",
82 printf("Actual: (%d, %d, %d, %d)\n",
93 static bool test_format(const format_info
*f
)
98 if (f
->extension
!= NULL
99 && !piglit_is_extension_supported(f
->extension
)) {
100 printf("Skipping %s since %s not present\n",
101 piglit_get_gl_enum_name(f
->format
), f
->extension
);
105 glGenRenderbuffers(1, &rbo
);
106 glBindRenderbuffer(GL_RENDERBUFFER
, rbo
);
107 glRenderbufferStorage(
110 glFramebufferRenderbuffer(
112 GL_COLOR_ATTACHMENT0
+ f
->buffer
,
113 GL_RENDERBUFFER
, rbo
);
114 if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER
)
115 != GL_FRAMEBUFFER_COMPLETE
) {
116 printf("Skipping %s: framebuffer not complete\n",
117 piglit_get_gl_enum_name(f
->format
));
119 printf("Testing %s\n", piglit_get_gl_enum_name(f
->format
));
120 if (!check_rgba_signed(f
->expected
))
124 glFramebufferRenderbuffer(
126 GL_COLOR_ATTACHMENT0
+ f
->buffer
,
128 glDeleteRenderbuffers(1, &rbo
);
133 piglit_init(int argc
, char **argv
)
135 int expected
[4] = {0, 0, 0, 0};
138 const GLenum buffers
[2] = {GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
};
140 piglit_require_extension("GL_EXT_packed_float");
142 /* With a normal window, all channels should be unsigned */
143 printf("Testing window\n");
144 if (!check_rgba_signed(expected
))
147 if (piglit_is_extension_supported("GL_ARB_framebuffer_object")) {
150 glGenFramebuffers(1, &fbo
);
151 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fbo
);
152 glDrawBuffers(2, buffers
);
153 /* Test a variety of FBO formats */
154 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
155 pass
= test_format(formats
+ i
) && pass
;
157 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
158 glDeleteFramebuffers(1, &fbo
);
161 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);