diff options
author | Adam Hunter <adam@mapbox.com> | 2015-10-06 13:54:36 -0700 |
---|---|---|
committer | Adam Hunter <adam@mapbox.com> | 2015-10-06 13:54:36 -0700 |
commit | 1179096dd8aff05903edeb7cfe74ef323bfc5709 (patch) | |
tree | fa7dd8d622265dc85205342b44294ffdf10fd691 | |
parent | 402819e1add767c11e691f209fa642ab807cf883 (diff) | |
download | qtlocation-mapboxgl-1179096dd8aff05903edeb7cfe74ef323bfc5709.tar.gz |
VAO and extension tracking code.
-rw-r--r-- | include/mbgl/platform/gl.hpp | 32 | ||||
-rw-r--r-- | src/mbgl/platform/gl.cpp | 41 |
2 files changed, 70 insertions, 3 deletions
diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index 1e3f13427b..6c1229f6d1 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -7,6 +7,10 @@ #include <stdexcept> #include <vector> +#ifdef GL_TRACK +#include <iostream> +#endif + #if __APPLE__ #include "TargetConditionals.h" #if TARGET_OS_IPHONE @@ -34,6 +38,28 @@ namespace mbgl { namespace gl { +#ifdef GL_TRACK + typedef void (*GLDEBUGPROC)(GLenum source, + GLenum type, + GLuint id, + GLenum severity, + GLsizei length, + const GLchar *message, + const void *userParam); + + template <class... Args> void mbx_trapExtension(const char *name, Args... args); + + void mbx_trapExtension(const char *); + void mbx_trapExtension(const char *, GLint, const char *); + void mbx_trapExtension(const char *, GLsizei, GLuint *); + void mbx_trapExtension(const char *, GLsizei, const GLuint *); + void mbx_trapExtension(const char *, GLenum, GLenum, GLenum, GLsizei, const GLuint *, GLboolean); + void mbx_trapExtension(const char *, GLenum, GLuint, GLsizei, const GLchar *); + void mbx_trapExtension(const char *, GLDEBUGPROC, const void *); + void mbx_trapExtension(const char *, GLuint, GLuint, GLuint, GLuint, GLint, const char *, const void*); + void mbx_trapExtension(const char *name, GLuint array); +#endif + struct Error : ::std::runtime_error { inline Error(GLenum err, const std::string &msg) : ::std::runtime_error(msg), code(err) {}; const GLenum code; @@ -53,6 +79,9 @@ public: typedef std::pair<const char *, const char *> Probe; std::vector<Probe> probes; void (*ptr)(); +#ifdef GL_TRACK + const char *foundName; +#endif }; template <class> @@ -71,6 +100,9 @@ public: } R operator()(Args... args) const { +#ifdef GL_TRACK + mbx_trapExtension(foundName, args...); +#endif return (*reinterpret_cast<R (*)(Args...)>(ptr))(std::forward<Args>(args)...); } }; diff --git a/src/mbgl/platform/gl.cpp b/src/mbgl/platform/gl.cpp index 973fe2e297..abf3d59ee5 100644 --- a/src/mbgl/platform/gl.cpp +++ b/src/mbgl/platform/gl.cpp @@ -29,6 +29,9 @@ void InitializeExtensions(glProc (*getProcAddress)(const char *)) { for (auto fn : ExtensionFunctionBase::functions()) { for (auto probe : fn->probes) { if (extensions.find(probe.first) != std::string::npos) { +#ifdef GL_TRACK + fn->foundName = probe.second; +#endif fn->ptr = getProcAddress(probe.second); break; } @@ -82,13 +85,45 @@ static std::map<GLint, GLsizeiptr> bufferBindingToSizeMap; static unsigned int currentUsedBufferBytes = 0; static unsigned int largestAmountUsedSoFar = 0; +static std::map<GLuint, GLuint> vertexArrayToArrayBufferMap; +static GLuint currentVertexArray = 0; + static std::mutex gDebugMutex; +namespace mbgl { + namespace gl { + void mbx_trapExtension(const char *) { } + void mbx_trapExtension(const char *, GLint, const char *) { } + void mbx_trapExtension(const char *, GLsizei, GLuint *) { } + void mbx_trapExtension(const char *, GLsizei, const GLuint *) { } + void mbx_trapExtension(const char *, GLenum, GLenum, GLenum, GLsizei, const GLuint *, GLboolean) { } + void mbx_trapExtension(const char *, GLenum, GLuint, GLsizei, const GLchar *) { } + void mbx_trapExtension(const char *, GLDEBUGPROC, const void *) { } + void mbx_trapExtension(const char *, GLuint, GLuint, GLuint, GLuint, GLint, const char *, const void*) { } + + void mbx_trapExtension(const char *name, GLuint array) { + if(strncasecmp(name, "glBindVertexArray", 17) == 0) { + currentVertexArray = array; + std::cout << name << ": " << array << std::endl; + } + } + } +} + void mbx_glBindBuffer(GLenum target, GLuint buffer) { std::unique_lock<std::mutex> lock(gDebugMutex); if (target == GL_ARRAY_BUFFER) { currentArrayBuffer = buffer; + if (currentVertexArray != 0) { + if (vertexArrayToArrayBufferMap.find(currentVertexArray) != vertexArrayToArrayBufferMap.end()) { + if (vertexArrayToArrayBufferMap[currentVertexArray] != currentArrayBuffer) { + std::cout << "glBindBuffer: ERROR: You are re-binding a VAO to point to a new array buffer. This is almost certainly unintended." << std::endl; + } + } + std::cout << "glBindBuffer: binding VAO " << currentVertexArray << " to array buffer " << currentArrayBuffer << std::endl; + vertexArrayToArrayBufferMap[currentVertexArray] = currentArrayBuffer; + } } else if (target == GL_ELEMENT_ARRAY_BUFFER) { currentElementArrayBuffer = buffer; } @@ -138,11 +173,11 @@ void mbx_glBufferData(GLenum target, void mbx_glShaderSource(GLuint shader, - GLsizei count, - const GLchar * const *string, + GLsizei count, + const GLchar * const *string, const GLint *length) { //std::cout << "Calling glShaderSource: " << *string << std::endl; - glShaderSource(shader, count, string, length); + glShaderSource(shader, count, const_cast<const GLchar **>(string), length); } void mbx_glClear(GLbitfield mask) { |