framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_shader_draw_parameters / drawid.c
blob80d1af12a6cd3e985cfa6fe809bb169cc5ed16bd
1 /*
2 * Copyright © 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 * 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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file drawid.c
27 * Basic test for gl_DrawIDARB.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_core_version = 31;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char vs_template[] =
40 "#version 140\n"
41 "#extension GL_ARB_shader_draw_parameters: require\n"
42 "\n"
43 "in vec4 piglit_vertex;\n"
44 "in ivec2 ref;\n"
45 "out vec4 color;\n"
46 "\n"
47 "void main()\n"
48 "{\n"
49 " gl_Position = piglit_vertex;\n"
50 " if (%s)\n"
51 " color = vec4(0, 1, 0, 1);\n"
52 " else\n"
53 " color = vec4(1, 0, 0, 1);\n"
54 "}\n";
56 static const char fs_text[] =
57 "#version 130\n"
58 "\n"
59 "in vec4 color;\n"
60 "\n"
61 "void main()\n"
62 "{\n"
63 " gl_FragColor = color;\n"
64 "}\n";
66 void
67 piglit_init(int argc, char **argv)
69 GLuint prog;
70 char *vs_text;
72 if (strcmp(argv[1], "drawid") == 0) {
73 (void)!asprintf(&vs_text, vs_template,
74 "ref.x == gl_DrawIDARB");
75 } else if (strcmp(argv[1], "vertexid") == 0) {
76 (void)!asprintf(&vs_text, vs_template,
77 "ref.x == gl_DrawIDARB && ref.y == gl_VertexID");
78 } else {
79 printf("Unknown subtest: %s\n", argv[1]);
80 piglit_report_result(PIGLIT_FAIL);
83 piglit_require_extension("GL_ARB_shader_draw_parameters");
84 piglit_require_extension("GL_ARB_base_instance");
86 prog = piglit_build_simple_program(vs_text, fs_text);
88 glBindAttribLocation(prog, 1, (const GLchar *) "ref");
89 glLinkProgram(prog);
90 glUseProgram(prog);
93 enum piglit_result
94 piglit_display()
96 bool pass;
98 struct {
99 float vertex_array[16];
100 int reference_array[16];
101 int indices[6];
102 } geometry = {
103 .vertex_array = {
104 -1, -1,
105 0, -1,
106 0, 1,
107 -1, 1,
109 0, -1,
110 1, -1,
111 1, 1,
112 0, 1,
114 .reference_array = {
115 0, 0,
116 0, 1,
117 0, 2,
118 0, 3,
120 2, 4,
121 2, 5,
122 2, 6,
123 2, 7,
127 const int indices[12] = {
128 0, 1, 2,
129 0, 2, 3,
131 4, 5, 6,
132 4, 6, 7,
135 float green[] = {0, 1, 0, 1};
137 GLuint vao, vbo;
138 glGenVertexArrays(1, &vao);
139 glBindVertexArray(vao);
141 glGenBuffers(1, &vbo);
142 glBindBuffer(GL_ARRAY_BUFFER, vbo);
143 glBufferData(GL_ARRAY_BUFFER, sizeof(geometry), &geometry, GL_STATIC_DRAW);
145 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,
146 2 * sizeof(GLfloat),
147 (void *) ((char *) &geometry.vertex_array - (char *) &geometry));
149 glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT,
150 2 * sizeof(int),
151 (void *) ((char *) &geometry.reference_array - (char *) &geometry));
153 /* Enable the attributes */
154 glEnableVertexAttribArray(0);
155 glEnableVertexAttribArray(1);
157 static const GLsizei counts[4] = { 6, 0, 6, 0 };
158 const int *indices_array[4] = { &indices[0], &indices[0], &indices[6], &indices[6] };
160 glMultiDrawElements(GL_TRIANGLES,
161 counts,
162 GL_UNSIGNED_INT,
163 (const void **) indices_array,
164 ARRAY_SIZE(counts));
166 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
167 green);
169 piglit_present_results();
171 return pass ? PIGLIT_PASS : PIGLIT_FAIL;