]> git.cworth.org Git - apitrace-tests/commitdiff
Basic map buffer test.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 10 Mar 2012 10:33:58 +0000 (10:33 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 10 Mar 2012 10:33:58 +0000 (10:33 +0000)
apps/gl/.gitignore
apps/gl/CMakeLists.txt
apps/gl/map_buffer.c [new file with mode: 0644]
apps/gl/map_buffer.ref.txt [new file with mode: 0644]

index d396b2a49533d12208a8a4ee2c261372ac639bc8..522615b4d89181b1c08018490770ae158b077127 100644 (file)
@@ -1,3 +1,4 @@
 gremedy
+map_buffer
 tri
 varray
index d78fce2f67d96d5fb142de13e3d8b560912d02e9..6344566cb8ba0d3884d3641d4fe05720d1d12327 100644 (file)
@@ -37,6 +37,7 @@ set (targets
     tri
     gremedy
     varray
+    map_buffer
 )
 
 foreach (target ${targets})
@@ -46,8 +47,8 @@ foreach (target ${targets})
     if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt)
         add_app_test(
             NAME ${api}_${target}
-           TARGET ${api}_${target}
-           REF ${target}.ref.txt
+            TARGET ${api}_${target}
+            REF ${target}.ref.txt
         )
     endif ()
 endforeach (target)
diff --git a/apps/gl/map_buffer.c b/apps/gl/map_buffer.c
new file mode 100644 (file)
index 0000000..f0108ed
--- /dev/null
@@ -0,0 +1,100 @@
+/**************************************************************************
+ *
+ * Copyright 2012 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <GL/glew.h>
+#ifdef __APPLE__
+#  include <GLUT/glut.h>
+#else
+#  include <GL/glut.h>
+#endif
+
+
+static void
+parseArgs(int argc, char** argv)
+{
+}
+
+static void
+init(void)
+{
+       GLenum target = GL_ARRAY_BUFFER;
+    GLuint buffers[2];
+    GLvoid *ptr;
+
+       if (!GLEW_VERSION_1_5 ||
+        !GLEW_ARB_map_buffer_range) {
+        exit(0);
+       }
+
+       glGenBuffers(2, buffers);
+       
+    glBindBuffer(target, buffers[0]);
+       glBufferData(target, 1000, NULL, GL_STATIC_DRAW);
+
+       ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT);
+       memset(ptr, 0, 200);
+       glUnmapBuffer(target);
+
+    glBindBuffer(target, buffers[1]);
+       glBufferData(target, 2000, NULL, GL_STATIC_DRAW);
+       ptr = glMapBufferRange(target, 200, 300, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
+       memset(ptr, 0, 300);
+
+    glBindBuffer(target, buffers[0]);
+       ptr = glMapBufferRange(target, 100, 200, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
+       memset(ptr, 0, 200);
+
+    glBindBuffer(target, buffers[1]);
+    glFlushMappedBufferRange(target, 20, 30);
+    glFlushMappedBufferRange(target, 40, 50);
+       glUnmapBuffer(target);
+
+    glBindBuffer(target, buffers[0]);
+    glFlushMappedBufferRange(target, 10, 20);
+    glFlushMappedBufferRange(target, 30, 40);
+       glUnmapBuffer(target);
+       
+    glMapBufferRange(target, 100, 200, GL_MAP_READ_BIT);
+       glUnmapBuffer(target);
+}
+
+int main(int argc, char** argv)
+{
+    parseArgs(argc, argv);
+    glutInit(&argc, argv);
+    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
+    glutCreateWindow(argv[0]);
+    glewInit();
+    init();
+    return 0;
+}
diff --git a/apps/gl/map_buffer.ref.txt b/apps/gl/map_buffer.ref.txt
new file mode 100644 (file)
index 0000000..e69de29