diff options
author | Laura Ekstrand <laura@jlekstrand.net> | 2015-02-09 11:22:39 -0800 |
---|---|---|
committer | Laura Ekstrand <laura@jlekstrand.net> | 2015-03-09 16:20:45 -0700 |
commit | 2f0cc901d649a3b0b75ff083a05032b038885953 (patch) | |
tree | b5ca8d9b24948ed07cc0a15fa735c30c66802b60 | |
parent | 5a997068eebaf172543cf805ca5a56e840c8b635 (diff) |
arb_direct_state_access: Add non-DSA test for DrawBuffers.
-rw-r--r-- | tests/all.py | 1 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/spec/arb_direct_state_access/drawbuffers-multi.c | 160 |
3 files changed, 162 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py index 2779c175f..a955238c8 100644 --- a/tests/all.py +++ b/tests/all.py @@ -4248,6 +4248,7 @@ with profile.group_manager( g(['arb_direct_state_access-invalidateframebuffer'], 'invalidateframebuffer') g(['arb_direct_state_access-clearnamedframebuffer'], 'clearnamedframebuffer') g(['arb_direct_state_access-drawbuffers'], 'drawbuffers') + g(['arb_direct_state_access-drawbuffers-multi'], 'drawbuffers-multi') with profile.group_manager( PiglitGLTest, diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt index 72900c8ac..b1fe6c4b6 100644 --- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt +++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt @@ -32,6 +32,7 @@ piglit_add_executable (arb_direct_state_access-fbattachmentparam-errors fbattach piglit_add_executable (arb_direct_state_access-invalidateframebuffer invalidateframebuffer.c) piglit_add_executable (arb_direct_state_access-clearnamedframebuffer clearnamedframebuffer.c) piglit_add_executable (arb_direct_state_access-drawbuffers drawbuffers.c) +piglit_add_executable (arb_direct_state_access-drawbuffers-multi drawbuffers-multi.c) piglit_add_executable (arb_direct_state_access-dsa-textures dsa-textures.c dsa-utils.c) piglit_add_executable (arb_direct_state_access-texturesubimage texturesubimage.c) piglit_add_executable (arb_direct_state_access-bind-texture-unit bind-texture-unit.c) diff --git a/tests/spec/arb_direct_state_access/drawbuffers-multi.c b/tests/spec/arb_direct_state_access/drawbuffers-multi.c new file mode 100644 index 000000000..06740b6a3 --- /dev/null +++ b/tests/spec/arb_direct_state_access/drawbuffers-multi.c @@ -0,0 +1,160 @@ +/* + * Copyright © 2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** @file drawbuffers-multi.c + * + * Tests explicitly setting the read and draw framebuffers. Tests drawing + * multiple fragments at the same time. + * + * Somewhat inspired by tests/general/read-front.c. + * Adapted from tests/spec/arb_direct_state_access/drawbuffers.c. + */ + +#include "piglit-util-gl.h" +#include "piglit-shader.h" +#include "dsa-utils.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 32; + + config.window_visual = PIGLIT_GL_VISUAL_RGBA | + PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +/* + * You must use shaders in order to render to multiple buffers at once. + * These duplicate fixed-function gl 1.0 pipeline shading. + * Adapted from arb_clear_texture/3d.c. + */ +static const char vs_source[] = + "#version 140\n" + "in vec4 piglit_vertex;\n" + "uniform mat4 proj;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = proj * piglit_vertex;\n" + "}\n"; + +static const char fs_source[] = + "#version 140\n" + "uniform vec4 red;\n" + "uniform vec4 green;\n" + "uniform vec4 blue;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragData[0] = red;\n" + " gl_FragData[1] = green;\n" + " gl_FragData[2] = blue;\n" + "}\n"; + +static bool pass = true; +static GLuint program; +static GLuint fbo; + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ARB_direct_state_access"); + program = piglit_build_simple_program(vs_source, fs_source); +} + +static void +clear_subtest(float color[4], int att, const char *test_name) +{ + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glNamedFramebufferReadBuffer(fbo, GL_COLOR_ATTACHMENT0 + att); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + piglit_check_gl_error(GL_NO_ERROR); + SUBTESTCONDITION(piglit_probe_rect_rgb(0, 0, piglit_width, + piglit_height, color), pass, test_name); +} + +enum piglit_result +piglit_display(void) +{ + float red[] = {1, 0, 0, 1}; + float green[] = {0, 1, 0, 1}; + float blue[] = {0, 0, 1, 1}; + GLuint textures[3]; + int i; + GLint red_uniform, green_uniform, blue_uniform, proj_uniform; + GLenum bufs[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, + GL_COLOR_ATTACHMENT2}; + + /* Set up the shader program. */ + glUseProgram(program); + red_uniform = glGetUniformLocation(program, "red"); + glUniform4fv(red_uniform, 1, red); + green_uniform = glGetUniformLocation(program, "green"); + glUniform4fv(green_uniform, 1, green); + blue_uniform = glGetUniformLocation(program, "blue"); + glUniform4fv(blue_uniform, 1, blue); + proj_uniform = glGetUniformLocation(program, "proj"); + piglit_ortho_uniform(proj_uniform, piglit_width, piglit_height); + + /* Make a custom framebuffer with three color attachments */ + glCreateFramebuffers(1, &fbo); + glCreateTextures(GL_TEXTURE_2D, 3, textures); + for (i = 0; i < 3; ++i) { + glTextureStorage2D(textures[i], 1, GL_RGBA8, + piglit_width, piglit_height); + glNamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0 + i, + textures[i], 0); + } + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + piglit_check_gl_error(GL_NO_ERROR); + + /* Set the draw buffers */ + glDrawBuffers(3, bufs); + + /* Draw the pretty colors. */ + piglit_draw_rect(0, 0, piglit_width, piglit_height); + + /* Make sure the correct colors were drawn */ + clear_subtest(blue, 2, "Clear 2 to blue"); + clear_subtest(red, 0, "Clear 0 to red"); + clear_subtest(green, 1, "Clear 1 to green"); + + /* Show the results of the last subtest on the screen */ + if (!piglit_automatic) { + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo); + glBlitFramebuffer(0, 0, piglit_width, piglit_height, + 0, 0, piglit_width, piglit_height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + piglit_present_results(); + } + + + glDeleteTextures(3, textures); + glDeleteFramebuffers(1, &fbo); + glDeleteProgram(program); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} |