Skip to content

Commit ce13a79

Browse files
committed
CMake TANGRAM_DEV_DEBUG_REDERER option
- We should not bake these into releases
1 parent 5842b63 commit ce13a79

12 files changed

+105
-56
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ option(TANGRAM_MBTILES_DATASOURCE "Build MBTiles Datasource" ON)
1414
option(TANGRAM_BUILD_TESTS "Build unit tests" OFF)
1515
option(TANGRAM_BUNDLE_TESTS "Compile all tests into a single binary" ON)
1616
option(TANGRAM_BUILD_BENCHMARKS "Build benchmarks" OFF)
17+
1718
option(TANGRAM_DEV_MODE "For developers only: Don't omit the frame pointer" OFF)
19+
option(TANGRAM_DEV_DEBUG_RENDERER "Build debug TextDisplay, RenderLayers and other things to toggle via DebugFlags" OFF)
1820

1921
message(STATUS "Build type configuration: ${CMAKE_BUILD_TYPE}")
2022

@@ -75,6 +77,10 @@ if (TANGRAM_JSCORE_AVAILABLE AND TANGRAM_USE_JSCORE)
7577
set(TANGRAM_JSCORE_ENABLED ON)
7678
endif()
7779

80+
if (TANGRAM_OSX OR TANGRAM_LINUX)
81+
set(TANGRAM_DEV_DEBUG_RENDERER ON)
82+
endif()
83+
7884
# Add core library.
7985
add_subdirectory(core)
8086

core/CMakeLists.txt

