ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_draw_indirect / draw-arrays-base-instance.c
blob5835440c4f4adb6046d33d1b92416cddfa1ce84d
1 /*
2 * Copyright © 2013 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 * 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 /* Basic test of glDrawArraysIndirect interaction with base instance */
27 #include "piglit-util-gl.h"
29 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config.supports_gl_core_version = 31;
33 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
34 config.khr_no_error_support = PIGLIT_NO_ERRORS;
36 PIGLIT_GL_TEST_CONFIG_END
38 GLuint vao;
39 GLint prog;
41 float green[] = {0,1,0};
42 float blue[] = {0,0,1};
44 enum piglit_result
45 piglit_display(void)
47 bool pass = true;
49 glViewport(0, 0, 128, 128);
51 glClearColor(0,0,1,1);
52 glClear(GL_COLOR_BUFFER_BIT);
54 glBindVertexArray(vao);
55 glUseProgram(prog);
57 glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)0);
59 glUseProgram(0);
61 piglit_present_results();
63 pass = piglit_probe_pixel_rgb(32, 32, green) && pass;
64 pass = piglit_probe_pixel_rgb(96, 96, blue) && pass;
66 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
69 float vertices_data[] = {
70 -1, -1,
71 1, -1,
72 -1, 1,
75 int instance_data[] = { 0, 0, 0, 0, 42, 0, 0 };
77 GLuint indirect_data[] = {
78 3, /* count */
79 1, /* primcount */
80 0, /* first vertex */
81 4, /* base instance */
84 void
85 piglit_init(int argc, char **argv)
87 GLuint vertices_bo;
88 GLuint instance_bo;
89 GLuint indirect_bo;
91 piglit_require_extension("GL_ARB_draw_indirect");
92 piglit_require_extension("GL_ARB_base_instance");
93 piglit_require_extension("GL_ARB_instanced_arrays");
95 glGenVertexArrays(1, &vao);
96 glBindVertexArray(vao);
98 glGenBuffers(1, &vertices_bo);
99 glBindBuffer(GL_ARRAY_BUFFER, vertices_bo);
100 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_data), vertices_data, GL_STATIC_DRAW);
101 glEnableVertexAttribArray(0);
102 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
104 glGenBuffers(1, &instance_bo);
105 glBindBuffer(GL_ARRAY_BUFFER, instance_bo);
106 glBufferData(GL_ARRAY_BUFFER, sizeof(instance_data), instance_data, GL_STATIC_DRAW);
107 glEnableVertexAttribArray(1);
108 glVertexAttribIPointer(1, 1, GL_INT, 0, 0);
109 glVertexAttribDivisorARB(1, 1);
111 glGenBuffers(1, &indirect_bo);
112 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirect_bo);
113 glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(indirect_data), indirect_data, GL_STATIC_DRAW);
115 prog = piglit_build_simple_program(
116 "#version 130\n"
117 "#extension GL_ARB_explicit_attrib_location: require\n"
118 "#extension GL_ARB_draw_instanced: require\n"
119 "\n"
120 "layout(location=0) in vec2 pos;\n"
121 "layout(location=1) in int instance_in;\n"
122 "\n"
123 "flat out int instance;\n"
124 "\n"
125 "void main() {\n"
126 " gl_Position = vec4(pos, 0, 1);\n"
127 " instance = instance_in;\n"
128 "}\n",
130 "#version 130\n"
131 "\n"
132 "flat in int instance;\n"
133 "\n"
134 "void main() {\n"
135 " if (instance == 42) {\n"
136 " gl_FragColor = vec4(0,1,0,1);\n"
137 " } else {\n"
138 " gl_FragColor = vec4(1,0,0,1);\n"
139 " }\n"
140 "}\n");
142 glBindVertexArray(0);