summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-08-19 15:22:13 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-08-19 17:41:55 +0200
commit0df60c46517648b18e65d860f5a9356ba751ca11 (patch)
treefbe895bed6aaac9f65ee095a48e1b12e10af5b3b /src
parentcb33c861b4cfa82d7afcb5b9ec85d7797679a7d8 (diff)
downloadqtlocation-mapboxgl-0df60c46517648b18e65d860f5a9356ba751ca11.tar.gz
[core] add ability show visualize the depth buffer to the GLFW and macOS app
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/painter.cpp6
-rw-r--r--src/mbgl/renderer/painter.hpp2
-rw-r--r--src/mbgl/renderer/painter_debug.cpp35
3 files changed, 43 insertions, 0 deletions
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 8500a946fd..163095d85b 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -198,6 +198,12 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
}
}
+#ifndef NDEBUG
+ if (frame.debugOptions & MapDebugOptions::DepthBuffer) {
+ renderDepthBuffer();
+ }
+#endif
+
// TODO: Find a better way to unbind VAOs after we're done with them without introducing
// unnecessary bind(0)/bind(N) sequences.
{
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 2b6c1efdea..119155e011 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -89,6 +89,8 @@ public:
#ifndef NDEBUG
// Renders tile clip boundaries, using stencil buffer to calculate fill color.
void renderClipMasks();
+ // Renders the depth buffer.
+ void renderDepthBuffer();
#endif
void renderDebugText(Tile&, const mat4&);
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index d6336b843c..7c24f67fb4 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -125,4 +125,39 @@ void Painter::renderClipMasks() {
}
#endif // NDEBUG
+#ifndef NDEBUG
+void Painter::renderDepthBuffer() {
+ config.stencilTest = GL_FALSE;
+ config.depthTest = GL_FALSE;
+ config.program = 0;
+ config.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
+
+#ifndef GL_ES_VERSION_2_0
+ config.pixelZoom = { 1, 1 };
+ config.rasterPos = {{ -1, -1, 0, 0 }};
+
+ // Read the stencil buffer
+ const auto& fbSize = frame.framebufferSize;
+ auto pixels = std::make_unique<GLubyte[]>(fbSize[0] * fbSize[1]);
+
+ const double base = 1.0 / (1.0 - depthRangeSize);
+ glPixelTransferf(GL_DEPTH_SCALE, base);
+ glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base);
+
+ MBGL_CHECK_ERROR(glReadPixels(
+ 0, // GLint x
+ 0, // GLint y
+ fbSize[0], // GLsizei width
+ fbSize[1], // GLsizei height
+ GL_DEPTH_COMPONENT, // GLenum format
+ GL_UNSIGNED_BYTE, // GLenum type
+ pixels.get() // GLvoid * data
+ ));
+
+ MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
+ MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
+#endif // GL_ES_VERSION_2_0
+}
+#endif // NDEBUG
+
} // namespace mbgl