+16-10
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ add_library(tangram-core
3434
src/data/formats/mvt.cpp
3535
src/data/formats/topoJson.h
3636
src/data/formats/topoJson.cpp
37-
src/debug/frameInfo.h
38-
src/debug/frameInfo.cpp
39-
src/debug/textDisplay.h
40-
src/debug/textDisplay.cpp
4137
src/gl/framebuffer.h
4238
src/gl/framebuffer.cpp
4339
src/gl/glError.h
@@ -48,8 +44,6 @@ add_library(tangram-core
4844
src/gl/hardware.cpp
4945
src/gl/mesh.h
5046
src/gl/mesh.cpp
51-
src/gl/primitives.h
52-
src/gl/primitives.cpp
5347
src/gl/renderState.h
5448
src/gl/renderState.cpp
5549
src/gl/shaderProgram.h
@@ -122,10 +116,6 @@ add_library(tangram-core
122116
src/selection/featureSelection.cpp
123117
src/selection/selectionQuery.h
124118
src/selection/selectionQuery.cpp
125-
src/style/debugStyle.h
126-
src/style/debugStyle.cpp
127-
src/style/debugTextStyle.h
128-
src/style/debugTextStyle.cpp
129119
src/style/material.h
130120
src/style/material.cpp
131121
src/style/pointStyle.h
@@ -248,6 +238,22 @@ else()
248238
target_link_libraries(tangram-core PRIVATE duktape)
249239
endif()
250240

241+
if(TANGRAM_DEV_DEBUG_RENDERER)
242+
target_compile_definitions(tangram-core PRIVATE TANGRAM_DEBUG_RENDERER=1)
243+
target_sources(tangram-core
244+
PRIVATE
245+
src/debug/frameInfo.h
246+
src/debug/frameInfo.cpp
247+
src/debug/textDisplay.h
248+
src/debug/textDisplay.cpp
249+
src/gl/primitives.h
250+
src/gl/primitives.cpp
251+
src/style/debugStyle.h
252+
src/style/debugStyle.cpp
253+
src/style/debugTextStyle.h
254+
src/style/debugTextStyle.cpp)
255+
endif()
256+
251257
# Add MBTiles implementation.
252258
if(TANGRAM_MBTILES_DATASOURCE)
253259
target_sources(tangram-core PRIVATE src/data/mbtilesDataSource.cpp)

core/src/debug/frameInfo.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define DEBUG_STATS_MAX_SIZE 128
1919

2020
namespace Tangram {
21+
namespace Debug {
2122

2223
static float s_lastUpdateTime = 0.0;
2324

@@ -154,3 +155,4 @@ void FrameInfo::draw(RenderState& rs, const View& _view, const TileManager& _til
154155
}
155156

156157
}
158+
}

core/src/debug/frameInfo.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ class RenderState;
66
class TileManager;
77
class View;
88

9-
struct FrameInfo {
9+
namespace Debug {
1010

11+
struct FrameInfo {
12+
#ifdef TANGRAM_DEBUG_RENDERER
1113
static void beginUpdate();
1214
static void beginFrame();
13-
1415
static void endUpdate();
15-
1616
static void draw(RenderState& rs, const View& _view, const TileManager& _tileManager);
17+
#else
18+
static void beginUpdate(){}
19+
static void beginFrame(){}
20+
static void endUpdate(){}
21+
static void draw(RenderState&, const View&, TileManager&){}
22+
#endif
1723
};
18-
24+
}
1925
}

core/src/debug/textDisplay.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "stb_easy_font.h"
1313

1414
namespace Tangram {
15+
namespace Debug {
1516

1617
TextDisplay::TextDisplay() : m_textDisplayResolution(350.0), m_initialized(false) {
1718
m_vertexBuffer = new char[VERTEX_BUFFER_SIZE];
@@ -142,7 +143,6 @@ void TextDisplay::draw(RenderState& rs, const std::vector<std::string>& _infos)
142143
rs.culling(GL_TRUE);
143144
rs.vertexBuffer(boundbuffer);
144145
}
145-
146146
}
147-
147+
}
148148

core/src/debug/textDisplay.h

+20-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace Tangram {
1919
typedef int FontID;
2020
class RenderState;
2121

22+
namespace Debug {
23+
2224
template <typename T>
2325
std::string to_string_with_precision(const T a_value, const int n = 6) {
2426
std::ostringstream out;
@@ -36,23 +38,21 @@ class TextDisplay {
3638
return instance;
3739
}
3840

39-
~TextDisplay();
4041

42+
#ifdef TANGRAM_DEBUG_RENDERER
43+
~TextDisplay();
4144
void setResolution(glm::vec2 _textDisplayResolution) { m_textDisplayResolution = _textDisplayResolution; }
4245

4346
void init();
4447
void deinit();
4548

4649
/* Draw stacked messages added through log and draw _infos string list */
4750
void draw(RenderState& rs, const std::vector<std::string>& _infos);
48-
4951
/* Stack the log message to be displayed in the screen log */
5052
void log(const char* fmt, ...);
5153

5254
private:
53-
5455
TextDisplay();
55-
5656
void draw(RenderState& rs, const std::string& _text, int _posx, int _posy);
5757

5858
glm::vec2 m_textDisplayResolution;
@@ -64,10 +64,24 @@ class TextDisplay {
6464

6565
UniformLocation m_uOrthoProj{"u_orthoProj"};
6666
UniformLocation m_uColor{"u_color"};
67-
67+
#else
68+
~TextDisplay() {}
69+
void setResolution(glm::vec2) {}
70+
void init() {}
71+
void deinit() {}
72+
void draw(RenderState&, const std::vector<std::string>&) {}
73+
void log(const char* fmt, ...) {}
74+
private:
75+
TextDisplay(){}
76+
#endif
6877
};
78+
}
6979

80+
#ifdef TANGRAM_DEBUG_RENDERER
7081
#define LOGS(fmt, ...) \
71-
do { Tangram::TextDisplay::Instance().log(fmt, ## __VA_ARGS__); } while(0)
82+
do { Tangram::Debug::TextDisplay::Instance().log(fmt, ## __VA_ARGS__); } while(0)
83+
#else
84+
#define LOGS(...)
85+
#endif
7286

7387
}

core/src/gl/framebuffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ FrameBuffer::~FrameBuffer() {
185185
void FrameBuffer::drawDebug(RenderState& _rs, glm::vec2 _dim) {
186186

187187
if (m_texture) {
188-
Primitives::drawTexture(_rs, *m_texture, glm::vec2{}, _dim);
188+
Debug::Primitives::drawTexture(_rs, *m_texture, glm::vec2{}, _dim);
189189
}
190190
}
191191

core/src/gl/primitives.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#include "debugTexture_fs.h"
1717

1818
namespace Tangram {
19-
20-
namespace Primitives {
19+
namespace Debug {
2120

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

3332
static UniformLocation s_uTextureProj{"u_proj"};
3433

35-
void init() {
34+
void Primitives::init() {
3635

3736
// lazy init
3837
if (!s_initialized) {
@@ -60,7 +59,7 @@ void init() {
6059
}
6160
}
6261

63-
void deinit() {
62+
void Primitives::deinit() {
6463

6564
s_shader.reset(nullptr);
6665
s_layout.reset(nullptr);
@@ -70,7 +69,7 @@ void deinit() {
7069

7170
}
7271

73-
void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) {
72+
void Primitives::drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) {
7473

7574
init();
7675

@@ -94,14 +93,14 @@ void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _desti
9493
rs.vertexBuffer(boundBuffer);
9594
}
9695

97-
void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) {
96+
void Primitives::drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination) {
9897
drawLine(rs, _origin, {_destination.x, _origin.y});
9998
drawLine(rs, {_destination.x, _origin.y}, _destination);
10099
drawLine(rs, _destination, {_origin.x, _destination.y});
101100
drawLine(rs, {_origin.x,_destination.y}, _origin);
102101
}
103102

104-
void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) {
103+
void Primitives::drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) {
105104
init();
106105

107106
if (!s_shader->use(rs)) { return; }
@@ -119,7 +118,7 @@ void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n) {
119118
rs.vertexBuffer(boundBuffer);
120119
}
121120

122-
void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim) {
121+
void Primitives::drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim) {
123122
init();
124123

125124
if (!s_textureShader->use(rs)) { return; }
@@ -156,7 +155,7 @@ void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim)
156155
rs.vertexBuffer(boundBuffer);
157156
}
158157

159-
void setColor(RenderState& rs, unsigned int _color) {
158+
void Primitives::setColor(RenderState& rs, unsigned int _color) {
160159
init();
161160

162161
float r = (_color >> 16 & 0xff) / 255.0;
@@ -166,7 +165,7 @@ void setColor(RenderState& rs, unsigned int _color) {
166165
s_shader->setUniformf(rs, s_uColor, r, g, b);
167166
}
168167

169-
void setResolution(RenderState& rs, float _width, float _height) {
168+
void Primitives::setResolution(RenderState& rs, float _width, float _height) {
170169
init();
171170

172171
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) {
175174
}
176175

177176
}
178-
179177
}
178+

core/src/gl/primitives.h

+23-12
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,39 @@ namespace Tangram {
77
class RenderState;
88
class Texture;
99

10-
namespace Primitives {
10+
namespace Debug {
1111

12-
void init();
13-
void deinit();
12+
struct Primitives {
13+
#ifdef TANGRAM_DEBUG_RENDERER
14+
static void init();
15+
static void deinit();
1416

1517
/* Setup the debug resolution size */
16-
void setResolution(RenderState& rs, float _width, float _height);
18+
static void setResolution(RenderState& rs, float _width, float _height);
1719

1820
/* Sets the current primitive color */
19-
void setColor(RenderState& rs, unsigned int _color);
21+
static void setColor(RenderState& rs, unsigned int _color);
2022

2123
/* Draws a line from _origin to _destination for the screen resolution _resolution */
22-
void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination);
24+
static void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination);
2325

2426
/* Draws a rect from _origin to _destination for the screen resolution _resolution */
25-
void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination);
27+
static void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination);
2628

2729
/* Draws a polyon of containing _n points in screen space for the screen resolution _resolution */
28-
void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n);
29-
30-
void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim);
31-
30+
static void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n);
31+
32+
static void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim);
33+
#else
34+
static void init(){}
35+
static void deinit(){}
36+
static void setResolution(RenderState& rs, float _width, float _height){}
37+
static void setColor(RenderState& rs, unsigned int _color){}
38+
static void drawLine(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination){}
39+
static void drawRect(RenderState& rs, const glm::vec2& _origin, const glm::vec2& _destination){}
40+
static void drawPoly(RenderState& rs, const glm::vec2* _polygon, size_t _n){}
41+
static void drawTexture(RenderState& rs, Texture& _tex, glm::vec2 _pos, glm::vec2 _dim){}
42+
#endif
43+
};
3244
}
33-
3445
}

core/src/labels/labelManager.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ void LabelManager::updateLabelSet(const ViewState& _viewState, float _dt, const
495495
}
496496

497497
void LabelManager::drawDebug(RenderState& rs, const View& _view) {
498+
#ifdef TAGRAM_DEBUG_RENDERER
499+
using Primitives = Debug::Primitives;
498500

499501
if (!Tangram::getDebugFlag(Tangram::DebugFlags::labels)) {
500502
return;
@@ -622,6 +624,7 @@ void LabelManager::drawDebug(RenderState& rs, const View& _view) {
622624
}
623625
}
624626
}
627+
#endif // DEBUG_RENDERER
625628
}
626629

627630
}

0 commit comments

Comments
 (0)