From 62379a8e6b5f0fcca47dcdaeea6f60b6be9707f4 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Thu, 29 Nov 2018 07:26:02 +0100 Subject: [PATCH] CMake TANGRAM_DEV_DEBUG_REDERER option - We should not bake these into releases --- CMakeLists.txt | 2 ++ core/CMakeLists.txt | 26 ++++++++++++++++++++----- core/src/debug/frameInfo.cpp | 2 ++ core/src/debug/frameInfo.h | 14 ++++++++++---- core/src/debug/textDisplay.cpp | 4 ++-- core/src/debug/textDisplay.h | 26 +++++++++++++++++++------ core/src/gl/framebuffer.cpp | 2 +- core/src/gl/primitives.cpp | 21 ++++++++++---------- core/src/gl/primitives.h | 35 ++++++++++++++++++++++------------ core/src/labels/labels.cpp | 5 +++++ core/src/map.cpp | 18 ++++++++--------- core/src/scene/sceneLoader.cpp | 7 +++++-- 12 files changed, 110 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af1b37ed91..5ca4091b26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ option(TANGRAM_MBTILES_DATASOURCE "Build MBTiles Datasource" ON) option(TANGRAM_BUILD_TESTS "Build unit tests" OFF) option(TANGRAM_BUNDLE_TESTS "Compile all tests into a single binary" ON) option(TANGRAM_BUILD_BENCHMARKS "Build benchmarks" OFF) + option(TANGRAM_DEV_MODE "For developers only: Don't omit the frame pointer" OFF) +option(TANGRAM_DEV_DEBUG_RENDERER "Build debug TextDisplay, RenderLayers and other things to toggle via DebugFlags" OFF) message(STATUS "Build type configuration: ${CMAKE_BUILD_TYPE}") diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f5cda004d7..29c86913ea 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -3,6 +3,7 @@ project(tangram-core) # Build core library dependencies. add_subdirectory(deps) + add_library(tangram-core src/map.cpp src/platform.cpp @@ -15,14 +16,11 @@ add_library(tangram-core src/data/formats/geoJson.cpp src/data/formats/mvt.cpp src/data/formats/topoJson.cpp - src/debug/frameInfo.cpp - src/debug/textDisplay.cpp src/gl/framebuffer.cpp src/gl/glError.cpp src/gl/glyphTexture.cpp src/gl/hardware.cpp src/gl/mesh.cpp - src/gl/primitives.cpp src/gl/renderState.cpp src/gl/shaderProgram.cpp src/gl/shaderSource.cpp @@ -58,8 +56,6 @@ add_library(tangram-core src/scene/styleParam.cpp src/selection/featureSelection.cpp src/selection/selectionQuery.cpp - src/style/debugStyle.cpp - src/style/debugTextStyle.cpp src/style/material.cpp src/style/pointStyle.cpp src/style/pointStyleBuilder.cpp @@ -168,6 +164,26 @@ if(TANGRAM_WARN_ON_RULE_CONFLICT) TANGRAM_WARN_ON_RULE_CONFLICT) endif() +if(TANGRAM_DEV_MODE) + target_compile_definitions(tangram-core + PRIVATE + TANGRAM_DEV_MODE) + + if(TANGRAM_DEV_DEBUG_RENDERER) + target_compile_definitions(tangram-core + PRIVATE + TANGRAM_DEBUG_RENDERER) + + target_sources(tangram-core + PRIVATE + src/debug/frameInfo.cpp + src/debug/textDisplay.cpp + src/style/debugStyle.cpp + src/style/debugTextStyle.cpp + src/gl/primitives.cpp) + endif() +endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang target_compile_options(tangram-core diff --git a/core/src/debug/frameInfo.cpp b/core/src/debug/frameInfo.cpp index 3144d0752d..b14f4aab0b 100644 --- a/core/src/debug/frameInfo.cpp +++ b/core/src/debug/frameInfo.cpp @@ -18,6 +18,7 @@ #define DEBUG_STATS_MAX_SIZE 128 namespace Tangram { +namespace Debug { static float s_lastUpdateTime = 0.0; @@ -154,3 +155,4 @@ void FrameInfo::draw(RenderState& rs, const View& _view, TileManager& _tileManag } } +} diff --git a/core/src/debug/frameInfo.h b/core/src/debug/frameInfo.h index f3c607b2ec..9b2971b193 100644 --- a/core/src/debug/frameInfo.h +++ b/core/src/debug/frameInfo.h @@ -6,14 +6,20 @@ class RenderState; class TileManager; class View; -struct FrameInfo { +namespace Debug { +struct FrameInfo { +#ifdef TANGRAM_DEBUG_RENDERER static void beginUpdate(); static void beginFrame(); - static void endUpdate(); - static void draw(RenderState& rs, const View& _view, TileManager& _tileManager); +#else + static void beginUpdate(){} + static void beginFrame(){} + static void endUpdate(){} + static void draw(RenderState&, const View&, TileManager&){} +#endif }; - +} } diff --git a/core/src/debug/textDisplay.cpp b/core/src/debug/textDisplay.cpp index 5b3166ee30..9151be3b01 100644 --- a/core/src/debug/textDisplay.cpp +++ b/core/src/debug/textDisplay.cpp @@ -12,6 +12,7 @@ #include "stb_easy_font.h" namespace Tangram { +namespace Debug { TextDisplay::TextDisplay() : m_textDisplayResolution(350.0), m_initialized(false) { m_vertexBuffer = new char[VERTEX_BUFFER_SIZE]; @@ -142,7 +143,6 @@ void TextDisplay::draw(RenderState& rs, const std::vector& _infos) rs.culling(GL_TRUE); rs.vertexBuffer(boundbuffer); } - } - +} diff --git a/core/src/debug/textDisplay.h b/core/src/debug/textDisplay.h index 51787c0faf..dbfc4c3f2e 100644 --- a/core/src/debug/textDisplay.h +++ b/core/src/debug/textDisplay.h @@ -19,6 +19,8 @@ namespace Tangram { typedef int FontID; class RenderState; +namespace Debug { + template std::string to_string_with_precision(const T a_value, const int n = 6) { std::ostringstream out; @@ -36,8 +38,9 @@ class TextDisplay { return instance; } - ~TextDisplay(); +#ifdef TANGRAM_DEBUG_RENDERER + ~TextDisplay(); void setResolution(glm::vec2 _textDisplayResolution) { m_textDisplayResolution = _textDisplayResolution; } void init(); @@ -45,14 +48,11 @@ class TextDisplay { /* Draw stacked messages added through log and draw _infos string list */ void draw(RenderState& rs, const std::vector& _infos); - /* Stack the log message to be displayed in the screen log */ void log(const char* fmt, ...); private: - TextDisplay(); - void draw(RenderState& rs, const std::string& _text, int _posx, int _posy); glm::vec2 m_textDisplayResolution; @@ -64,10 +64,24 @@ class TextDisplay { UniformLocation m_uOrthoProj{"u_orthoProj"}; UniformLocation m_uColor{"u_color"}; - +#else + ~TextDisplay() {} + void setResolution(glm::vec2) {} + void init() {} + void deinit() {} + void draw(RenderState&, const std::vector&) {} + void log(const char* fmt, ...) {} +private: + TextDisplay(){} +#endif }; +} +#ifdef TANGRAM_DEBUG_RENDERER #define LOGS(fmt, ...) \ -do { Tangram::TextDisplay::Instance().log(fmt, ## __VA_ARGS__); } while(0) + do { Tangram::Debug::TextDisplay::Instance().log(fmt, ## __VA_ARGS__); } while(0) +#else +#define LOGS(...) +#endif } diff --git a/core/src/gl/framebuffer.cpp b/core/src/gl/framebuffer.cpp index a8886e198d..86eb8f8ccf 100644 --- a/core/src/gl/framebuffer.cpp +++ b/core/src/gl/framebuffer.cpp @@ -185,7 +185,7 @@ FrameBuffer::~FrameBuffer() { void FrameBuffer::drawDebug(RenderState& _rs, glm::vec2 _dim) { if (m_texture) { - Primitives::drawTexture(_rs, *m_texture, glm::vec2{}, _dim); + Debug::Primitives::drawTexture(_rs, *m_texture, glm::vec2{}, _dim); } } diff --git a/core/src/gl/primitives.cpp b/core/src/gl/primitives.cpp index 2524c25229..d150d62f10 100644 --- a/core/src/gl/primitives.cpp +++ b/core/src/gl/primitives.cpp @@ -16,8 +16,7 @@ #include "debugTexture_fs.h" namespace Tangram { - -namespace Primitives { +namespace Debug { static bool s_initialized; static std::unique_ptr s_shader; @@ -32,7 +31,7 @@ static std::unique_ptr s_textureLayout; static UniformLocation s_uTextureProj{"u_proj"}; -void init() { +void Primitives::init() { // lazy init if (!s_initialized) { @@ -60,7 +59,7 @@ void init() { } } -void deinit() { +void Primitives::deinit() { s_shader.reset(nullptr); s_layout.reset(nullptr); @@ -70,7 +69,7 @@ void deinit() { } -void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) { +void Primitives::drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) { init(); @@ -94,14 +93,14 @@ void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _desti rs.vertexBuffer(boundBuffer); } -void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) { +void Primitives::drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) { drawLine(rs, _origin, {_destination.x, _origin.y}); drawLine(rs, {_destination.x, _origin.y}, _destination); drawLine(rs, _destination, {_origin.x, _destination.y}); drawLine(rs, {_origin.x,_destination.y}, _origin); } -void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) { +void Primitives::drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) { init(); if (!s_shader->use(rs)) { return; } @@ -119,7 +118,7 @@ void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) { rs.vertexBuffer(boundBuffer); } -void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim) { +void Primitives::drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim) { init(); if (!s_textureShader->use(rs)) { return; } @@ -156,7 +155,7 @@ void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim) rs.vertexBuffer(boundBuffer); } -void setColor(RenderState& rs, unsigned int _color) { +void Primitives::setColor(RenderState& rs, unsigned int _color) { init(); float r = (_color >> 16 & 0xff) / 255.0; @@ -166,7 +165,7 @@ void setColor(RenderState& rs, unsigned int _color) { s_shader->setUniformf(rs, s_uColor, r, g, b); } -void setResolution(RenderState& rs, float _width, float _height) { +void Primitives::setResolution(RenderState& rs, float _width, float _height) { init(); glm::mat4 proj = glm::ortho(0.f, _width, _height, 0.f, -1.f, 1.f); @@ -175,5 +174,5 @@ void setResolution(RenderState& rs, float _width, float _height) { } } - } + diff --git a/core/src/gl/primitives.h b/core/src/gl/primitives.h index 1e3388e678..732dc90306 100644 --- a/core/src/gl/primitives.h +++ b/core/src/gl/primitives.h @@ -7,28 +7,39 @@ namespace Tangram { class RenderState; class Texture; -namespace Primitives { +namespace Debug { -void init(); -void deinit(); +struct Primitives { +#ifdef TANGRAM_DEBUG_RENDERER +static void init(); +static void deinit(); /* Setup the debug resolution size */ -void setResolution(RenderState& rs, float _width, float _height); +static void setResolution(RenderState& rs, float _width, float _height); /* Sets the current primitive color */ -void setColor(RenderState& rs, unsigned int _color); +static void setColor(RenderState& rs, unsigned int _color); /* Draws a line from _origin to _destination for the screen resolution _resolution */ -void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination); +static void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination); /* Draws a rect from _origin to _destination for the screen resolution _resolution */ -void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination); +static void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination); /* Draws a polyon of containing _n points in screen space for the screen resolution _resolution */ -void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n); - -void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim); - +static void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n); + +static void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim); +#else +static void init(){} +static void deinit(){} +static void setResolution(RenderState& rs, float _width, float _height){} +static void setColor(RenderState& rs, unsigned int _color){} +static void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination){} +static void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination){} +static void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n){} +static void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim){} +#endif +}; } - } diff --git a/core/src/labels/labels.cpp b/core/src/labels/labels.cpp index e7093f29fa..cdeb105b10 100644 --- a/core/src/labels/labels.cpp +++ b/core/src/labels/labels.cpp @@ -496,7 +496,9 @@ void Labels::updateLabelSet(const ViewState& _viewState, float _dt, } } +#ifdef TAGRAM_DEBUG_RENDERER void Labels::drawDebug(RenderState& rs, const View& _view) { + using Primitives = Debug::Primitives; if (!Tangram::getDebugFlag(Tangram::DebugFlags::labels)) { return; @@ -625,5 +627,8 @@ void Labels::drawDebug(RenderState& rs, const View& _view) { } } } +#else +void Labels::drawDebug(RenderState& rs, const View& _view) {} +#endif } diff --git a/core/src/map.cpp b/core/src/map.cpp index e40879b78e..783d7cc765 100644 --- a/core/src/map.cpp +++ b/core/src/map.cpp @@ -126,8 +126,8 @@ Map::~Map() { // All jobs will be executed immediately on add() afterwards. impl->jobQueue.stop(); - TextDisplay::Instance().deinit(); - Primitives::deinit(); + Debug::TextDisplay::Instance().deinit(); + Debug::Primitives::deinit(); } void Map::Impl::setScene(std::shared_ptr& _scene) { @@ -382,7 +382,7 @@ void Map::resize(int _newWidth, int _newHeight) { impl->selectionBuffer = std::make_unique(_newWidth/2, _newHeight/2); - Primitives::setResolution(impl->renderState, _newWidth, _newHeight); + Debug::Primitives::setResolution(impl->renderState, _newWidth, _newHeight); } bool Map::update(float _dt) { @@ -395,7 +395,7 @@ bool Map::update(float _dt) { return false; } - FrameInfo::beginUpdate(); + Debug::FrameInfo::beginUpdate(); impl->scene->updateTime(_dt); @@ -451,7 +451,7 @@ bool Map::update(float _dt) { } } - FrameInfo::endUpdate(); + Debug::FrameInfo::endUpdate(); bool viewChanged = impl->view.changedOnLastUpdate(); bool tilesChanged = impl->tileManager.hasTileSetChanged(); @@ -504,7 +504,7 @@ bool Map::render() { // Cache default framebuffer handle used for rendering impl->renderState.cacheDefaultFramebuffer(); - FrameInfo::beginFrame(); + Debug::FrameInfo::beginFrame(); // Invalidate render states for new frame if (!impl->cacheGlState) { @@ -555,7 +555,7 @@ bool Map::render() { if (drawSelectionBuffer) { impl->selectionBuffer->drawDebug(impl->renderState, viewport); - FrameInfo::draw(impl->renderState, impl->view, impl->tileManager); + Debug::FrameInfo::draw(impl->renderState, impl->view, impl->tileManager); return impl->isCameraEasing; } @@ -583,7 +583,7 @@ bool Map::render() { impl->labels.drawDebug(impl->renderState, impl->view); - FrameInfo::draw(impl->renderState, impl->view, impl->tileManager); + Debug::FrameInfo::draw(impl->renderState, impl->view, impl->tileManager); return impl->isCameraEasing; } @@ -1079,7 +1079,7 @@ void Map::setupGL() { } // Set default primitive render color - Primitives::setColor(impl->renderState, 0xffffff); + Debug::Primitives::setColor(impl->renderState, 0xffffff); // Load GL extensions and capabilities Hardware::loadExtensions(); diff --git a/core/src/scene/sceneLoader.cpp b/core/src/scene/sceneLoader.cpp index 93fdd36ad0..65798d0cf1 100644 --- a/core/src/scene/sceneLoader.cpp +++ b/core/src/scene/sceneLoader.cpp @@ -184,12 +184,15 @@ bool SceneLoader::applyConfig(const std::shared_ptr& _platform, const // Instantiate built-in styles _scene->styles().emplace_back(new PolygonStyle("polygons")); _scene->styles().emplace_back(new PolylineStyle("lines")); - _scene->styles().emplace_back(new DebugTextStyle("debugtext", _scene->fontContext(), true)); _scene->styles().emplace_back(new TextStyle("text", _scene->fontContext(), true)); - _scene->styles().emplace_back(new DebugStyle("debug")); _scene->styles().emplace_back(new PointStyle("points", _scene->fontContext())); _scene->styles().emplace_back(new RasterStyle("raster")); +#ifdef TANGRAM_DEBUG_RENDERER + _scene->styles().emplace_back(new DebugTextStyle("debugtext", _scene->fontContext(), true)); + _scene->styles().emplace_back(new DebugStyle("debug")); +#endif + if (config["global"]) { applyGlobals(config, *_scene); }