1 /**************************************************************************
3 * Copyright 2012 Jose Fonseca
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
36 # include <GLUT/glut.h>
43 parseArgs(int argc, char** argv)
50 GLenum target = GL_ARRAY_BUFFER;
54 if (!GLEW_VERSION_1_5 ||
55 !GLEW_ARB_map_buffer_range) {
56 fprintf(stderr, "error: GL_ARB_map_buffer_range not supported\n");
60 glGenBuffers(2, buffers);
62 glBindBuffer(target, buffers[0]);
63 glBufferData(target, 1000, NULL, GL_STATIC_DRAW);
65 ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT);
67 glUnmapBuffer(target);
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);
74 glBindBuffer(target, buffers[0]);
75 ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
78 glBindBuffer(target, buffers[1]);
79 glFlushMappedBufferRange(target, 20, 30);
80 glFlushMappedBufferRange(target, 40, 50);
81 glUnmapBuffer(target);
83 glBindBuffer(target, buffers[0]);
84 glFlushMappedBufferRange(target, 10, 20);
85 glFlushMappedBufferRange(target, 30, 40);
86 glUnmapBuffer(target);
88 glMapBufferRange(target, 100, 200, GL_MAP_READ_BIT);
89 glUnmapBuffer(target);
91 glDeleteBuffers(2, buffers);
94 int main(int argc, char** argv)
96 parseArgs(argc, argv);
97 glutInit(&argc, argv);
98 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
99 glutCreateWindow(argv[0]);