[core] Move GLFW stencil clip debug to core
This makes the stencil clip debug available to all platforms. Fixes #4669.
This commit is contained in:
@@ -797,8 +797,15 @@ void Map::setDebug(MapDebugOptions debugOptions) {
|
||||
}
|
||||
|
||||
void Map::cycleDebugOptions() {
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
if (impl->debugOptions & MapDebugOptions::StencilClip)
|
||||
impl->debugOptions = MapDebugOptions::NoDebug;
|
||||
else if (impl->debugOptions & MapDebugOptions::Wireframe)
|
||||
impl->debugOptions = MapDebugOptions::StencilClip;
|
||||
#else
|
||||
if (impl->debugOptions & MapDebugOptions::Wireframe)
|
||||
impl->debugOptions = MapDebugOptions::NoDebug;
|
||||
#endif // GL_ES_VERSION_2_0
|
||||
else if (impl->debugOptions & MapDebugOptions::Collision)
|
||||
impl->debugOptions = MapDebugOptions::Collision | MapDebugOptions::Wireframe;
|
||||
else if (impl->debugOptions & MapDebugOptions::Timestamps)
|
||||
|
||||
@@ -169,6 +169,11 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
|
||||
drawClippingMasks(generator.getStencils());
|
||||
}
|
||||
|
||||
if (frame.debugOptions & MapDebugOptions::StencilClip) {
|
||||
renderClipMasks();
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually render the layers
|
||||
if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; }
|
||||
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
// Renders the red debug frame around a tile, visualizing its perimeter.
|
||||
void renderDebugFrame(const mat4 &matrix);
|
||||
|
||||
void renderClipMasks();
|
||||
|
||||
void renderDebugText(TileData&, const mat4&);
|
||||
void renderFill(FillBucket&, const FillLayer&, const UnwrappedTileID&, const mat4&);
|
||||
void renderLine(LineBucket&, const LineLayer&, const UnwrappedTileID&, const mat4&);
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <mbgl/shader/plain_shader.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/gl/debugging.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
#include <mbgl/gl/gl_values.hpp>
|
||||
#include <mbgl/gl/gl_helper.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
@@ -75,3 +78,39 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
|
||||
config.lineWidth = 4.0f * frame.pixelRatio;
|
||||
MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));
|
||||
}
|
||||
|
||||
void Painter::renderClipMasks() {
|
||||
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<uint8_t[]>(fbSize[0] * fbSize[1]);
|
||||
MBGL_CHECK_ERROR(glReadPixels(
|
||||
0, // GLint x
|
||||
0, // GLint y
|
||||
fbSize[0], // GLsizei width
|
||||
fbSize[1], // 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 + fbSize[0] * fbSize[1];
|
||||
const auto factor = 255.0f / *std::max_element(it, end);
|
||||
for (; it != end; ++it) {
|
||||
*it *= factor;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user