]> git.cworth.org Git - apitrace-tests/blob - apps/gl/map_buffer.c
f0108ed18e1cc34213fbabfb34e619305a2daa8c
[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         exit(0);
57         }
58
59         glGenBuffers(2, buffers);
60         
61     glBindBuffer(target, buffers[0]);
62         glBufferData(target, 1000, NULL, GL_STATIC_DRAW);
63
64         ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT);
65         memset(ptr, 0, 200);
66         glUnmapBuffer(target);
67
68     glBindBuffer(target, buffers[1]);
69         glBufferData(target, 2000, NULL, GL_STATIC_DRAW);
70         ptr = glMapBufferRange(target, 200, 300, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
71         memset(ptr, 0, 300);
72
73     glBindBuffer(target, buffers[0]);
74         ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
75         memset(ptr, 0, 200);
76
77     glBindBuffer(target, buffers[1]);
78     glFlushMappedBufferRange(target, 20, 30);
79     glFlushMappedBufferRange(target, 40, 50);
80         glUnmapBuffer(target);
81
82     glBindBuffer(target, buffers[0]);
83     glFlushMappedBufferRange(target, 10, 20);
84     glFlushMappedBufferRange(target, 30, 40);
85         glUnmapBuffer(target);
86         
87     glMapBufferRange(target, 100, 200, GL_MAP_READ_BIT);
88         glUnmapBuffer(target);
89 }
90
91 int main(int argc, char** argv)
92 {
93     parseArgs(argc, argv);
94     glutInit(&argc, argv);
95     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
96     glutCreateWindow(argv[0]);
97     glewInit();
98     init();
99     return 0;
100 }