diff options
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_debug.cpp | 35 |
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 |