[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.
This commit is contained in:
Bruno de Oliveira Abinader
2016-05-21 12:01:24 +03:00
parent 645dd25d0b
commit 7143408f69
6 changed files with 51 additions and 22 deletions

View File

@@ -42,6 +42,7 @@ enum class MapDebugOptions : EnumType {
ParseStatus = 1 << 2,
Timestamps = 1 << 3,
Collision = 1 << 4,
Wireframe = 1 << 5,
};
inline MapDebugOptions operator| (const MapDebugOptions& lhs, const MapDebugOptions& rhs) {

View File

@@ -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)

View File

@@ -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));

View File

@@ -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()));

View File

@@ -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

View File

@@ -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());