diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-05-21 12:01:24 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-05-23 11:50:05 +0300 |
commit | 7143408f69618828bb37b8f38d719d3ceeeec9c2 (patch) | |
tree | 094a1d373129c1288331e3d9079e1ef8aeac1693 /src | |
parent | 645dd25d0b8fa3ca39c2362083e7822f4a955fe4 (diff) | |
download | qtlocation-mapboxgl-7143408f69618828bb37b8f38d719d3ceeeec9c2.tar.gz |
[core] Implement MapDebugOptions::Wireframe
Together with MapDebugOptions::Collision, provides "wireframe" rendering
output so all drawn objects are visible. This mode ignores the line
width, background and fill colors for better visualization.
Fixes #4359.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_background.cpp | 28 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_line.cpp | 19 |
5 files changed, 50 insertions, 22 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 0a6adfc565..fc2a653510 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -796,8 +796,10 @@ void Map::setDebug(MapDebugOptions debugOptions) { } void Map::cycleDebugOptions() { - if (impl->debugOptions & MapDebugOptions::Collision) + if (impl->debugOptions & MapDebugOptions::Wireframe) impl->debugOptions = MapDebugOptions::NoDebug; + else if (impl->debugOptions & MapDebugOptions::Collision) + impl->debugOptions = MapDebugOptions::Collision | MapDebugOptions::Wireframe; else if (impl->debugOptions & MapDebugOptions::Timestamps) impl->debugOptions = impl->debugOptions | MapDebugOptions::Collision; else if (impl->debugOptions & MapDebugOptions::ParseStatus) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 175770dbb1..b03e4d1afe 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -141,7 +141,11 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a config.depthTest = GL_FALSE; config.depthMask = GL_TRUE; config.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE }; - config.clearColor = { background[0], background[1], background[2], background[3] }; + if (frame.debugOptions & MapDebugOptions::Wireframe) { + config.clearColor = { 0.0f, 0.0f, 0.0f, 1.0f }; + } else { + config.clearColor = { background[0], background[1], background[2], background[3] }; + } config.clearStencil = 0; config.clearDepth = 1; MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index e71e9677d1..5054722e79 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -14,10 +14,13 @@ void Painter::renderBackground(const BackgroundLayer& layer) { // glClear rather than this method. const BackgroundPaintProperties& properties = layer.paint; - const bool isPatterned = !properties.backgroundPattern.value.to.empty();// && false; + bool isPatterned = !properties.backgroundPattern.value.to.empty();// && false; optional<SpriteAtlasPosition> imagePosA; optional<SpriteAtlasPosition> imagePosB; + bool wireframe = frame.debugOptions & MapDebugOptions::Wireframe; + isPatterned &= !wireframe; + if (isPatterned) { imagePosA = spriteAtlas->getPosition(properties.backgroundPattern.value.from, true); imagePosB = spriteAtlas->getPosition(properties.backgroundPattern.value.to, true); @@ -38,14 +41,18 @@ void Painter::renderBackground(const BackgroundLayer& layer) { backgroundPatternArray.bind(*patternShader, tileStencilBuffer, BUFFER_OFFSET(0), glObjectStore); } else { - Color color = properties.backgroundColor; - color[0] *= properties.backgroundOpacity; - color[1] *= properties.backgroundOpacity; - color[2] *= properties.backgroundOpacity; - color[3] *= properties.backgroundOpacity; + if (wireframe) { + plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; + } else { + Color color = properties.backgroundColor; + color[0] *= properties.backgroundOpacity; + color[1] *= properties.backgroundOpacity; + color[2] *= properties.backgroundOpacity; + color[3] *= properties.backgroundOpacity; + plainShader->u_color = color; + } config.program = plainShader->getID(); - plainShader->u_color = color; backgroundArray.bind(*plainShader, tileStencilBuffer, BUFFER_OFFSET(0), glObjectStore); } @@ -99,8 +106,11 @@ void Painter::renderBackground(const BackgroundLayer& layer) { } else { plainShader->u_matrix = vtxMatrix; - Color color = properties.backgroundColor; - plainShader->u_color = color; + if (wireframe) { + plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; + } else { + plainShader->u_color = properties.backgroundColor; + } } MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)tileStencilBuffer.index())); diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 2e103462e6..1ac90a2806 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -33,11 +33,19 @@ void Painter::renderFill(FillBucket& bucket, stroke_color[3] *= properties.fillOpacity; } - const bool pattern = !properties.fillPattern.value.from.empty(); - + bool pattern = !properties.fillPattern.value.from.empty(); bool outline = properties.fillAntialias && !pattern && stroke_color != fill_color; bool fringeline = properties.fillAntialias && !pattern && stroke_color == fill_color; + bool wireframe = frame.debugOptions & MapDebugOptions::Wireframe; + if (wireframe) { + fill_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + stroke_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + pattern = false; + outline = true; + fringeline = true; + } + config.stencilOp.reset(); config.stencilTest = GL_TRUE; config.depthFunc.reset(); @@ -154,8 +162,7 @@ void Painter::renderFill(FillBucket& bucket, bucket.drawVertices(*outlinePatternShader, glObjectStore); } } - } - else { + } else if (!wireframe) { // No image fill. if ((fill_color[3] >= 1.0f) == (pass == RenderPass::Opaque)) { // Only draw the fill when it's either opaque and we're drawing opaque diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 6adf471cef..c0706dcdd7 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -30,13 +30,15 @@ void Painter::renderLine(LineBucket& bucket, // Retina devices need a smaller distance to avoid aliasing. float antialiasing = 1.0 / frame.pixelRatio; + bool wireframe = frame.debugOptions & MapDebugOptions::Wireframe; + float blur = properties.lineBlur + antialiasing; - float edgeWidth = properties.lineWidth / 2.0; + float edgeWidth = wireframe ? 1 : properties.lineWidth / 2.0; float inset = -1; float offset = 0; float shift = 0; - if (properties.lineGapWidth != 0) { + if (properties.lineGapWidth != 0 && !wireframe) { inset = properties.lineGapWidth / 2.0 + antialiasing * 0.5; edgeWidth = properties.lineWidth; @@ -46,11 +48,14 @@ void Painter::renderLine(LineBucket& bucket, float outset = offset + edgeWidth + antialiasing / 2.0 + shift; - Color color = properties.lineColor; - color[0] *= properties.lineOpacity; - color[1] *= properties.lineOpacity; - color[2] *= properties.lineOpacity; - color[3] *= properties.lineOpacity; + Color color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + if (!wireframe) { + color = properties.lineColor; + color[0] *= properties.lineOpacity; + color[1] *= properties.lineOpacity; + color[2] *= properties.lineOpacity; + color[3] *= properties.lineOpacity; + } const float ratio = 1.0 / tileID.pixelsToTileUnits(1.0, state.getZoom()); |