]> git.cworth.org Git - apitrace-tests/blob - apps/gl/map_buffer.c
Add --exact, --no-deps, or --no-prune to trim tests as needed
[apitrace-tests] / apps / gl / map_buffer.c
1 /**************************************************************************
2  *
3  * Copyright 2012 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifdef _WIN32
27 #include <windows.h>
28 #endif
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 #include <GL/glew.h>
35 #ifdef __APPLE__
36 #  include <GLUT/glut.h>
37 #else
38 #  include <GL/glut.h>
39 #endif
40
41
42 static void
43 parseArgs(int argc, char** argv)
44 {
45 }
46
47 static void
48 init(void)
49 {
50     GLenum target = GL_ARRAY_BUFFER;
51     GLuint buffers[2];
52     GLvoid *ptr;
53
54     if (!GLEW_VERSION_1_5 ||
55         !GLEW_ARB_map_buffer_range) {
56         fprintf(stderr, "error: GL_ARB_map_buffer_range not supported\n");
57         exit(1);
58     }
59
60     glGenBuffers(2, buffers);
61     
62     glBindBuffer(target, buffers[0]);
63     glBufferData(target, 1000, NULL, GL_STATIC_DRAW);
64
65     ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT);
66     memset(ptr, 0, 200);
67     glUnmapBuffer(target);
68
69     glBindBuffer(target, buffers[1]);
70     glBufferData(target, 2000, NULL, GL_STATIC_DRAW);
71     ptr = glMapBufferRange(target, 200, 300, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
72     memset(ptr, 0, 300);
73
74     glBindBuffer(target, buffers[0]);
75     ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
76     memset(ptr, 0, 200);
77
78     glBindBuffer(target, buffers[1]);
79     glFlushMappedBufferRange(target, 20, 30);
80     glFlushMappedBufferRange(target, 40, 50);
81     glUnmapBuffer(target);
82
83     glBindBuffer(target, buffers[0]);
84     glFlushMappedBufferRange(target, 10, 20);
85     glFlushMappedBufferRange(target, 30, 40);
86     glUnmapBuffer(target);
87     
88     glMapBufferRange(target, 100, 200, GL_MAP_READ_BIT);
89         glUnmapBuffer(target);
90
91     glDeleteBuffers(2, buffers);
92 }
93
94 int main(int argc, char** argv)
95 {
96     parseArgs(argc, argv);
97     glutInit(&argc, argv);
98     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
99     glutCreateWindow(argv[0]);
100     glewInit();
101     init();
102     return 0;
103 }