1 /*
2  * Copyright 2016 VMware, Inc.
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 /**
25  * Simple test of copying within a single buffer.
26  *
27  * Brian Paul
28  * 21 June 2016
29  */
30 
31 #include "piglit-util-gl.h"
32 
33 PIGLIT_GL_TEST_CONFIG_BEGIN
34 	config.supports_gl_compat_version = 15;
35 	config.supports_gl_core_version = 31;
36 	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
37 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
39 
40 
41 void
piglit_init(int argc,char * argv[])42 piglit_init(int argc, char *argv[])
43 {
44 	bool pass = true;
45 	GLuint buffer;
46 	GLubyte data[250], *map;
47 	int i;
48 
49 	piglit_require_extension("GL_ARB_copy_buffer");
50 
51 	glGenBuffers(1, &buffer);
52 	glBindBuffer(GL_COPY_READ_BUFFER, buffer);
53 	glBindBuffer(GL_COPY_WRITE_BUFFER, buffer);
54 
55 	/* create empty buffer */
56 	glBufferData(GL_COPY_READ_BUFFER, 1000, NULL, GL_STREAM_COPY);
57 
58 	/* fill last 250 of 1000 bytes */
59 	for (i = 0; i < 250; i++)
60 		data[i] = i;
61 	glBufferSubData(GL_COPY_READ_BUFFER, 750, 250, data);
62 
63 	/* copy last 250 bytes to offset 500 */
64 	glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
65 			    750, 500, 250);
66 
67 	/* copy last 500 bytes to start of buffer */
68 	glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
69 			    500, 0, 500);
70 
71 	/* check results */
72 	map = glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
73 	assert(map);
74 
75 	for (i = 0; i < 1000; i++) {
76 		if (map[i] != i % 250) {
77 			printf("Wrong buffer value at position %u.\n", i);
78 			printf("Expected %u, found %u\n", i % 250, map[i]);
79 			pass = false;
80 			break;
81 		}
82 	}
83 
84 	glUnmapBuffer(GL_COPY_READ_BUFFER);
85 
86 	glDeleteBuffers(1, &buffer);
87 
88 	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
89 }
90 
91 enum piglit_result
piglit_display(void)92 piglit_display(void)
93 {
94 	/* unreachable */
95 	return PIGLIT_FAIL;
96 }
97