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
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.
25 * Test OpenGL 3.0's glVertexAttribIPointer function with all combinations
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
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
=
44 "uniform ivec4 expected_i; \n"
46 "uniform uvec4 expected_u; \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"
56 " color = vec4(1, 0, 0, 0); // bad! \n"
59 static const char *fragShaderText
=
64 " gl_FragColor = color; \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 };
76 static GLint ExpectedUniform_i
, ExpectedUniform_u
;
77 static GLint Attr_i
, Attr_u
;
81 * Test glVertexAttribIArray(type, size, normalized)
84 test_array(GLenum type
, GLuint size
)
86 static const GLfloat verts
[4][2] = {
92 static const GLfloat green
[4] = { 0.0, 1.0, 0.0, 0.0 };
93 GLubyte attr_buffer
[4 * 4 * sizeof(GLuint
)];
101 typeSize
= sizeof(GLbyte
);
103 for (i
= 0; i
< 4; i
++)
104 expected
[i
] = byte4_data
[i
];
106 case GL_UNSIGNED_BYTE
:
107 typeSize
= sizeof(GLubyte
);
109 for (i
= 0; i
< 4; i
++)
110 expected
[i
] = ubyte4_data
[i
];
113 typeSize
= sizeof(GLshort
);
115 for (i
= 0; i
< 4; i
++)
116 expected
[i
] = short4_data
[i
];
118 case GL_UNSIGNED_SHORT
:
119 typeSize
= sizeof(GLushort
);
121 for (i
= 0; i
< 4; i
++)
122 expected
[i
] = ushort4_data
[i
];
125 typeSize
= sizeof(GLint
);
127 for (i
= 0; i
< 4; i
++)
128 expected
[i
] = int4_data
[i
];
130 case GL_UNSIGNED_INT
:
131 typeSize
= sizeof(GLuint
);
133 for (i
= 0; i
< 4; i
++)
134 expected
[i
] = uint4_data
[i
];
138 typeSize
= sizeof(GLint
);
142 /* set unused components to defaults */
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,
189 printf("Test %s[%d] failed\n",
190 piglit_get_gl_enum_name(type
), size
);
194 piglit_present_results();
203 static const GLenum types
[] = {
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
;
225 piglit_init(int argc
, char **argv
)
227 piglit_require_gl_version(30);
229 Prog
= piglit_build_simple_program(vertShaderText
, fragShaderText
);
231 printf("Failed to compile/link program\n");
232 piglit_report_result(PIGLIT_FAIL
);
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");