ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_draw_indirect / draw-arrays-shared-binding.c
blob45d11d47437f5e1ba69b2415d2314007b7d4400d
1 /*
2 * Copyright (c) 2015 Intel Corporation
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, 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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * @file draw-arrays-shared-binding.c
27 * Test creates a VAO and tests sharing binding point with 2 enabled vertex
28 * attribute arrays, one used for vertices and another for output colors.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_core_version = 31;
35 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char vs_text[] =
40 "attribute vec4 vertex;\n"
41 "attribute vec4 colors;\n"
42 "varying vec4 color;\n"
43 "void main() {\n"
44 "gl_Position = vertex;\n"
45 "color = colors;\n"
46 "}";
48 static const char fs_text[] =
49 "varying vec4 color;\n"
50 "void main() {\n"
51 "gl_FragColor = color;\n"
52 "}";
54 static const GLfloat rect[] = {
55 -1.0f, 1.0f, 0.0f,
56 1.0f, 1.0f, 0.0f,
57 -1.0f, -1.0f, 0.0f,
58 1.0f, -1.0f, 0.0f,
61 GLuint indirect_data[] = {
62 4, 1, 0, 0
65 GLuint vao;
67 enum piglit_result
68 piglit_display(void)
70 bool pass = true;
71 unsigned i;
72 GLfloat colors[ARRAY_SIZE(rect)];
74 /* Resulting colors should match given vertices clamped. */
75 for (i = 0; i < ARRAY_SIZE(rect); i++)
76 colors[i] = CLAMP(rect[i], 0.0, 1.0);
78 glBindVertexArray(vao);
79 glDrawArraysIndirect(GL_TRIANGLE_STRIP, 0);
81 if (!piglit_check_gl_error(GL_NO_ERROR))
82 piglit_report_result(PIGLIT_FAIL);
84 piglit_present_results();
86 /* Probe each corner. */
87 pass &= piglit_probe_pixel_rgb(0, piglit_height -1, colors);
88 pass &= piglit_probe_pixel_rgb(piglit_width - 1, piglit_height - 1, &colors[3]);
89 pass &= piglit_probe_pixel_rgb(0, 0, &colors[6]);
90 pass &= piglit_probe_pixel_rgb(piglit_width - 1, 0, &colors[9]);
92 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
95 void
96 piglit_init(int argc, char **argv)
98 GLuint prog, vbo, indirect;
100 piglit_require_GLSL();
101 piglit_require_extension("GL_ARB_draw_indirect");
103 prog = piglit_build_simple_program(vs_text, fs_text);
104 glUseProgram(prog);
106 glGenVertexArrays(1, &vao);
107 glBindVertexArray(vao);
109 glGenBuffers(1, &indirect);
110 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirect);
111 glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(indirect_data), indirect_data, GL_STATIC_DRAW);
113 glGenBuffers(1, &vbo);
114 glBindBuffer(GL_ARRAY_BUFFER, vbo);
115 glBufferData(GL_ARRAY_BUFFER, sizeof(rect), rect, GL_STATIC_DRAW);
117 /* Enable 2 vertex attrib arrays. */
118 glEnableVertexAttribArray(0);
119 glEnableVertexAttribArray(1);
121 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
123 glBindBuffer(GL_ARRAY_BUFFER, 0);
125 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
127 /* Associate both arrays with binding 0. */
128 glVertexAttribBinding(0, 0);
129 glVertexAttribBinding(1, 0);
131 glBindVertexArray(0);
133 if (!piglit_check_gl_error(GL_NO_ERROR))
134 piglit_report_result(PIGLIT_FAIL);