diff --git a/src/geometry/glyph_atlas.cpp b/src/geometry/glyph_atlas.cpp index f4defac69..afb904407 100644 --- a/src/geometry/glyph_atlas.cpp +++ b/src/geometry/glyph_atlas.cpp @@ -137,6 +137,8 @@ void GlyphAtlas::bind() { glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); dirty = false; +#if defined(DEBUG) // platform::show_debug_image("Glyph Atlas", data, width, height); +#endif } }; diff --git a/src/geometry/sprite_atlas.cpp b/src/geometry/sprite_atlas.cpp index 35f6f4588..882c6c17d 100644 --- a/src/geometry/sprite_atlas.cpp +++ b/src/geometry/sprite_atlas.cpp @@ -270,8 +270,9 @@ void SpriteAtlas::bind(bool linear) { data // const GLvoid * data ); +#if defined(DEBUG) // platform::show_color_debug_image("Sprite Atlas", data, width, height, width * pixelRatio, height * pixelRatio); - +#endif dirty = false; } }; diff --git a/src/map/map.cpp b/src/map/map.cpp index 7ac6dbe0e..60a7aa78d 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -479,8 +479,9 @@ void Map::prepare() { } void Map::render() { +#if defined(DEBUG) std::vector debug; - +#endif painter.clear(); painter.resetFramebuffer(); @@ -493,6 +494,7 @@ void Map::render() { painter.drawClippingMasks(sources); +#if defined(DEBUG) // Generate debug information size_t source_id = 0; for (const auto &pair : sources) { @@ -501,7 +503,7 @@ void Map::render() { debug.emplace_back(util::sprintf<100>("source %d: %d\n", source_id, count)); source_id++; } - +#endif // Actually render the layers if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } renderLayers(style.layers); @@ -520,7 +522,9 @@ void Map::render() { painter.renderMatte(); +#if defined(DEBUG) painter.renderDebugText(debug); +#endif // Schedule another rerender when we definitely need a next frame. if (transform.needsTransition()) { @@ -573,12 +577,14 @@ void Map::renderLayers(const std::vector& layers) { template typename Styles::const_iterator find_style(const Styles &styles, const LayerDescription &layer_desc) { auto it = styles.find(layer_desc.name); +#if defined(DEBUG) if (it == styles.end()) { if (debug::renderWarnings) { fprintf(stderr, "[WARNING] can't find class named '%s' in style\n", layer_desc.name.c_str()); } } +#endif return it; } diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 9ad752526..2c8a47deb 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -42,7 +42,9 @@ void TileData::request() { // Schedule tile parsing in another thread tile->reparse(); } else { +#if defined(DEBUG) fprintf(stderr, "[%s] tile loading failed: %d, %s\n", tile->url.c_str(), res->code, res->error_message.c_str()); +#endif } }, map.getLoop()); } diff --git a/src/map/vector_tile_data.cpp b/src/map/vector_tile_data.cpp index 3c972aa31..4a1e91f41 100644 --- a/src/map/vector_tile_data.cpp +++ b/src/map/vector_tile_data.cpp @@ -24,7 +24,9 @@ void VectorTileData::parse() { // is going to be discarded afterwards. TileParser parser(data, *this, map.getStyle(), map.getGlyphAtlas(), map.getGlyphStore(), map.getSpriteAtlas()); } catch (const std::exception& ex) { +#if defined(DEBUG) fprintf(stderr, "[%p] exception [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what()); +#endif cancel(); return; } diff --git a/src/renderer/fill_bucket.cpp b/src/renderer/fill_bucket.cpp index 2a4e1c78a..702156659 100644 --- a/src/renderer/fill_bucket.cpp +++ b/src/renderer/fill_bucket.cpp @@ -182,18 +182,24 @@ void FillBucket::tessellate() { if (a != TESS_UNDEF && b != TESS_UNDEF && c != TESS_UNDEF) { triangleElementsBuffer.add(triangleIndex + a, triangleIndex + b, triangleIndex + c); } else { +#if defined(DEBUG) // TODO: We're missing a vertex that was not part of the line. fprintf(stderr, "undefined element buffer\n"); +#endif } } else { +#if defined(DEBUG) fprintf(stderr, "undefined element buffer\n"); +#endif } } triangleGroup.vertex_length += total_vertex_count; triangleGroup.elements_length += triangle_count; } else { +#if defined(DEBUG) fprintf(stderr, "tessellation failed\n"); +#endif } // We're adding the total vertex count *after* we added additional vertices diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 82808f4d1..b755301eb 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -1,13 +1,13 @@ #include - #include - #include #include -#include #include #include #include +#if defined(DEBUG) +#include +#endif #include #include @@ -29,8 +29,9 @@ bool Painter::needsAnimation() const { } void Painter::setup() { +#if defined(DEBUG) util::timer timer("painter setup"); - +#endif setupShaders(); assert(iconShader); diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp index 0c3c0a01b..bd1709a96 100644 --- a/src/renderer/painter_text.cpp +++ b/src/renderer/painter_text.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using namespace llmr; @@ -66,8 +67,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons history[0].z = history[1].z; } - size_t frameLen = history.size(); - assert("there should never be less than three frames in the history" && frameLen >= 3); + assert("there should never be less than three frames in the history" && (history.size() >= 3)); // Find the range of zoom levels we want to fade between float startingZ = history.front().z; @@ -81,7 +81,9 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons timeDiff = lastFrame.timestamp - history[1].timestamp; float fadedist = zoomDiff / (timeDiff / duration); - if (isnan(fadedist)) fprintf(stderr, "fadedist should never be NaN\n"); +#if defined(DEBUG) + if (std::isnan(fadedist)) fprintf(stderr, "fadedist should never be NaN\n"); +#endif // At end of a zoom when the zoom stops changing continue pretending to zoom at that speed // bump is how much farther it would have been if it had continued zooming at the same rate diff --git a/src/shader/gaussian_shader.cpp b/src/shader/gaussian_shader.cpp index 450ce331a..03509de41 100644 --- a/src/shader/gaussian_shader.cpp +++ b/src/shader/gaussian_shader.cpp @@ -12,7 +12,9 @@ GaussianShader::GaussianShader() shaders[GAUSSIAN_SHADER].fragment ) { if (!valid) { +#if defined(DEBUG) fprintf(stderr, "invalid raster shader\n"); +#endif return; } diff --git a/src/shader/raster_shader.cpp b/src/shader/raster_shader.cpp index eaf45ea2b..f083d3e26 100644 --- a/src/shader/raster_shader.cpp +++ b/src/shader/raster_shader.cpp @@ -12,7 +12,9 @@ RasterShader::RasterShader() shaders[RASTER_SHADER].fragment ) { if (!valid) { +#if defined(DEBUG) fprintf(stderr, "invalid raster shader\n"); +#endif return; } diff --git a/src/shader/shader.cpp b/src/shader/shader.cpp index 97e494f65..70b59e7aa 100644 --- a/src/shader/shader.cpp +++ b/src/shader/shader.cpp @@ -1,7 +1,8 @@ #include #include +#if defined(DEBUG) #include - +#endif #include #include #include @@ -11,18 +12,23 @@ using namespace llmr; Shader::Shader(const GLchar *vertSource, const GLchar *fragSource) : valid(false), program(0) { +#if defined(DEBUG) util::timer timer("shader compilation"); - +#endif GLuint vertShader; if (!compileShader(&vertShader, GL_VERTEX_SHADER, vertSource)) { +#if defined(DEBUG) fprintf(stderr, "Vertex shader failed to compile: %s\n", vertSource); +#endif return; } GLuint fragShader; if (!compileShader(&fragShader, GL_FRAGMENT_SHADER, fragSource)) { +#if defined(DEBUG) fprintf(stderr, "Fragment shader failed to compile: %s\n", fragSource); +#endif return; } @@ -80,7 +86,9 @@ Shader::Shader(const GLchar *vertSource, const GLchar *fragSource) glGetProgramiv(program, GL_VALIDATE_STATUS, &status); if (status == 0) { +#if defined(DEBUG) fprintf(stderr, "Program failed to validate\n"); +#endif glDeleteShader(vertShader); vertShader = 0; glDeleteShader(fragShader); diff --git a/src/style/sprite.cpp b/src/style/sprite.cpp index bb24c5fec..a0070b288 100644 --- a/src/style/sprite.cpp +++ b/src/style/sprite.cpp @@ -54,7 +54,9 @@ void Sprite::complete(std::shared_ptr &sprite) { if (sprite->raster && sprite->pos.size()) { sprite->loaded = true; sprite->map.update(); +#if defined(DEBUG) fprintf(stderr, "sprite loaded\n"); +#endif } } diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 3f741236f..4a4517b70 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -52,7 +52,9 @@ GlyphPBF::GlyphPBF(const std::string &fontStack, GlyphRange glyphRange) // TODO: Find more reliable URL normalization function std::replace(url.begin(), url.end(), ' ', '+'); +#if defined(DEBUG) fprintf(stderr, "%s\n", url.c_str()); +#endif platform::request_http(url, [&](platform::Response *res) { if (res->code != 200) { diff --git a/src/util/constants.cpp b/src/util/constants.cpp index f67464926..c939bbde4 100644 --- a/src/util/constants.cpp +++ b/src/util/constants.cpp @@ -2,6 +2,7 @@ const float llmr::util::tileSize = 512.0f; +#if defined(DEBUG) const bool llmr::debug::tileParseWarnings = false; const bool llmr::debug::styleParseWarnings = false; const bool llmr::debug::spriteWarnings = false; @@ -12,3 +13,15 @@ const bool llmr::debug::missingFontStackWarning = true; const bool llmr::debug::missingFontFaceWarning = true; const bool llmr::debug::glyphWarning = true; const bool llmr::debug::shapingWarning = true; +#else +const bool llmr::debug::tileParseWarnings = false; +const bool llmr::debug::styleParseWarnings = false; +const bool llmr::debug::spriteWarnings = false; +const bool llmr::debug::renderWarnings = false; +const bool llmr::debug::renderTree = false; +const bool llmr::debug::labelTextMissingWarning = false; +const bool llmr::debug::missingFontStackWarning = false; +const bool llmr::debug::missingFontFaceWarning = false; +const bool llmr::debug::glyphWarning = true; +const bool llmr::debug::shapingWarning = true; +#endif \ No newline at end of file