Skip to content

Commit

Permalink
CMake TANGRAM_DEV_DEBUG_REDERER option
Browse files Browse the repository at this point in the history
- We should not bake these into releases
  • Loading branch information
hjanetzek committed Dec 7, 2018
1 parent 014c3c5 commit a1e6a34
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 52 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
26 changes: 21 additions & 5 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(tangram-core)
# Build core library dependencies.
add_subdirectory(deps)


add_library(tangram-core
src/map.cpp
src/platform.cpp
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions core/src/debug/frameInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DEBUG_STATS_MAX_SIZE 128

namespace Tangram {
namespace Debug {

static float s_lastUpdateTime = 0.0;

Expand Down Expand Up @@ -154,3 +155,4 @@ void FrameInfo::draw(RenderState& rs, const View& _view, TileManager& _tileManag
}

}
}
14 changes: 10 additions & 4 deletions core/src/debug/frameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

}
}
4 changes: 2 additions & 2 deletions core/src/debug/textDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -142,7 +143,6 @@ void TextDisplay::draw(RenderState& rs, const std::vector<std::string>& _infos)
rs.culling(GL_TRUE);
rs.vertexBuffer(boundbuffer);
}

}

}

26 changes: 20 additions & 6 deletions core/src/debug/textDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Tangram {
typedef int FontID;
class RenderState;

namespace Debug {

template <typename T>
std::string to_string_with_precision(const T a_value, const int n = 6) {
std::ostringstream out;
Expand All @@ -36,23 +38,21 @@ class TextDisplay {
return instance;
}

~TextDisplay();

#ifdef TANGRAM_DEBUG_RENDERER
~TextDisplay();
void setResolution(glm::vec2 _textDisplayResolution) { m_textDisplayResolution = _textDisplayResolution; }

void init();
void deinit();

/* Draw stacked messages added through log and draw _infos string list */
void draw(RenderState& rs, const std::vector<std::string>& _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;
Expand All @@ -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<std::string>&) {}
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

}
2 changes: 1 addition & 1 deletion core/src/gl/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
21 changes: 10 additions & 11 deletions core/src/gl/primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "debugTexture_fs.h"

namespace Tangram {

namespace Primitives {
namespace Debug {

static bool s_initialized;
static std::unique_ptr<ShaderProgram> s_shader;
Expand All @@ -32,7 +31,7 @@ static std::unique_ptr<VertexLayout> s_textureLayout;

static UniformLocation s_uTextureProj{"u_proj"};

void init() {
void Primitives::init() {

// lazy init
if (!s_initialized) {
Expand Down Expand Up @@ -60,7 +59,7 @@ void init() {
}
}

void deinit() {
void Primitives::deinit() {

s_shader.reset(nullptr);
s_layout.reset(nullptr);
Expand All @@ -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();

Expand All @@ -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; }
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -175,5 +174,5 @@ void setResolution(RenderState& rs, float _width, float _height) {
}

}

}

35 changes: 23 additions & 12 deletions core/src/gl/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

}
5 changes: 5 additions & 0 deletions core/src/labels/labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -625,5 +627,8 @@ void Labels::drawDebug(RenderState& rs, const View& _view) {
}
}
}
#else
void Labels::drawDebug(RenderState& rs, const View& _view) {}
#endif

}
Loading

0 comments on commit a1e6a34

Please sign in to comment.