Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] CMake TANGRAM_DEV_DEBUG_REDERER option #1966

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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 Expand Up @@ -75,6 +77,10 @@ if (TANGRAM_JSCORE_AVAILABLE AND TANGRAM_USE_JSCORE)
set(TANGRAM_JSCORE_ENABLED ON)
endif()

if (TANGRAM_OSX OR TANGRAM_LINUX)
set(TANGRAM_DEV_DEBUG_RENDERER ON)
endif()

# Add core library.
add_subdirectory(core)

Expand Down
26 changes: 16 additions & 10 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ add_library(tangram-core
src/data/formats/mvt.cpp
src/data/formats/topoJson.h
src/data/formats/topoJson.cpp
src/debug/frameInfo.h
src/debug/frameInfo.cpp
src/debug/textDisplay.h
src/debug/textDisplay.cpp
src/gl/framebuffer.h
src/gl/framebuffer.cpp
src/gl/glError.h
Expand All @@ -48,8 +44,6 @@ add_library(tangram-core
src/gl/hardware.cpp
src/gl/mesh.h
src/gl/mesh.cpp
src/gl/primitives.h
src/gl/primitives.cpp
src/gl/renderState.h
src/gl/renderState.cpp
src/gl/shaderProgram.h
Expand Down Expand Up @@ -122,10 +116,6 @@ add_library(tangram-core
src/selection/featureSelection.cpp
src/selection/selectionQuery.h
src/selection/selectionQuery.cpp
src/style/debugStyle.h
src/style/debugStyle.cpp
src/style/debugTextStyle.h
src/style/debugTextStyle.cpp
src/style/material.h
src/style/material.cpp
src/style/pointStyle.h
Expand Down Expand Up @@ -248,6 +238,22 @@ else()
target_link_libraries(tangram-core PRIVATE duktape)
endif()

if(TANGRAM_DEV_DEBUG_RENDERER)
target_compile_definitions(tangram-core PRIVATE TANGRAM_DEBUG_RENDERER=1)
target_sources(tangram-core
PRIVATE
src/debug/frameInfo.h
src/debug/frameInfo.cpp
src/debug/textDisplay.h
src/debug/textDisplay.cpp
src/gl/primitives.h
src/gl/primitives.cpp
src/style/debugStyle.h
src/style/debugStyle.cpp
src/style/debugTextStyle.h
src/style/debugTextStyle.cpp)
endif()

# Add MBTiles implementation.
if(TANGRAM_MBTILES_DATASOURCE)
target_sources(tangram-core PRIVATE src/data/mbtilesDataSource.cpp)
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, const TileManager& _til
}

}
}
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, const 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
};
}

}
3 changes: 3 additions & 0 deletions core/src/labels/labelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ void LabelManager::updateLabelSet(const ViewState& _viewState, float _dt, const
}

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

if (!Tangram::getDebugFlag(Tangram::DebugFlags::labels)) {
return;
Expand Down Expand Up @@ -622,6 +624,7 @@ void LabelManager::drawDebug(RenderState& rs, const View& _view) {
}
}
}
#endif // DEBUG_RENDERER
}

}
Loading