2 * Copyright (c) 2010 VMware, Inc.
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
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Tests GL_ARB_draw_instanced
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
36 config
.window_width
= 500;
37 config
.window_height
= 500;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static const char *TestName
= "draw-instanced";
45 static GLint PosUniform
, ColorUniform
;
49 static const char *VertShaderText
=
50 "#extension GL_ARB_draw_instanced: enable \n"
51 "uniform vec2 Pos[8]; \n"
52 "uniform vec4 Color[8]; \n"
56 " vec4 p = ftransform(); \n"
57 " vec2 pos = Pos[gl_InstanceIDARB]; \n"
60 " gl_Position = p; \n"
62 " vec4 p = gl_Vertex; \n"
63 " vec2 pos = Pos[gl_InstanceIDARB]; \n"
66 " gl_Position = gl_ModelViewProjectionMatrix * p; \n"
68 " gl_FrontColor = Color[gl_InstanceIDARB]; \n"
71 static const char *FragShaderText
=
74 " gl_FragColor = gl_Color; \n"
78 static GLuint VertShader
, FragShader
, Program
;
80 static const GLfloat Positions
[PRIMS
][2] = {
91 static const GLfloat Colors
[PRIMS
][4] = {
104 test_instancing(void)
106 static const GLfloat verts
[4][2] = {
107 {-1, -1}, {1, -1}, {1, 1}, {-1, 1}
110 glVertexPointer(2, GL_FLOAT
, 0, verts
);
111 glEnableClientState(GL_VERTEX_ARRAY
);
113 glClear(GL_COLOR_BUFFER_BIT
);
115 glUseProgram(Program
);
117 glDrawArraysInstancedARB(GL_POLYGON
, 0, 4, PRIMS
);
125 for (i
= 0; i
< PRIMS
; i
++) {
126 /* use glRasterPos to determine where to read a sample pixel */
127 glRasterPos2fv(Positions
[i
]);
128 glGetIntegerv(GL_CURRENT_RASTER_POSITION
, pos
);
130 if (!piglit_probe_pixel_rgba(pos
[0], pos
[1], Colors
[i
])) {
131 fprintf(stderr
, "%s: instance %d failed to draw correctly\n",
133 piglit_present_results();
139 piglit_present_results();
148 if (!test_instancing())
156 piglit_init(int argc
, char **argv
)
158 piglit_require_extension("GL_ARB_draw_instanced");
160 VertShader
= piglit_compile_shader_text(GL_VERTEX_SHADER
, VertShaderText
);
163 FragShader
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, FragShaderText
);
166 Program
= piglit_link_simple_program(VertShader
, FragShader
);
168 glUseProgram(Program
);
170 PosUniform
= glGetUniformLocation(Program
, "Pos");
171 ColorUniform
= glGetUniformLocation(Program
, "Color");
173 glUniform2fv(PosUniform
, PRIMS
, (GLfloat
*) Positions
);
174 glUniform4fv(ColorUniform
, PRIMS
, (GLfloat
*) Colors
);
176 glMatrixMode(GL_PROJECTION
);
178 glFrustum(-5, 5, -5, 5, 10, 20);
180 glMatrixMode(GL_MODELVIEW
);
182 glTranslatef(0, 0, -11.0);
183 glScalef(0.5, 0.5, 1.0);