]> git.cworth.org Git - apitrace/blobdiff - wrappers/gltrace.hpp
d3dretrace: Dump D3D10 depth stencil surfaces as float.
[apitrace] / wrappers / gltrace.hpp
index db824bb315ffd5f1044b3752104b83e7de466fac..dd8058cef4c42248075a9a1b3c74bbfdd7bc3940 100644 (file)
 #define _GLTRACE_HPP_
 
 
+#include <string.h>
+#include <stdlib.h>
+#include <map>
+
 #include "glimports.hpp"
 
 
@@ -39,6 +43,52 @@ enum Profile {
     PROFILE_ES2,
 };
 
+
+/**
+ * OpenGL ES buffers cannot be read. This class is used to track index buffer
+ * contents.
+ */
+class Buffer {
+public:
+    GLsizeiptr size;
+    GLvoid *data;
+
+    Buffer() :
+        size(0),
+        data(0)
+    {}
+
+    ~Buffer() {
+        free(data);
+    }
+
+    void
+    bufferData(GLsizeiptr new_size, const void *new_data) {
+        if (new_size < 0) {
+            new_size = 0;
+        }
+        size = new_size;
+        data = realloc(data, new_size);
+        if (new_size && new_data) {
+            memcpy(data, new_data, size);
+        }
+    }
+
+    void
+    bufferSubData(GLsizeiptr offset, GLsizeiptr length, const void *new_data) {
+        if (offset >= 0 && offset < size && length > 0 && offset + length <= size && new_data) {
+            memcpy((GLubyte *)data + offset, new_data, length);
+        }
+    }
+
+    void
+    getSubData(GLsizeiptr offset, GLsizeiptr length, void *out_data) {
+        if (offset >= 0 && offset < size && length > 0 && offset + length <= size && out_data) {
+            memcpy(out_data, (GLubyte *)data + offset, length);
+        }
+    }
+};
+
 class Context {
 public:
     enum Profile profile;
@@ -47,13 +97,26 @@ public:
     bool user_arrays_nv;
     unsigned retain_count;
 
+    // Whether it has been bound before
+    bool bound;
+
+    // TODO: This will fail for buffers shared by multiple contexts.
+    std::map <GLuint, Buffer> buffers;
+
     Context(void) :
         profile(PROFILE_COMPAT),
         user_arrays(false),
         user_arrays_arb(false),
         user_arrays_nv(false),
-        retain_count(0)
+        retain_count(0),
+        bound(false)
     { }
+
+    inline bool
+    needsShadowBuffers(void)
+    {
+        return profile == PROFILE_ES1 || profile == PROFILE_ES2;
+    }
 };
 
 void