Commit 3e1cdfe6 authored by Marek Olšák's avatar Marek Olšák

draw-elements: test user arrays

parent 56c5cb9d
......@@ -228,6 +228,7 @@ add_plain_test(general, 'dlist-fdo3129-02')
add_plain_test(general, 'dlist-fdo31590')
add_plain_test(general, 'draw-batch')
add_plain_test(general, 'draw-elements')
general['draw-elements-user'] = PlainExecTest(['draw-elements', '-auto', 'user'])
add_plain_test(general, 'draw-elements-vs-inputs')
add_plain_test(general, 'draw-instanced')
add_plain_test(general, 'draw-instanced-divisor')
......
......@@ -34,197 +34,224 @@
int piglit_width = 320, piglit_height = 60;
int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
GLboolean user = GL_FALSE;
void piglit_init(int argc, char **argv)
{
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
unsigned i;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "user")) {
user = GL_TRUE;
puts("Testing user arrays.");
}
}
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
if (!GLEW_VERSION_1_5) {
printf("Requires OpenGL 1.5\n");
piglit_report_result(PIGLIT_SKIP);
}
if (!GLEW_VERSION_1_5) {
printf("Requires OpenGL 1.5\n");
piglit_report_result(PIGLIT_SKIP);
}
glShadeModel(GL_FLAT);
glClearColor(0.2, 0.2, 0.2, 1.0);
glShadeModel(GL_FLAT);
glClearColor(0.2, 0.2, 0.2, 1.0);
}
static void test_ubyte_indices(float x1, float y1, float x2, float y2, int index)
{
float v[] = {
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1
};
unsigned char indx[] = {
/*aligned:*/ 0, 1, 2, /*unused:*/ 2,
2, 2, 3, 3,
3, /* unaligned:*/ 3, 4, 5,
/*unused:*/ 5, 5, 5, 6,
6, 6, /*unaligned:*/ 6, 7,
8, /*unused:*/ 8, 8, 8,
9, 9, 9, /*unaligned:*/ 9,
10, 11, /*unused:*/ 11, 11,
11, 11, 11, 11
};
GLuint buf;
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indx), indx, GL_STATIC_DRAW);
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, (void*)(intptr_t)(index*9));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
float v[] = {
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1
};
unsigned char indx[] = {
/*aligned:*/ 0, 1, 2, /*unused:*/ 2,
2, 2, 3, 3,
3, /* unaligned:*/ 3, 4, 5,
/*unused:*/ 5, 5, 5, 6,
6, 6, /*unaligned:*/ 6, 7,
8, /*unused:*/ 8, 8, 8,
9, 9, 9, /*unaligned:*/ 9,
10, 11, /*unused:*/ 11, 11,
11, 11, 11, 11
};
GLuint buf;
glVertexPointer(2, GL_FLOAT, 0, v);
if (!user) {
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indx), indx, GL_STATIC_DRAW);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, (void*)(intptr_t)(index*9));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
} else {
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, indx + index*9);
}
}
static void test_ushort_indices(float x1, float y1, float x2, float y2, int index)
{
float v[] = {
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1
};
unsigned short indx[] = {
/*aligned:*/ 0, 1,
2, /*unused:*/ 2,
2, 2,
3, 3,
3, /* unaligned:*/ 3,
4, 5,
/*unused:*/ 5, 5,
5, 5
};
GLuint buf;
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indx), indx, GL_STATIC_DRAW);
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, (void*)(intptr_t)(index*18));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
float v[] = {
x1, y1,
x1, y2,
x2, y1,
x1, y1,
x1, y2,
x2, y1
};
unsigned short indx[] = {
/*aligned:*/ 0, 1,
2, /*unused:*/ 2,
2, 2,
3, 3,
3, /* unaligned:*/ 3,
4, 5,
/*unused:*/ 5, 5,
5, 5
};
GLuint buf;
glVertexPointer(2, GL_FLOAT, 0, v);
if (!user) {
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indx), indx, GL_STATIC_DRAW);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, (void*)(intptr_t)(index*18));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
} else {
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, (char*)indx + index*18);
}
}
static void test_large_index_count(float x1, float y1, float x2, float y2, int index)
{
float v[] = {
x1, y1,
x1, y2,
x2, y1
};
unsigned tris = 100000;
unsigned *indx = (unsigned*)malloc(sizeof(unsigned) * 3 * tris);
unsigned i;
// A large index count for DrawElements
for (i = 0; i < tris*3; i += 3) {
indx[i+0] = 0;
indx[i+1] = 1;
indx[i+2] = 2;
}
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, tris*3, GL_UNSIGNED_INT, indx);
free(indx);
float v[] = {
x1, y1,
x1, y2,
x2, y1
};
unsigned tris = 100000;
unsigned *indx = (unsigned*)malloc(sizeof(unsigned) * 3 * tris);
unsigned i;
/* A large index count for DrawElements */
for (i = 0; i < tris*3; i += 3) {
indx[i+0] = 0;
indx[i+1] = 1;
indx[i+2] = 2;
}
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, tris*3, GL_UNSIGNED_INT, indx);
free(indx);
}
static void test_large_indexbuf_offset(float x1, float y1, float x2, float y2, int index)
{
float v[] = {
x1, y1,
x1, y2,
x2, y1
};
GLuint buf;
unsigned *map;
unsigned num = 1000000;
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, num*4, 0, GL_STATIC_DRAW);
map = (unsigned*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
memset(map, 0, num*4);
map[num-2] = 1;
map[num-1] = 2;
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)(intptr_t)((num-3)*4));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
float v[] = {
x1, y1,
x1, y2,
x2, y1
};
GLuint buf;
unsigned *map;
unsigned num = 1000000;
glGenBuffers(1, &buf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, num*4, 0, GL_STATIC_DRAW);
map = (unsigned*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
memset(map, 0, num*4);
map[num-2] = 1;
map[num-1] = 2;
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)(intptr_t)((num-3)*4));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &buf);
}
enum {
USER,
VBO,
BOTH
};
struct test {
void (*test)(float x1, float y1, float x2, float y2, int index);
int index;
float expected_color[3];
const char *name;
void (*test)(float x1, float y1, float x2, float y2, int index);
int index;
float expected_color[3];
int flag;
const char *name;
};
struct test tests[] = {
{test_ubyte_indices, 0, {1, 1, 1}, "Ubyte indices - offset: 0"},
{test_ubyte_indices, 1, {1, 1, 1}, "Ubyte indices - offset: 1"},
{test_ubyte_indices, 2, {1, 1, 1}, "Ubyte indices - offset: 2"},
{test_ubyte_indices, 3, {1, 1, 1}, "Ubyte indices - offset: 3"},
{test_ubyte_indices, 0, {1, 1, 1}, BOTH, "Ubyte indices - offset: 0"},
{test_ubyte_indices, 1, {1, 1, 1}, BOTH, "Ubyte indices - offset: 1"},
{test_ubyte_indices, 2, {1, 1, 1}, BOTH, "Ubyte indices - offset: 2"},
{test_ubyte_indices, 3, {1, 1, 1}, BOTH, "Ubyte indices - offset: 3"},
{test_ushort_indices, 0, {1, 1, 1}, "Ushort indices - offset: 0"},
{test_ushort_indices, 1, {1, 1, 1}, "Ushort indices - offset: 2"},
{test_ushort_indices, 0, {1, 1, 1}, BOTH, "Ushort indices - offset: 0"},
{test_ushort_indices, 1, {1, 1, 1}, BOTH, "Ushort indices - offset: 2"},
{test_large_index_count, 1, {1, 1, 1}, "Large index count"},
{test_large_indexbuf_offset, 0, {1, 1, 1}, "Large index offset"},
{test_large_index_count, 1, {1, 1, 1}, USER, "Large index count"},
{test_large_indexbuf_offset, 0, {1, 1, 1}, VBO, "Large index offset"},
{0}
{0}
};
enum piglit_result
piglit_display(void)
piglit_display(void)
{
GLboolean pass = GL_TRUE;
unsigned i;
float x = 0, y = 0;
GLboolean pass = GL_TRUE;
unsigned i;
float x = 0, y = 0;
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
for (i = 0; tests[i].test; i++) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
for (i = 0; tests[i].test; i++) {
if (user && tests[i].flag == VBO)
continue;
if (!user && tests[i].flag == USER)
continue;
printf("%s\n", tests[i].name);
tests[i].test(x, y, x+20, y+20, tests[i].index);
assert(glGetError() == 0);
pass = piglit_probe_pixel_rgb(x+5, y+5, tests[i].expected_color) && pass;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
x += 20;
if (x > 300) {
x = 0;
y += 20;
}
}
printf("%s\n", tests[i].name);
tests[i].test(x, y, x+20, y+20, tests[i].index);
assert(glGetError() == 0);
pass = piglit_probe_pixel_rgb(x+5, y+5, tests[i].expected_color) && pass;
glFinish();
glutSwapBuffers();
x += 20;
if (x > 300) {
x = 0;
y += 20;
}
}
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
glFinish();
glutSwapBuffers();
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment