ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_packed_float / query-rgba-signed-components.c
blobf5c0047fa9b830ea279cc0952f5e58553f479c29
1 /*
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
13 * Software.
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"
27 typedef struct {
28 GLenum format;
29 const char *extension;
30 int expected[4];
31 int buffer; /* Draw buffer to attach the renderbuffer to */
32 } format_info;
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
54 enum piglit_result
55 piglit_display(void)
57 /* Should never be reached */
58 return PIGLIT_FAIL;
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)
66 int i;
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)) {
72 return false;
75 for (i = 0; i < 4; i++) {
76 if (expected[i] != actual[i]) {
77 printf("Expected: (%d, %d, %d, %d)\n",
78 expected[0],
79 expected[1],
80 expected[2],
81 expected[3]);
82 printf("Actual: (%d, %d, %d, %d)\n",
83 actual[0],
84 actual[1],
85 actual[2],
86 actual[3]);
87 return false;
90 return true;
93 static bool test_format(const format_info *f)
95 GLuint rbo = 0;
96 bool pass = true;
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);
102 return pass;
105 glGenRenderbuffers(1, &rbo);
106 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
107 glRenderbufferStorage(
108 GL_RENDERBUFFER,
109 f->format, 16, 16);
110 glFramebufferRenderbuffer(
111 GL_DRAW_FRAMEBUFFER,
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));
118 } else {
119 printf("Testing %s\n", piglit_get_gl_enum_name(f->format));
120 if (!check_rgba_signed(f->expected))
121 pass = false;
124 glFramebufferRenderbuffer(
125 GL_DRAW_FRAMEBUFFER,
126 GL_COLOR_ATTACHMENT0 + f->buffer,
127 GL_RENDERBUFFER, 0);
128 glDeleteRenderbuffers(1, &rbo);
129 return pass;
132 void
133 piglit_init(int argc, char **argv)
135 int expected[4] = {0, 0, 0, 0};
136 bool pass = true;
137 unsigned int i;
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))
145 pass = false;
147 if (piglit_is_extension_supported("GL_ARB_framebuffer_object")) {
148 GLuint fbo = 0;
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);