2 * Copyright © 2009 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
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 * Eric Anholt <eric@anholt.net>
25 * Michal Suchanek <hramrach@centrum.cz>
26 * based on mesa demo added by Keith Whitwell <keith@tungstengraphics.com>
29 /** @file draw-elements-base-vertex.c
30 * Tests ARB_draw_elements_base_vertex functionality by drawing two
31 * triangles using different base vertices, using the same vertex and
33 * In Mesa Gallium 7.11 this causes a crash.
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 10;
42 config
.window_width
= 300;
43 config
.window_height
= 300;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
49 static GLfloat vertices
[][4] = {
50 { 1, -1, 0, 1 }, /* bottom right */
51 { 1, 1, 0, 1 }, /* top right */
52 { -1, 1, 0, 1 }, /* top left */
53 { -1, -1, 0, 1 }, /* bottom left */
55 static GLubyte colors
[][4] = {
63 piglit_init(int argc
, char **argv
)
65 static const char * program
=
67 "MOV result.color, vertex.color;\n"
68 "MOV result.position, vertex.position;\n"
72 piglit_require_extension("GL_ARB_draw_elements_base_vertex");
73 piglit_require_extension("GL_ARB_vertex_program");
74 glGenProgramsARB(1, &program_no
);
75 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, program_no
);
76 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
77 strlen(program
), program
);
78 assert(glIsProgramARB(program_no
));
80 glMatrixMode(GL_MODELVIEW
);
84 glEnableClientState(GL_VERTEX_ARRAY
);
85 glVertexPointer(3, GL_FLOAT
, sizeof(vertices
[0]), vertices
);
86 glEnableClientState(GL_COLOR_ARRAY
);
87 glColorPointer(4, GL_UNSIGNED_BYTE
, 0, colors
);
93 GLboolean pass
= GL_TRUE
;
94 GLuint indices
[] = { 1, 2, 0,
96 static GLfloat test_colors
[][3] = {
103 glViewport(0, 0, piglit_width
, piglit_height
);
104 glMatrixMode(GL_PROJECTION
);
106 glOrtho(-1, 1, -1, 1, -0.5, 1000);
107 glMatrixMode(GL_MODELVIEW
);
110 glClearColor(0.3, 0.3, 0.3, 1);
111 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
113 glEnable(GL_VERTEX_PROGRAM_ARB
);
114 /* draw elements 3,4,5 ->verts 3,0,1 (lower-right tri) */
115 glDrawElements(GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, indices
+ 3);
116 /* draw elements 0,1,2 ->verts (1+1),(2+1),(0+1) (upper-left tri) */
117 glDrawElementsBaseVertex(GL_TRIANGLES
, 3, GL_UNSIGNED_INT
, indices
, 1);
120 pass
= piglit_probe_pixel_rgb(0, 0, test_colors
[0]) && pass
;
121 pass
= piglit_probe_pixel_rgb(piglit_width
- 1, 0, test_colors
[1]) && pass
;
122 pass
= piglit_probe_pixel_rgb(piglit_width
- 1, piglit_height
- 1, test_colors
[2]) && pass
;
123 pass
= piglit_probe_pixel_rgb(0, piglit_height
- 1, test_colors
[3]) && pass
;
125 piglit_present_results();
127 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;