ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_draw_buffers / state_change.c
blobe067d77a93070e83c55eccef8a3d12d451167fb3
1 /*
2 * Copyright © 2011 Henri Verbeet <hverbeet@gmail.com>
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.
25 /* Test switching between various draw buffers. In particular, this tests that
26 * glDrawBuffersARB() enables the correct buffers when only the buffer count
27 * changes. This is for a bug in _mesa_drawbuffers() where it would fail to
28 * set the remaining buffers to NONE when only the first buffer was updated.
29 * It would then fail to enable the second buffer again because it was already
30 * pointing to the new buffer. */
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 128;
39 config.window_height = 128;
40 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
42 PIGLIT_GL_TEST_CONFIG_END
44 static void
45 check_fbo_status(void)
47 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
48 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
49 printf("FBO incomplete, status %#x.\n", status);
50 piglit_report_result(PIGLIT_FAIL);
54 enum piglit_result
55 piglit_display(void)
57 static GLenum buffers[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
58 static const float red[] = {1.0f, 0.0f, 0.0f};
59 static const float green[] = {0.0f, 1.0f, 0.0f};
60 static const float blue[] = {0.0f, 0.0f, 1.0f};
61 static const struct {
62 GLsizei buffer_count;
63 const float *clear_color;
64 const float *expected_0;
65 const float *expected_1;
66 } tests[] = {
67 {2, red, red, red},
68 {1, green, green, red},
69 {2, blue, blue, blue},
71 int w = piglit_width;
72 int h = piglit_height;
73 GLuint fbo, tex[2];
74 unsigned i;
76 glGenTextures(2, tex);
77 glBindTexture(GL_TEXTURE_2D, tex[0]);
78 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h,
79 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
80 glBindTexture(GL_TEXTURE_2D, tex[1]);
81 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h,
82 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
84 glGenFramebuffersEXT(1, &fbo);
85 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
86 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
87 GL_TEXTURE_2D, tex[0], 0);
88 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
89 GL_TEXTURE_2D, tex[1], 0);
90 check_fbo_status();
91 if (!piglit_check_gl_error(GL_NO_ERROR))
92 piglit_report_result(PIGLIT_FAIL);
94 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i) {
95 GLint buffer, expected_buffer;
97 glDrawBuffersARB(tests[i].buffer_count, buffers);
98 check_fbo_status();
100 glGetIntegerv(GL_DRAW_BUFFER1_ARB, &buffer);
101 expected_buffer = tests[i].buffer_count < 2 ? GL_NONE : GL_COLOR_ATTACHMENT1_EXT;
102 if (buffer != expected_buffer) {
103 printf("Unexpected buffer %#x for DRAW_BUFFER1_ARB in test %u, expected %#x.\n",
104 buffer, i, expected_buffer);
105 piglit_report_result(PIGLIT_FAIL);
108 glClearColor(tests[i].clear_color[0], tests[i].clear_color[1],
109 tests[i].clear_color[2], 1.0f);
110 glClear(GL_COLOR_BUFFER_BIT);
112 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
113 if (!piglit_probe_pixel_rgb(w / 2, h / 2, tests[i].expected_0)) {
114 printf("Probe failed for test %u, attachment 0.\n", i);
115 piglit_report_result(PIGLIT_FAIL);
118 glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
119 if (!piglit_probe_pixel_rgb(w / 2, h / 2, tests[i].expected_1)) {
120 printf("Probe failed for test %u, attachment 1.\n", i);
121 piglit_report_result(PIGLIT_FAIL);
125 if (!piglit_check_gl_error(GL_NO_ERROR))
126 piglit_report_result(PIGLIT_FAIL);
128 return PIGLIT_PASS;
131 void
132 piglit_init(int argc, char **argv)
134 GLint i;
136 piglit_require_extension("GL_EXT_framebuffer_object");
137 piglit_require_extension("GL_ARB_draw_buffers");
138 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &i);
139 if (i < 2) {
140 printf("2 draw buffers required, %d reported.\n", i);
141 piglit_report_result(PIGLIT_SKIP);