2 * Copyright (c) 2011 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 DEALINGS
25 * Test some unusual vertex array strides.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
39 PIGLIT_GL_TEST_CONFIG_END
41 static const char *TestName
= "array-stride";
46 #define NUM_VERTS (ROWS * COLS * 4)
48 static GLfloat Verts
[ROWS
][COLS
][4][2];
54 float dx
= 9.0, dy
= 9.0;
56 for (i
= 0; i
< ROWS
; i
++) {
58 for (j
= 0; j
< COLS
; j
++) {
60 Verts
[i
][j
][0][0] = x
;
61 Verts
[i
][j
][0][1] = y
;
62 Verts
[i
][j
][1][0] = x
+ dx
;
63 Verts
[i
][j
][1][1] = y
;
64 Verts
[i
][j
][2][0] = x
+ dx
;
65 Verts
[i
][j
][2][1] = y
+ dy
;
66 Verts
[i
][j
][3][0] = x
;
67 Verts
[i
][j
][3][1] = y
+ dy
;
74 draw_simple_stride(void)
76 static GLushort elements
[NUM_VERTS
];
79 for (i
= 0; i
< ARRAY_SIZE(elements
); i
++)
82 glVertexPointer(2, GL_FLOAT
, 2 * sizeof(GLfloat
), Verts
);
83 glEnableClientState(GL_VERTEX_ARRAY
);
84 glDrawElements(GL_QUADS
, NUM_VERTS
, GL_UNSIGNED_SHORT
, elements
);
85 glDisableClientState(GL_VERTEX_ARRAY
);
90 * Use a stride that's less than the vertex element size.
91 * Use scaled indices in the element array.
92 * Should render the same as the simple stride case above.
95 draw_unusual_stride(int stride
)
97 static GLushort elements
[NUM_VERTS
];
100 for (i
= 0; i
< ARRAY_SIZE(elements
); i
++)
101 elements
[i
] = i
* 8 / stride
;
103 glVertexPointer(2, GL_FLOAT
, stride
, Verts
);
104 glEnableClientState(GL_VERTEX_ARRAY
);
105 glDrawElements(GL_QUADS
, NUM_VERTS
, GL_UNSIGNED_SHORT
, elements
);
106 glDisableClientState(GL_VERTEX_ARRAY
);
113 GLubyte
*buf0
, *buf1
;
114 enum piglit_result result
= PIGLIT_PASS
;
119 buf0
= (GLubyte
*) malloc(piglit_width
* piglit_height
* 4);
120 buf1
= (GLubyte
*) malloc(piglit_width
* piglit_height
* 4);
122 /* draw reference image */
123 glClear(GL_COLOR_BUFFER_BIT
);
124 draw_simple_stride();
125 glReadPixels(0, 0, piglit_width
, piglit_height
,
126 GL_RGBA
, GL_UNSIGNED_BYTE
, buf0
);
128 /* draw w/ unusual strides */
129 for (stride
= 1; stride
<= 8; stride
*= 2) {
130 glClear(GL_COLOR_BUFFER_BIT
);
131 draw_unusual_stride(stride
);
132 glReadPixels(0, 0, piglit_width
, piglit_height
,
133 GL_RGBA
, GL_UNSIGNED_BYTE
, buf1
);
135 piglit_present_results();
138 if (memcmp(buf0
, buf1
, piglit_width
* piglit_height
* 4) != 0) {
139 printf("%s: image comparison failed at stride = %d\n",
141 result
= PIGLIT_FAIL
;
153 piglit_init(int argc
, char**argv
)
155 glOrtho(-1.0, 101.0, -1.0, 101.0, -1.0, 1.0);