summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-31 19:45:17 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-11-01 10:46:04 +0100
commitbb6e39a1cfcbd5c478c4b221f723ba948d576e61 (patch)
treebd48c92cedd22a8f7e0b4bb4983f316959fe01b8
parentf7801e5d82d272d53db6925a325391e5da5c842e (diff)
downloadqtlocation-mapboxgl-bb6e39a1cfcbd5c478c4b221f723ba948d576e61.tar.gz
[core] fix depth/stencil visualization
The previous code didn't set the packing correctly, which meant that we had a buffer overrun in the debug code.
-rw-r--r--src/mbgl/renderer/painter_debug.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index 5428631698..a502c3eddf 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -71,6 +71,10 @@ void Painter::renderClipMasks(PaintParameters&) {
context.pixelZoom = { 1, 1 };
context.rasterPos = { -1, -1, 0, 0 };
+ // When reading data from the framebuffer, make sure that we are storing the depth values
+ // tightly packed into the buffer to avoid buffer overruns. Also see unpacking adjustment below.
+ MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 1));
+
// Read the stencil buffer
const auto viewport = context.viewport.getCurrentValue();
auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height);
@@ -92,6 +96,7 @@ void Painter::renderClipMasks(PaintParameters&) {
*it *= factor;
}
+ MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE,
GL_UNSIGNED_BYTE, pixels.get()));
@@ -108,13 +113,19 @@ void Painter::renderDepthBuffer(PaintParameters&) {
context.pixelZoom = { 1, 1 };
context.rasterPos = { -1, -1, 0, 0 };
- // Read the stencil buffer
- const auto viewport = context.viewport.getCurrentValue();
- auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height);
+ // When reading data from the framebuffer, make sure that we are storing the depth values
+ // tightly packed into the buffer to avoid buffer overruns. Also see unpacking adjustment below.
+ MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, 1));
+ // Scales the values in the depth buffer so that they cover the entire grayscale range. This
+ // makes it easier to spot tiny differences.
const double base = 1.0 / (1.0 - depthRangeSize);
- glPixelTransferf(GL_DEPTH_SCALE, base);
- glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base);
+ MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_SCALE, base));
+ MBGL_CHECK_ERROR(glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base));
+
+ // Read the stencil buffer
+ auto viewport = context.viewport.getCurrentValue();
+ auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height);
MBGL_CHECK_ERROR(glReadPixels(
viewport.x, // GLint x
@@ -126,6 +137,7 @@ void Painter::renderDepthBuffer(PaintParameters&) {
pixels.get() // GLvoid * data
));
+ MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE,
GL_UNSIGNED_BYTE, pixels.get()));