2 * Copyright © 2010 Marek Olšák <maraeo@gmail.com>
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.
24 * Marek Olšák <maraeo@gmail.com>
27 #include "piglit-util-gl.h"
29 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config
.supports_gl_compat_version
= 10;
33 config
.window_width
= 320;
34 config
.window_height
= 80;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
36 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
40 GLboolean user_va
= GL_FALSE
;
42 void piglit_init(int argc
, char **argv
)
46 for (i
= 1; i
< argc
; i
++) {
47 if (!strcmp(argv
[i
], "user_varrays")) {
49 puts("Testing user vertex arrays.");
53 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
55 piglit_require_gl_version(15);
57 piglit_require_extension("GL_ARB_draw_elements_base_vertex");
59 glShadeModel(GL_FLAT
);
60 glClearColor(0.2, 0.2, 0.2, 1.0);
63 static GLuint
vboVertexPointer(GLint size
, GLenum type
, GLsizei stride
,
64 const GLvoid
*buf
, GLsizei bufSize
, intptr_t bufOffset
)
68 glVertexPointer(size
, type
, stride
, (char*)buf
+ bufOffset
);
72 glBindBuffer(GL_ARRAY_BUFFER
, id
);
73 glBufferData(GL_ARRAY_BUFFER
, bufSize
, buf
, GL_STATIC_DRAW
);
74 glVertexPointer(size
, type
, stride
, (void*)bufOffset
);
78 static GLuint
vboElementPointer(const GLvoid
*buf
, GLsizei bufSize
)
85 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, id
);
86 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, bufSize
, buf
, GL_STATIC_DRAW
);
90 static void test_negative_index_offset(float x1
, float y1
, float x2
, float y2
, int index
)
98 index
, index
+1, index
+2
102 vbo
= vboVertexPointer(2, GL_FLOAT
, 0, v2
, sizeof(v2
), 0);
103 ib
= vboElementPointer(indices
, sizeof(indices
));
104 glDrawElementsBaseVertex(GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, user_va
? indices
: NULL
, -index
);
106 glDeleteBuffers(1, &vbo
);
108 glDeleteBuffers(1, &ib
);
111 enum piglit_result
piglit_display(void)
113 GLboolean pass
= GL_TRUE
;
116 float expected
[] = {1,1,1};
118 glClear(GL_COLOR_BUFFER_BIT
);
119 glEnableClientState(GL_VERTEX_ARRAY
);
121 for (i
= 0; i
< 63; i
++) {
122 int index
= (int)pow(i
, 5.2)+1;
123 glBindBuffer(GL_ARRAY_BUFFER
, 0);
124 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
126 printf("BaseVertex = -%i\n", index
);
127 test_negative_index_offset(x
, y
, x
+20, y
+20, index
);
128 if (!piglit_check_gl_error(GL_NO_ERROR
))
129 piglit_report_result(PIGLIT_FAIL
);
130 pass
= piglit_probe_pixel_rgb(x
+5, y
+5, expected
) && pass
;
140 piglit_present_results();
142 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;