framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_draw_instanced / execution / drawarrays.c
bloba3d72bc45ee1d83ba042c4a9abbff18900e56e7f
1 /*
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
13 * Software.
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
22 * SOFTWARE.
25 /**
26 * @file
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;
47 #define PRIMS 8
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"
53 "void main() \n"
54 "{ \n"
55 #if 0
56 " vec4 p = ftransform(); \n"
57 " vec2 pos = Pos[gl_InstanceIDARB]; \n"
58 " p.x += pos.x; \n"
59 " p.y += pos.y; \n"
60 " gl_Position = p; \n"
61 #else
62 " vec4 p = gl_Vertex; \n"
63 " vec2 pos = Pos[gl_InstanceIDARB]; \n"
64 " p.x += pos.x; \n"
65 " p.y += pos.y; \n"
66 " gl_Position = gl_ModelViewProjectionMatrix * p; \n"
67 #endif
68 " gl_FrontColor = Color[gl_InstanceIDARB]; \n"
69 "} \n";
71 static const char *FragShaderText =
72 "void main() \n"
73 "{ \n"
74 " gl_FragColor = gl_Color; \n"
75 "} \n";
78 static GLuint VertShader, FragShader, Program;
80 static const GLfloat Positions[PRIMS][2] = {
81 { -6, 6 },
82 { -4, 4 },
83 { -2, 2 },
84 { 0, 0 },
85 { 2, -2 },
86 { 4, -4 },
87 { 6, -6 },
88 { 8, -8 }
91 static const GLfloat Colors[PRIMS][4] = {
92 {1, 0, 0, 1},
93 {0, 1, 0, 1},
94 {0, 0, 1, 1},
95 {1, 1, 0, 1},
96 {0, 1, 1, 1},
97 {1, 0, 1, 1},
98 {1, 1, 1, 1},
99 {0.5, 0.5, 0.5, 1},
103 static GLboolean
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);
119 glUseProgram(0);
122 GLint i;
123 GLint pos[4];
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",
132 TestName, i);
133 piglit_present_results();
134 return GL_FALSE;
139 piglit_present_results();
141 return GL_TRUE;
145 enum piglit_result
146 piglit_display(void)
148 if (!test_instancing())
149 return PIGLIT_FAIL;
151 return PIGLIT_PASS;
155 void
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);
161 assert(VertShader);
163 FragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, FragShaderText);
164 assert(FragShader);
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);
177 glLoadIdentity();
178 glFrustum(-5, 5, -5, 5, 10, 20);
180 glMatrixMode(GL_MODELVIEW);
181 glLoadIdentity();
182 glTranslatef(0, 0, -11.0);
183 glScalef(0.5, 0.5, 1.0);