2 * Copyright © 2013 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 that glBufferData() synchronizes correctly with
27 * glCopyBufferSubData().
29 * We make sure that a glBufferData() over the read buffer after the
30 * copy has no effect, while a glBufferData() over the write buffer
31 * after the copy does have an effect.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 15;
39 config
.supports_gl_core_version
= 31;
41 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
47 piglit_init(int argc
, char *argv
[])
50 uint32_t dummy_data_1
[4], dummy_data_2
[4];
51 uint32_t good_data
[4] = {0, 1, 2, 3};
52 uint32_t result_data
[4];
54 size_t size
= sizeof(good_data
);
55 GLuint buffer_handles
[2];
57 memset(dummy_data_1
, 0xaa, size
);
58 memset(dummy_data_2
, 0xbb, size
);
60 piglit_require_extension("GL_ARB_copy_buffer");
62 glGenBuffers(2, buffer_handles
);
63 glBindBuffer(GL_COPY_READ_BUFFER
, buffer_handles
[0]);
64 glBindBuffer(GL_COPY_WRITE_BUFFER
, buffer_handles
[1]);
66 glBufferData(GL_COPY_READ_BUFFER
, size
, good_data
, GL_STREAM_COPY
);
67 glBufferData(GL_COPY_WRITE_BUFFER
, size
, dummy_data_1
, GL_STREAM_COPY
);
68 glCopyBufferSubData(GL_COPY_READ_BUFFER
, GL_COPY_WRITE_BUFFER
,
70 glBufferData(GL_COPY_READ_BUFFER
, size
, dummy_data_2
, GL_STREAM_COPY
);
71 memset(result_data
, 0xd0, size
);
72 glGetBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, result_data
);
73 subtest_pass
= memcmp(good_data
, result_data
, size
) == 0;
75 fprintf(stderr
, "found 0x%08x 0x%08x 0x%08x 0x%08x\n",
76 result_data
[0], result_data
[1],
77 result_data
[2], result_data
[3]);
80 piglit_report_subtest_result(subtest_pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
81 "overwrite source data");
83 glBufferData(GL_COPY_READ_BUFFER
, size
, dummy_data_2
, GL_STREAM_COPY
);
84 glBufferData(GL_COPY_WRITE_BUFFER
, size
, dummy_data_1
, GL_STREAM_COPY
);
85 glCopyBufferSubData(GL_COPY_READ_BUFFER
, GL_COPY_WRITE_BUFFER
,
87 glBufferData(GL_COPY_WRITE_BUFFER
, size
, good_data
, GL_STREAM_COPY
);
88 memset(result_data
, 0xd0, size
);
89 glGetBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, result_data
);
90 subtest_pass
= memcmp(good_data
, result_data
, size
) == 0;
92 fprintf(stderr
, "found 0x%08x 0x%08x 0x%08x 0x%08x\n",
93 result_data
[0], result_data
[1],
94 result_data
[2], result_data
[3]);
97 piglit_report_subtest_result(subtest_pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
98 "overwrite destination data");
100 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);