framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / gl-3.0 / vertexattribipointer.c
blob7ea0cadcb3e23ba1606cbed003840a01bfdecbaa
1 /*
2 * Copyright 2014 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 * 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 * Test OpenGL 3.0's glVertexAttribIPointer function with all combinations
26 * of types and sizes.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config.supports_gl_compat_version = 30;
33 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
34 config.khr_no_error_support = PIGLIT_NO_ERRORS;
35 PIGLIT_GL_TEST_CONFIG_END
38 /**
39 * We'll pass in the same data for both the signed and unsigned vertex
40 * attributes and the signed/unsigned expected value.
42 static const char *vertShaderText =
43 "#version 130 \n"
44 "uniform ivec4 expected_i; \n"
45 "in ivec4 attr_i; \n"
46 "uniform uvec4 expected_u; \n"
47 "in uvec4 attr_u; \n"
48 "out vec4 color; \n"
49 " \n"
50 "void main() \n"
51 "{ \n"
52 " gl_Position = gl_Vertex; \n"
53 " if (attr_i == expected_i && attr_u == expected_u) \n"
54 " color = vec4(0, 1, 0, 0); // good! \n"
55 " else \n"
56 " color = vec4(1, 0, 0, 0); // bad! \n"
57 "} \n";
59 static const char *fragShaderText =
60 "#version 130 \n"
61 "in vec4 color;\n"
62 "void main()\n"
63 "{ \n"
64 " gl_FragColor = color; \n"
65 "} \n";
68 static const GLubyte ubyte4_data[] = { 100, 0, 200, 255 };
69 static const GLbyte byte4_data[] = { 50, 0, -25, -50 };
70 static const GLushort ushort4_data[] = { 16000, 0, 32000, 65535 };
71 static const GLshort short4_data[] = { 2000, 0, -4000, -32010 };
72 static const GLuint uint4_data[] = { 10000000, 0, 20000000, 80000020 };
73 static const GLint int4_data[] = { 10000000, 0, -20000000, -40000020 };
75 static GLuint Prog;
76 static GLint ExpectedUniform_i, ExpectedUniform_u;
77 static GLint Attr_i, Attr_u;
81 * Test glVertexAttribIArray(type, size, normalized)
83 static bool
84 test_array(GLenum type, GLuint size)
86 static const GLfloat verts[4][2] = {
87 { -1.0, -1.0 },
88 { 1.0, -1.0 },
89 { 1.0, 1.0 },
90 { -1.0, 1.0 }
92 static const GLfloat green[4] = { 0.0, 1.0, 0.0, 0.0 };
93 GLubyte attr_buffer[4 * 4 * sizeof(GLuint)];
94 int typeSize;
95 const void *data;
96 GLint expected[4];
97 int i, p;
99 switch (type) {
100 case GL_BYTE:
101 typeSize = sizeof(GLbyte);
102 data = byte4_data;
103 for (i = 0; i < 4; i++)
104 expected[i] = byte4_data[i];
105 break;
106 case GL_UNSIGNED_BYTE:
107 typeSize = sizeof(GLubyte);
108 data = ubyte4_data;
109 for (i = 0; i < 4; i++)
110 expected[i] = ubyte4_data[i];
111 break;
112 case GL_SHORT:
113 typeSize = sizeof(GLshort);
114 data = short4_data;
115 for (i = 0; i < 4; i++)
116 expected[i] = short4_data[i];
117 break;
118 case GL_UNSIGNED_SHORT:
119 typeSize = sizeof(GLushort);
120 data = ushort4_data;
121 for (i = 0; i < 4; i++)
122 expected[i] = ushort4_data[i];
123 break;
124 case GL_INT:
125 typeSize = sizeof(GLint);
126 data = int4_data;
127 for (i = 0; i < 4; i++)
128 expected[i] = int4_data[i];
129 break;
130 case GL_UNSIGNED_INT:
131 typeSize = sizeof(GLuint);
132 data = uint4_data;
133 for (i = 0; i < 4; i++)
134 expected[i] = uint4_data[i];
135 break;
136 default:
137 assert(0);
138 typeSize = sizeof(GLint);
139 data = NULL;
142 /* set unused components to defaults */
143 switch (size) {
144 case 1:
145 expected[1] = 0;
146 case 2:
147 expected[2] = 0;
148 case 3:
149 expected[3] = 1;
152 /* Setup the attribute buffer by making four copies of the
153 * test's array data (for the four vertices).
156 int i, sz = typeSize * size;
157 for (i = 0; i < 4; i++) {
158 memcpy(attr_buffer + i * sz, data, sz);
162 /* We set up both the signed and unsigned int attribute arrays to
163 * point to the same vertex data.
165 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
166 glEnableVertexAttribArray(0);
167 glVertexAttribIPointer(Attr_i, size, type, 0, attr_buffer);
168 glEnableVertexAttribArray(Attr_i);
169 glVertexAttribIPointer(Attr_u, size, type, 0, attr_buffer);
170 glEnableVertexAttribArray(Attr_u);
172 glViewport(0, 0, piglit_width, piglit_height);
173 glClearColor(1,0,0,0);
174 glClear(GL_COLOR_BUFFER_BIT);
176 /* The same value is expected for the signed and unsigned attributes */
177 glUniform4iv(ExpectedUniform_i, 1, expected);
178 glUniform4uiv(ExpectedUniform_u, 1, (const GLuint *) expected);
180 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
182 glDisableVertexAttribArray(0);
183 glDisableVertexAttribArray(Attr_i);
184 glDisableVertexAttribArray(Attr_u);
186 p = piglit_probe_pixel_rgba(piglit_width / 2, piglit_height / 2,
187 green);
188 if (!p) {
189 printf("Test %s[%d] failed\n",
190 piglit_get_gl_enum_name(type), size);
191 fflush(stdout);
194 piglit_present_results();
196 return p;
200 enum piglit_result
201 piglit_display(void)
203 static const GLenum types[] = {
204 GL_BYTE,
205 GL_UNSIGNED_BYTE,
206 GL_SHORT,
207 GL_UNSIGNED_SHORT,
208 GL_INT,
209 GL_UNSIGNED_INT
211 bool pass = true;
212 int t, size;
214 for (t = 0; t < ARRAY_SIZE(types); t++) {
215 for (size = 1; size <= 4; size++) {
216 pass = test_array(types[t], size) && pass;
220 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
224 void
225 piglit_init(int argc, char **argv)
227 piglit_require_gl_version(30);
229 Prog = piglit_build_simple_program(vertShaderText, fragShaderText);
230 if (!Prog) {
231 printf("Failed to compile/link program\n");
232 piglit_report_result(PIGLIT_FAIL);
235 glUseProgram(Prog);
237 Attr_i = glGetAttribLocation(Prog, "attr_i");
238 Attr_u = glGetAttribLocation(Prog, "attr_u");
239 ExpectedUniform_i = glGetUniformLocation(Prog, "expected_i");
240 ExpectedUniform_u = glGetUniformLocation(Prog, "expected_u");