X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fgltrace.hpp;h=dd8058cef4c42248075a9a1b3c74bbfdd7bc3940;hb=8cf630712592eea93b1a1988a0875fe293e6aea8;hp=155f82760cd641139e5ddd4ef28c8923fe67fce3;hpb=d493737765bed0fcbba908024d2314778c26b5c9;p=apitrace diff --git a/wrappers/gltrace.hpp b/wrappers/gltrace.hpp index 155f827..dd8058c 100644 --- a/wrappers/gltrace.hpp +++ b/wrappers/gltrace.hpp @@ -27,11 +27,12 @@ #define _GLTRACE_HPP_ -#include "glimports.hpp" #include #include #include +#include "glimports.hpp" + namespace gltrace { @@ -42,23 +43,50 @@ enum Profile { PROFILE_ES2, }; + +/** + * OpenGL ES buffers cannot be read. This class is used to track index buffer + * contents. + */ class Buffer { public: - ~Buffer() - { + GLsizeiptr size; + GLvoid *data; + + Buffer() : + size(0), + data(0) + {} + + ~Buffer() { free(data); } - void resetData(const void *new_data, size_t new_size) - { - data = realloc(data, new_size); + void + bufferData(GLsizeiptr new_size, const void *new_data) { + if (new_size < 0) { + new_size = 0; + } size = new_size; - if (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); + } } - size_t size; - void *data; + 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 { @@ -68,14 +96,20 @@ public: bool user_arrays_arb; bool user_arrays_nv; unsigned retain_count; - std::map buffers; + + // Whether it has been bound before + bool bound; + + // TODO: This will fail for buffers shared by multiple contexts. + std::map 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