diff options
author | Adam Hunter <adam@mapbox.com> | 2015-09-17 14:10:18 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2015-09-29 15:07:39 -0700 |
commit | 3f9f2596190c4dbf87425d793a8d51a75547ba89 (patch) | |
tree | d3ee1bc33e6ad5e84363f792f1187f9c53710ef1 | |
parent | 6d357eb0c87897ef99926a4b2b12d0ae3354e7d8 (diff) | |
download | qtlocation-mapboxgl-3f9f2596190c4dbf87425d793a8d51a75547ba89.tar.gz |
Added GL logging utility
-rw-r--r-- | include/mbgl/platform/gl.hpp | 40 | ||||
-rw-r--r-- | ios/app/app-info.plist | 2 | ||||
-rw-r--r-- | platform/default/headless_view.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/platform/gl.cpp | 141 |
5 files changed, 204 insertions, 1 deletions
diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index 6bcb85fee7..1e3f13427b 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -1,6 +1,8 @@ #ifndef MBGL_RENDERER_GL #define MBGL_RENDERER_GL +//#define GL_TRACK + #include <string> #include <stdexcept> #include <vector> @@ -84,4 +86,42 @@ void InitializeExtensions(glProc (*getProcAddress)(const char *)); #define glDepthRange glDepthRangef #endif +#ifdef GL_TRACK +#define glBindTexture mbx_glBindTexture +#define glDeleteTexture mbx_glDeleteTexture +#define glTexImage2D mbx_glTexImage2D +#define glClear mbx_glClear +#define glShaderSource mbx_glShaderSource +#define glBufferData mbx_glBufferData +#define glBindBuffer mbx_glBindBuffer +#define glDeleteBuffers mbx_glDeleteBuffers + +void mbx_glDeleteBuffers(GLsizei n, + const GLuint * buffers); +void mbx_glBindBuffer(GLenum target, + GLuint buffer); +void mbx_glBufferData(GLenum target, + GLsizeiptr size, + const GLvoid * data, + GLenum usage); +void mbx_glShaderSource(GLuint shader, + GLsizei count, + const GLchar * const *string, + const GLint *length); +void mbx_glClear(GLbitfield mask); +void mbx_glBindTexture( GLenum target, + GLuint texture); +void mbx_glDeleteTextures(GLsizei n, + const GLuint * textures); +void mbx_glTexImage2D(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const GLvoid * data); +#endif + #endif diff --git a/ios/app/app-info.plist b/ios/app/app-info.plist index d497d09e76..757be15c78 100644 --- a/ios/app/app-info.plist +++ b/ios/app/app-info.plist @@ -2,6 +2,8 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> + <key>MGLMapboxAccessToken</key> + <string>pk.eyJ1IjoiYWRhbS1tYXBib3giLCJhIjoiMWE1M2QzNmI0YTk4OGRmMDlkYTRkY2UyOTM5Y2E1ZjQifQ.YYiIeO_J_JyPmRvh_zf-gw</string> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleDisplayName</key> diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 0e688163a1..aa80a1e720 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -11,6 +11,7 @@ #include <string> #include <cstring> #include <cassert> +#include <iostream> #ifdef MBGL_USE_CGL #include <CoreFoundation/CoreFoundation.h> @@ -22,6 +23,7 @@ namespace mbgl { HeadlessView::HeadlessView(float pixelRatio_, uint16_t width, uint16_t height) : display(std::make_shared<HeadlessDisplay>()), pixelRatio(pixelRatio_) { + std::cout << "HeadlessView::HeadlessView" << std::endl; resize(width, height); } @@ -30,10 +32,12 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display_, uint16_t width, uint16_t height) : display(display_), pixelRatio(pixelRatio_) { + std::cout << "HeadlessView::HeadlessView" << std::endl; resize(width, height); } void HeadlessView::loadExtensions() { + std::cout << "HeadlessView::loadExtensions" << std::endl; if (extensionsLoaded) { return; } @@ -63,6 +67,7 @@ void HeadlessView::loadExtensions() { } void HeadlessView::createContext() { + std::cout << "HeadlessView::createContext" << std::endl; if (!display) { throw std::runtime_error("Display is not set"); } @@ -115,6 +120,7 @@ bool HeadlessView::isActive() { } void HeadlessView::resizeFramebuffer() { + std::cout << "HeadlessView::resizeFramebuffer: " << this << std::endl; assert(isActive()); if (!needsResize) return; @@ -135,6 +141,7 @@ void HeadlessView::resizeFramebuffer() { MBGL_CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h)); MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); + std::cout << "I am creating a new framebuffer right here: " << this << " " << fbo << std::endl; MBGL_CHECK_ERROR(glGenFramebuffersEXT(1, &fbo)); MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)); @@ -162,11 +169,16 @@ void HeadlessView::resizeFramebuffer() { } void HeadlessView::resize(const uint16_t width, const uint16_t height) { + if(dimensions[0] == width && + dimensions[1] == height) { + return; + } dimensions = {{ width, height }}; needsResize = true; } std::unique_ptr<StillImage> HeadlessView::readStillImage() { + std::cout << "HeadlessView::readStillImage: " << this << "fbo = " << fbo<< std::endl; assert(isActive()); const unsigned int w = dimensions[0] * pixelRatio; @@ -192,13 +204,16 @@ std::unique_ptr<StillImage> HeadlessView::readStillImage() { } void HeadlessView::clearBuffers() { + std::cout << "HeadlessView::clearBuffers: " << this << "fbo = " << fbo << std::endl; assert(isActive()); MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)); if (fbo) { MBGL_CHECK_ERROR(glDeleteFramebuffersEXT(1, &fbo)); + std::cout << "HeadlessView::clearBuffers2: " << this << "fbo = " << fbo << std::endl; fbo = 0; + std::cout << "HeadlessView::clearBuffers3: " << this << "fbo = " << fbo << std::endl; } if (fboColor) { @@ -213,6 +228,7 @@ void HeadlessView::clearBuffers() { } HeadlessView::~HeadlessView() { + std::cout << "HeadlessView::~HeadlessView" << std::endl; activate(); clearBuffers(); deactivate(); @@ -249,7 +265,8 @@ std::array<uint16_t, 2> HeadlessView::getFramebufferSize() const { } void HeadlessView::activate() { - if (thread != std::thread::id()) { + std::cout << "HeadlessView::activate" << std::endl; + if (thread != std::thread::id()) { throw std::runtime_error("OpenGL context was already current"); } thread = std::this_thread::get_id(); @@ -275,6 +292,7 @@ void HeadlessView::activate() { } void HeadlessView::deactivate() { + std::cout << "HeadlessView::deactivate" << std::endl; if (thread == std::thread::id()) { throw std::runtime_error("OpenGL context was not current"); } diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 4ba8d6cd8f..fa565376f9 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -11,6 +11,8 @@ #include <mbgl/util/thread.hpp> #include <mbgl/util/math.hpp> +#include <iostream> + namespace mbgl { Map::Map(View& view_, FileSource& fileSource, MapMode mode) diff --git a/src/mbgl/platform/gl.cpp b/src/mbgl/platform/gl.cpp index d387f3fbf8..06f055b0d8 100644 --- a/src/mbgl/platform/gl.cpp +++ b/src/mbgl/platform/gl.cpp @@ -1,6 +1,10 @@ #include <mbgl/platform/gl.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/platform/log.hpp> +#include <cassert> +#include <iostream> +#include <map> #include <mutex> namespace mbgl { @@ -55,6 +59,143 @@ void checkError(const char *cmd, const char *file, int line) { throw ::mbgl::gl::Error(err, std::string(cmd) + ": Error GL_" + error + " - " + file + ":" + util::toString(line)); } } +} +} + +#ifdef GL_TRACK +#undef glBindTexture +#undef glDeleteTextures +#undef glTexImage2D +#undef glClear +#undef glShaderSource +#undef glBufferData +#undef glBindBuffer +#undef glDeleteBuffers +#undef glBufferData +static unsigned int current_used_bytes = 0; +static GLint current_bound_texture = 0; +static std::map<GLint, unsigned int> binding_to_size_map; + +static GLuint current_array_buffer = 0; +static GLuint current_element_array_buffer = 0; +static std::map<GLint, GLsizeiptr> buffer_binding_to_size_map; +static unsigned int current_used_buffer_bytes = 0; +static unsigned int largest_amount_used_so_far = 0; + +static std::mutex g_debug_mutex; +void mbx_glBindBuffer(GLenum target, + GLuint buffer) { + g_debug_mutex.lock(); + if(target == GL_ARRAY_BUFFER) { + current_array_buffer = buffer; + } else if(target == GL_ELEMENT_ARRAY_BUFFER) { + current_element_array_buffer = buffer; + } + g_debug_mutex.unlock(); + glBindBuffer(target, buffer); } + +void mbx_glDeleteBuffers(GLsizei n, + const GLuint * buffers) { + g_debug_mutex.lock(); + for(int i = 0; i < n; ++i) { + if(buffer_binding_to_size_map.find(buffers[i]) != buffer_binding_to_size_map.end()) { + current_used_buffer_bytes -= buffer_binding_to_size_map[buffers[i]]; + std::cout << "GL glDeleteBuffers: " << buffers[i] << " freeing " << buffer_binding_to_size_map[buffers[i]] << " bytes current total " << current_used_buffer_bytes << "\n"; + buffer_binding_to_size_map.erase(buffers[i]); + } + } + g_debug_mutex.unlock(); + glDeleteBuffers(n, buffers); } + +void mbx_glBufferData(GLenum target, + GLsizeiptr size, + const GLvoid * data, + GLenum usage) { + g_debug_mutex.lock(); + GLuint current_binding = 0; + if(target == GL_ARRAY_BUFFER) { + current_binding = current_array_buffer; + } else if(target == GL_ELEMENT_ARRAY_BUFFER) { + current_binding = current_element_array_buffer; + } + if(buffer_binding_to_size_map.find(current_binding) != buffer_binding_to_size_map.end()) { + current_used_buffer_bytes -= buffer_binding_to_size_map[current_binding]; + std::cout << "GL glBufferData: " << current_binding << " freeing " << buffer_binding_to_size_map[current_binding] << " bytes current total " << current_used_buffer_bytes << "\n"; + } + buffer_binding_to_size_map[current_binding] = size; + current_used_buffer_bytes += size; + if (current_used_buffer_bytes > largest_amount_used_so_far) { + largest_amount_used_so_far = current_used_buffer_bytes; + } + std::cout << "GL glBufferData: " << current_binding << " using " << buffer_binding_to_size_map[current_binding] << " bytes current total " << current_used_buffer_bytes << " high water mark " << largest_amount_used_so_far << "\n"; + g_debug_mutex.unlock(); + + glBufferData(target, size, data, usage); +} + + +void mbx_glShaderSource(GLuint shader, + GLsizei count, + const GLchar * const *string, + const GLint *length) { + //std::cout << "Calling glShaderSource: " << *string << std::endl; + glShaderSource(shader, count, string, length); +} + +void mbx_glClear(GLbitfield mask) { + //std::cout << "Calling glClear" << std::endl; + glClear(mask); +} + +void mbx_glBindTexture( GLenum target, + GLuint texture) { + g_debug_mutex.lock(); + if (target == GL_TEXTURE_2D) { + current_bound_texture = texture; + } + g_debug_mutex.unlock(); + glBindTexture(target, texture); +} + +void mbx_glDeleteTextures(GLsizei n, + const GLuint * textures) { + g_debug_mutex.lock(); + for(int i = 0; i < n; ++i) { + if(binding_to_size_map.find(textures[i]) != binding_to_size_map.end()) { + std::cout << "GL deleteTexture:" << textures[i] << "freeing " << binding_to_size_map[textures[i]] << " bytes current total " << current_used_bytes << "\n"; + current_used_bytes -= binding_to_size_map[textures[i]]; + binding_to_size_map.erase(textures[i]); + } + } + g_debug_mutex.unlock(); + glDeleteTextures(n, textures); +} + +void mbx_glTexImage2D(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const GLvoid * data) { + g_debug_mutex.lock(); + if (internalformat == GL_RGBA && + type == GL_UNSIGNED_BYTE) { + if (binding_to_size_map.find(current_bound_texture) != binding_to_size_map.end()) { + current_used_bytes -= binding_to_size_map[current_bound_texture]; + std::cout << "GL glTexImage2D: " << current_bound_texture << " freeing " << binding_to_size_map[current_bound_texture] << " bytes current total " << current_used_bytes << "\n"; + } + binding_to_size_map[current_bound_texture] = width * height * 4; + current_used_bytes += binding_to_size_map[current_bound_texture]; + std::cout << "GL glTexImage2D: " << current_bound_texture << " freeing " << binding_to_size_map[current_bound_texture] << " bytes current total " << current_used_bytes << "\n"; + } + g_debug_mutex.unlock(); + glTexImage2D(target, level, internalformat, width, height, border, format, type, data); +} +#endif + |