2 * Copyright © 2012 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
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.
27 * Tests that glDrawElementsInstancedARB() can render multiple
28 * instances and the instance IDs are propagated to the shader.
30 * This is a derivative of instance-array-dereference.c, which uses
31 * glDrawArraysInstancedARB().
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
44 static const char *vs_source
=
46 "#extension GL_ARB_draw_instanced: require\n"
48 "uniform vec4 instance_colors[] = vec4[](vec4(0.0, 1.0, 0.0, 1.0),\n"
49 " vec4(0.0, 1.0, 1.0, 1.0),\n"
50 " vec4(0.0, 0.0, 1.0, 1.0));\n"
52 "varying vec4 color;\n"
56 " color = instance_colors[gl_InstanceIDARB];\n"
58 " vec4 v = gl_Vertex;\n"
59 " v.x += 20.0 * float(gl_InstanceIDARB);\n"
61 " gl_Position = gl_ModelViewProjectionMatrix * v;\n"
64 static const char *fs_source
=
65 "varying vec4 color;\n"
68 " gl_FragColor = color;\n"
74 static const int indices
[6] = {0, 1, 2, 0, 2, 3};
75 static const float verts
[] = {
81 static const float green
[4] = {0.0, 1.0, 0.0, 1.0};
82 static const float cyan
[4] = {0.0, 1.0, 1.0, 1.0};
83 static const float blue
[4] = {0.0, 0.0, 1.0, 1.0};
84 enum piglit_result result
= PIGLIT_PASS
;
86 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
88 glViewport(0, 0, piglit_width
, piglit_height
);
90 glClearColor(0.5, 0.5, 0.5, 0.0);
91 glClear(GL_COLOR_BUFFER_BIT
);
93 glVertexPointer(2, GL_FLOAT
, 0, verts
);
94 glEnableClientState(GL_VERTEX_ARRAY
);
95 glDrawElementsInstancedARB(GL_TRIANGLES
, 6, GL_UNSIGNED_INT
,
97 glDisableClientState(GL_VERTEX_ARRAY
);
99 if (!piglit_probe_rect_rgba(10, 10, 10, 10, green
))
100 result
= PIGLIT_FAIL
;
102 if (!piglit_probe_rect_rgba(30, 10, 10, 10, cyan
))
103 result
= PIGLIT_FAIL
;
105 if (!piglit_probe_rect_rgba(50, 10, 10, 10, blue
))
106 result
= PIGLIT_FAIL
;
108 piglit_present_results();
114 piglit_init(int argc
, char **argv
)
118 piglit_require_extension("GL_ARB_draw_instanced");
120 prog
= piglit_build_simple_program(vs_source
, fs_source
);