X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fgltrace.hpp;h=04c64b6afc0623ad690cbeb80ced17d3687de53f;hb=7a9fb5103e052150232b64cb5d99374cda3f1234;hp=e4fefc3daaf5f1d5d70a4ec0bf444fe8491bb46f;hpb=452d3256a3ba7f249222ef857d69c8caaaa753f3;p=apitrace diff --git a/wrappers/gltrace.hpp b/wrappers/gltrace.hpp index e4fefc3..04c64b6 100644 --- a/wrappers/gltrace.hpp +++ b/wrappers/gltrace.hpp @@ -27,6 +27,10 @@ #define _GLTRACE_HPP_ +#include +#include +#include + #include "glimports.hpp" @@ -39,24 +43,104 @@ enum Profile { PROFILE_ES2, }; -struct Context { + +/** + * 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; bool user_arrays; bool user_arrays_arb; bool user_arrays_nv; + unsigned retain_count; + + // 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) + { } + + inline bool + needsShadowBuffers(void) + { + return profile == PROFILE_ES1 || profile == PROFILE_ES2; + } }; - -Context * + +void +createContext(uintptr_t context_id); + +void +retainContext(uintptr_t context_id); + +bool +releaseContext(uintptr_t context_id); + +void +setContext(uintptr_t context_id); + +void +clearContext(void); + +gltrace::Context * getContext(void); const GLubyte * -__glGetString_override(GLenum name); +_glGetString_override(GLenum name); void -__glGetIntegerv_override(GLenum pname, GLint *params); +_glGetIntegerv_override(GLenum pname, GLint *params); const GLubyte * -__glGetStringi_override(GLenum name, GLuint index); +_glGetStringi_override(GLenum name, GLuint index); } /* namespace gltrace */