summaryrefslogtreecommitdiff
path: root/platform/default/glfw_view.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/default/glfw_view.cpp')
-rw-r--r--platform/default/glfw_view.cpp73
1 files changed, 63 insertions, 10 deletions
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 83e2c65585..a4e8d7059f 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -1,10 +1,12 @@
+#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
-#include <mbgl/platform/default/glfw_view.hpp>
-#include <mbgl/platform/gl.hpp>
+#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/gl_values.hpp>
+#include <mbgl/gl/gl_helper.hpp>
#include <mbgl/platform/log.hpp>
-#include <mbgl/util/gl_helper.hpp>
+#include <mbgl/platform/platform.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/chrono.hpp>
@@ -135,6 +137,9 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!mods)
view->map->resetPosition();
break;
+ case GLFW_KEY_C:
+ view->toggleClipMasks();
+ break;
case GLFW_KEY_S:
if (view->changeStyleCallback)
view->changeStyleCallback();
@@ -231,6 +236,11 @@ void GLFWView::nextOrientation() {
}
}
+void GLFWView::toggleClipMasks() {
+ showClipMasks = !showClipMasks;
+ map->update(mbgl::Update::Repaint);
+}
+
void GLFWView::addRandomCustomPointAnnotations(int count) {
std::vector<mbgl::PointAnnotation> points;
@@ -438,9 +448,52 @@ void GLFWView::beforeRender() {
}
void GLFWView::afterRender() {
+ if (showClipMasks) {
+ renderClipMasks();
+ }
+
glfwSwapBuffers(window);
}
+void GLFWView::renderClipMasks() {
+ // Read the stencil buffer
+ auto pixels = std::make_unique<uint8_t[]>(fbWidth * fbHeight);
+ glReadPixels(0, // GLint x
+ 0, // GLint y
+ fbWidth, // GLsizei width
+ fbHeight, // GLsizei height
+ GL_STENCIL_INDEX, // GLenum format
+ GL_UNSIGNED_BYTE, // GLenum type
+ pixels.get() // GLvoid * data
+ );
+
+ // Scale the Stencil buffer to cover the entire color space.
+ auto it = pixels.get();
+ auto end = it + fbWidth * fbHeight;
+ const auto factor = 255.0f / *std::max_element(it, end);
+ for (; it != end; ++it) {
+ *it *= factor;
+ }
+
+ using namespace mbgl::gl;
+ Preserve<PixelZoom> pixelZoom;
+ Preserve<RasterPos> rasterPos;
+ Preserve<StencilTest> stencilTest;
+ Preserve<DepthTest> depthTest;
+ Preserve<Program> program;
+ Preserve<ColorMask> colorMask;
+
+ MBGL_CHECK_ERROR(glPixelZoom(1.0f, 1.0f));
+ MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, -1.0f));
+ MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST));
+ MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
+ MBGL_CHECK_ERROR(glUseProgram(0));
+ MBGL_CHECK_ERROR(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
+ MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
+
+ MBGL_CHECK_ERROR(glDrawPixels(fbWidth, fbHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
+}
+
void GLFWView::report(float duration) {
frames++;
frameTime += duration;
@@ -496,8 +549,8 @@ void showDebugImage(std::string name, const char *data, size_t width, size_t hei
float scale = static_cast<float>(fbWidth) / static_cast<float>(width);
{
- gl::PreservePixelZoom pixelZoom;
- gl::PreserveRasterPos rasterPos;
+ gl::Preserve<gl::PixelZoom> pixelZoom;
+ gl::Preserve<gl::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
@@ -533,11 +586,11 @@ void showColorDebugImage(std::string name, const char *data, size_t logicalWidth
float yScale = static_cast<float>(fbHeight) / static_cast<float>(height);
{
- gl::PreserveClearColor clearColor;
- gl::PreserveBlend blend;
- gl::PreserveBlendFunc blendFunc;
- gl::PreservePixelZoom pixelZoom;
- gl::PreserveRasterPos rasterPos;
+ gl::Preserve<gl::ClearColor> clearColor;
+ gl::Preserve<gl::Blend> blend;
+ gl::Preserve<gl::BlendFunc> blendFunc;
+ gl::Preserve<gl::PixelZoom> pixelZoom;
+ gl::Preserve<gl::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));