1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "piglit-util-gl-common.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.window_width = 320;
config.window_height = 320;
config.window_visual = PIGLIT_GL_VISUAL_RGB;
PIGLIT_GL_TEST_CONFIG_END
#define width (10)
#define height (12)
#define depth (3)
void piglit_init(int argc, char **argv)
{
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
if (!piglit_is_extension_supported("GL_ARB_robustness"))
piglit_report_result(PIGLIT_SKIP);
glClearColor(0.2, 0.2, 0.2, 1.0);
}
static GLboolean
succeeded(int offby)
{
GLboolean should_error = (offby < 0);
GLenum err = glGetError();
if (should_error) {
if (err == GL_INVALID_OPERATION)
return GL_TRUE;
fprintf(stderr, "Did not give GL_INVALID_OPERATION "
"with too small a buffer! (off by: %d)\n", offby);
return GL_FALSE;
} else {
if (err == GL_NO_ERROR)
return GL_TRUE;
fprintf(stderr, "Unexpected error! (off by: %d)\n", offby);
return GL_FALSE;
}
}
static enum piglit_result
test_pixelmap(int offby)
{
#define MAPSIZE 32
#define TEST_PIXMAP(type, t)\
do {\
GL##type v[MAPSIZE];\
GLsizei bufSize = offby + (int)(sizeof v);\
unsigned i;\
\
memset(v, 0, sizeof v);\
for (i = 0; i < MAPSIZE; i += 2)\
v[i] = 1.0;\
\
glClear(GL_COLOR_BUFFER_BIT);\
\
glPixelTransferi(GL_MAP_COLOR, GL_FALSE);\
glPixelMap##t##v(GL_PIXEL_MAP_R_TO_R, MAPSIZE, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
glPixelMap##t##v(GL_PIXEL_MAP_G_TO_G, MAPSIZE, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
glPixelMap##t##v(GL_PIXEL_MAP_B_TO_B, MAPSIZE, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
glPixelMap##t##v(GL_PIXEL_MAP_A_TO_A, MAPSIZE, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
\
glGetnPixelMap##t##vARB(GL_PIXEL_MAP_R_TO_R, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
glGetnPixelMap##t##vARB(GL_PIXEL_MAP_G_TO_G, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
glGetnPixelMap##t##vARB(GL_PIXEL_MAP_B_TO_B, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
glGetnPixelMap##t##vARB(GL_PIXEL_MAP_A_TO_A, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
} while (0)
TEST_PIXMAP(float, f);
TEST_PIXMAP(uint, ui);
TEST_PIXMAP(ushort, us);
#undef TEST_PIXMAP
#undef MAPSIZE
return PIGLIT_PASS;
}
static enum piglit_result
test_readpix(int offby)
{
#define TEST_READPIX(gltype, enumtype) \
do {\
GL##gltype v[4*width*height];\
GLsizei bufSize = offby + (int)(sizeof v);\
\
memset(v, 0, sizeof v);\
glClear(GL_COLOR_BUFFER_BIT);\
\
glReadnPixelsARB(0, 0, width, height, GL_RGBA, GL_##enumtype, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
glReadnPixelsARB(1, 1, width, height, GL_RGBA, GL_##enumtype, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
} while (0)
TEST_READPIX(float, FLOAT);
TEST_READPIX(int, INT);
TEST_READPIX(byte, BYTE);
#undef TEST_READPIX
return PIGLIT_PASS;
}
static enum piglit_result
test_stipple(int offby)
{
GLubyte pattern[4*32];
GLsizei bufSize = offby + (int)(sizeof pattern);
unsigned i;
for (i = 0; i < sizeof pattern; i++)
pattern[i] = 0x55;
glPolygonStipple(pattern);
if (!succeeded(0))
return PIGLIT_FAIL;
glGetnPolygonStippleARB(bufSize, pattern);
if (!succeeded(offby))
return PIGLIT_FAIL;
return PIGLIT_PASS;
}
static enum piglit_result
test_teximage1d(int offby);
static enum piglit_result
test_teximage2d(int offby);
static enum piglit_result
test_teximage3d(int offby);
static enum piglit_result
test_teximage(int offby)
{
if (test_teximage1d(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
if (test_teximage2d(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
if (test_teximage3d(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
return PIGLIT_PASS;
}
static enum piglit_result
test_teximage1d(int offby)
{
#define TEST_TEX1D(gltype, enumtype)\
do {\
GL##gltype v[4*width];\
GLsizei bufSize = offby + (int)(sizeof v);\
\
memset(v, 0, sizeof v);\
glClear(GL_COLOR_BUFFER_BIT);\
\
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width,\
0, GL_RGBA, GL_##enumtype, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
\
glGetnTexImageARB(GL_TEXTURE_1D, 0, GL_RGBA, GL_##enumtype, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
} while(0)
TEST_TEX1D(float, FLOAT);
TEST_TEX1D(int, INT);
TEST_TEX1D(byte, BYTE);
#undef TEST_TEX1D
return PIGLIT_PASS;
}
static enum piglit_result
test_teximage2d(int offby)
{
#define TEST_TEX2D(gltype, enumtype)\
do {\
GL##gltype v[4*width*height];\
GLsizei bufSize = offby + (int)(sizeof v);\
\
memset(v, 0, sizeof v);\
glClear(GL_COLOR_BUFFER_BIT);\
\
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,\
0, GL_RGBA, GL_##enumtype, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
\
glGetnTexImageARB(GL_TEXTURE_2D, 0, GL_RGBA, GL_##enumtype, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
} while(0)
TEST_TEX2D(float, FLOAT);
TEST_TEX2D(int, INT);
TEST_TEX2D(byte, BYTE);
#undef TEST_TEX2D
return PIGLIT_PASS;
}
static enum piglit_result
test_teximage3d(int offby)
{
#define TEST_TEX3D(gltype, enumtype)\
do {\
GL##gltype v[4*width*height*depth];\
GLsizei bufSize = offby + (int)(sizeof v);\
\
memset(v, 0, sizeof v);\
glClear(GL_COLOR_BUFFER_BIT);\
\
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth,\
0, GL_RGBA, GL_##enumtype, v);\
if (!succeeded(0))\
return PIGLIT_FAIL;\
\
glGetnTexImageARB(GL_TEXTURE_3D, 0, GL_RGBA, GL_##enumtype, bufSize, v);\
if (!succeeded(offby))\
return PIGLIT_FAIL;\
} while(0)
TEST_TEX3D(float, FLOAT);
TEST_TEX3D(int, INT);
TEST_TEX3D(byte, BYTE);
#undef TEST_TEX3D
return PIGLIT_PASS;
}
static enum piglit_result
test(int offby)
{
/* write to client memory, not a bound buffer */
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
if (test_pixelmap(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
if (test_stipple(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
if (test_readpix(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
if (test_teximage(offby) != PIGLIT_PASS)
return PIGLIT_FAIL;
return PIGLIT_PASS;
}
enum piglit_result
piglit_display(void)
{
int i;
enum piglit_result res;
glClear(GL_COLOR_BUFFER_BIT);
for (i = -9; i <= 1; ++i) {
res = test(i);
assert(glGetError() == GL_NO_ERROR);
if (res != PIGLIT_PASS)
break;
}
glFinish();
return res;
}
|