2 * Copyright © 2012 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 DEALINGS
26 * Tests the following piece of the GL_ARB_copy_buffer spec:
28 * "An INVALID_VALUE error is generated if the same buffer object
29 * is bound to both readtarget and writetarget, and the ranges
30 * [readoffset, readoffset+size) and [writeoffset,
31 * writeoffset+size) overlap."
33 * And it also tests that copying works correctly if there isn't
34 * overlap, but with one buffer being both src and dst.
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
44 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
46 PIGLIT_GL_TEST_CONFIG_END
49 test_copy(GLenum usage
, int data_size
, int src
, int dst
, int size
)
56 data
= (uint8_t *)malloc(data_size
);
57 expected
= (uint8_t *)malloc(data_size
);
59 for (i
= 0; i
< data_size
; i
++) {
63 glBufferData(GL_COPY_READ_BUFFER
, data_size
, data
, usage
);
65 glCopyBufferSubData(GL_COPY_READ_BUFFER
, GL_COPY_WRITE_BUFFER
,
68 if (src
> dst
- size
&&
70 if (!piglit_check_gl_error(GL_INVALID_VALUE
)) {
72 "No error reported for overlapping "
73 "glCopyBufferSubData() from %d to %d, "
76 piglit_report_result(PIGLIT_FAIL
);
83 if (!piglit_check_gl_error(0)) {
85 "Error reported for non-overlapping "
86 "glCopyBufferSubData() from %d to %d, "
89 piglit_report_result(PIGLIT_FAIL
);
92 //piglit_reset_gl_error();
94 /* Now compute what the result should be and check that it matches. */
95 memcpy(expected
, data
, data_size
);
96 memcpy(expected
+ dst
, expected
+ src
, size
);
97 ptr
= glMapBuffer(GL_COPY_READ_BUFFER
, GL_READ_ONLY
);
98 if (memcmp(expected
, ptr
, data_size
)) {
100 "Data not copied correctly for non-overlapping "
101 "glCopyBufferSubData().\n"
102 "from offset %d to offset %d, size %d\n",
105 fprintf(stderr
, "original: expected: found:\n");
106 for (i
= 0; i
< data_size
; i
++) {
107 fprintf(stderr
, "0x%02x 0x%02x 0x%02x\n",
108 i
, expected
[i
], ptr
[i
]);
110 piglit_report_result(PIGLIT_FAIL
);
112 glUnmapBuffer(GL_COPY_READ_BUFFER
);
126 piglit_init(int argc
, char **argv
)
131 static const GLenum bo_modes
[] = {
143 piglit_require_extension("GL_ARB_copy_buffer");
145 glGenBuffers(1, &buf
);
147 glBindBufferARB(GL_COPY_READ_BUFFER
, buf
);
148 glBindBufferARB(GL_COPY_WRITE_BUFFER
, buf
);
150 for (i
= 0; i
< ARRAY_SIZE(bo_modes
); i
++) {
151 GLenum usage
= bo_modes
[i
];
153 for (src
= 0; src
< size
; src
++) {
154 int max_src_size
= size
- src
;
155 for (dst
= 0; dst
< size
; dst
++) {
156 int max_dst_size
= size
- dst
;
157 int max_size
= ((max_src_size
< max_dst_size
) ?
162 for (copy_size
= 1; copy_size
<= max_size
;
164 test_copy(usage
, size
,
165 src
, dst
, copy_size
);
171 glDeleteBuffers(1, &buf
);
173 piglit_report_result(PIGLIT_PASS
);