add debug window showing the glyph atlas

This commit is contained in:
Konstantin Käfer
2014-03-14 12:43:42 +01:00
parent 99cef810ac
commit 3c5bac0f6b
6 changed files with 43 additions and 11 deletions

View File

@@ -68,12 +68,10 @@ public:
glfwSetKeyCallback(window, key);
}
static void character(GLFWwindow *window, unsigned int codepoint) {
}
static void key(GLFWwindow *window, int key, int scancode, int action, int mods) {
MapView *mapView = (MapView *)glfwGetWindowUserPointer(window);
@@ -95,7 +93,6 @@ public:
}
}
static void scroll(GLFWwindow *window, double xoffset, double yoffset) {
MapView *mapView = (MapView *)glfwGetWindowUserPointer(window);
double delta = yoffset * 40;
@@ -234,3 +231,38 @@ public:
llmr::Settings& settings;
llmr::Map map;
};
namespace llmr {
namespace platform {
double time() {
return glfwGetTime();
}
void show_debug_image(std::string name, const char *data, size_t width, size_t height) {
static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
if (!debug_window) {
glfwTerminate();
fprintf(stderr, "Failed to initialize window\n");
exit(1);
}
}
GLFWwindow *current_window = glfwGetCurrentContext();
glfwSetWindowSize(debug_window, width, height);
glfwMakeContextCurrent(debug_window);
glPixelZoom(1.0, -1.0);
glRasterPos2f(-1.0f, 1.0f);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
glfwSwapBuffers(debug_window);
glfwMakeContextCurrent(current_window);
}
}
}

View File

@@ -34,6 +34,9 @@ double time();
// Performs routine cleanup operation and is called on every loop iteration.
void cleanup();
// Shows an RGBA image with the specified dimensions in a named window.
void show_debug_image(std::string name, const char *data, size_t width, size_t height);
}
}

View File

@@ -110,9 +110,5 @@ void cancel_request_http(Request *request) {
}
}
double time() {
return glfwGetTime();
}
}
}

View File

@@ -84,9 +84,5 @@ void cancel_request_http(Request *request)
}];
}
double time() {
return glfwGetTime();
}
}
}

View File

@@ -1,6 +1,7 @@
#include <llmr/geometry/glyph_atlas.hpp>
#include <llmr/map/vector_tile.hpp>
#include <llmr/platform/gl.hpp>
#include <llmr/platform/platform.hpp>
#include <cassert>
#include <algorithm>
@@ -135,5 +136,7 @@ void GlyphAtlas::bind() {
std::lock_guard<std::mutex> lock(mtx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
dirty = false;
platform::show_debug_image("Glyph Atlas", data, width, height);
}
};

View File

@@ -432,6 +432,8 @@ bool Map::render() {
transform.updateAnimations();
}
glyphAtlas.bind();
bool changed = updateTiles();
painter.clear();