diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 43e0b4c7c..e6fa79eb5 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -33,10 +33,10 @@ void Painter::renderBackground(const BackgroundLayer& layer) { config.program = patternShader->getID(); patternShader->u_matrix = identityMatrix; - patternShader->u_pattern_tl_a = (*imagePosA).tl; - patternShader->u_pattern_br_a = (*imagePosA).br; - patternShader->u_pattern_tl_b = (*imagePosB).tl; - patternShader->u_pattern_br_b = (*imagePosB).br; + patternShader->u_pattern_tl_a = imagePosA->tl; + patternShader->u_pattern_br_a = imagePosA->br; + patternShader->u_pattern_tl_b = imagePosB->tl; + patternShader->u_pattern_br_b = imagePosB->br; patternShader->u_mix = properties.backgroundPattern.value.t; patternShader->u_opacity = properties.backgroundOpacity; @@ -62,28 +62,26 @@ void Painter::renderBackground(const BackgroundLayer& layer) { config.depthMask = GL_FALSE; setDepthSublayer(0); - auto tileIDs = util::tileCover(state, state.getIntegerZoom()); - - for (auto& id : tileIDs) { - mat4 vtxMatrix; - state.matrixFor(vtxMatrix, id); - matrix::multiply(vtxMatrix, projMatrix, vtxMatrix); + for (const auto& tileID : util::tileCover(state, state.getIntegerZoom())) { + mat4 vertexMatrix; + state.matrixFor(vertexMatrix, tileID); + matrix::multiply(vertexMatrix, projMatrix, vertexMatrix); if (isPatterned) { - patternShader->u_matrix = vtxMatrix; + patternShader->u_matrix = vertexMatrix; patternShader->u_pattern_size_a = imagePosA->size; patternShader->u_pattern_size_b = imagePosB->size; patternShader->u_scale_a = properties.backgroundPattern.value.fromScale; patternShader->u_scale_b = properties.backgroundPattern.value.toScale; - patternShader->u_tile_units_to_pixels = 1.0f / id.pixelsToTileUnits(1.0f, state.getIntegerZoom()); + patternShader->u_tile_units_to_pixels = 1.0f / tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom()); - GLint tileSizeAtNearestZoom = util::tileSize * state.zoomScale(state.getIntegerZoom() - id.canonical.z); - GLint pixelX = tileSizeAtNearestZoom * (id.canonical.x + id.wrap * state.zoomScale(id.canonical.z)); - GLint pixelY = tileSizeAtNearestZoom * id.canonical.y; + GLint tileSizeAtNearestZoom = util::tileSize * state.zoomScale(state.getIntegerZoom() - tileID.canonical.z); + GLint pixelX = tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * state.zoomScale(tileID.canonical.z)); + GLint pixelY = tileSizeAtNearestZoom * tileID.canonical.y; patternShader->u_pixel_coord_upper = {{ float(pixelX >> 16), float(pixelY >> 16) }}; patternShader->u_pixel_coord_lower = {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }}; } else { - plainShader->u_matrix = vtxMatrix; + plainShader->u_matrix = vertexMatrix; } 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 3bf30362c..123215ee2 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace mbgl { @@ -17,25 +18,28 @@ void Painter::renderFill(FillBucket& bucket, const UnwrappedTileID& tileID, const mat4& matrix) { const FillPaintProperties& properties = layer.impl->paint; - mat4 vtxMatrix = + mat4 vertexMatrix = translatedMatrix(matrix, properties.fillTranslate, tileID, properties.fillTranslateAnchor); - Color fill_color = properties.fillColor; + Color fillColor = properties.fillColor; float opacity = properties.fillOpacity; - Color stroke_color = properties.fillOutlineColor; - if (stroke_color.a < 0) { - stroke_color = fill_color; + Color strokeColor = properties.fillOutlineColor; + bool isOutlineColorDefined = strokeColor.a >= 0; + if (!isOutlineColorDefined) { + strokeColor = fillColor; } + auto worldSize = util::convert(frame.framebufferSize); + 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 outline = properties.fillAntialias && !pattern && isOutlineColorDefined; + bool fringeline = properties.fillAntialias && !pattern && !isOutlineColorDefined; 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 }; + fillColor = { 1.0f, 1.0f, 1.0f, 1.0f }; + strokeColor = { 1.0f, 1.0f, 1.0f, 1.0f }; opacity = 1.0f; pattern = false; outline = true; @@ -47,38 +51,35 @@ void Painter::renderFill(FillBucket& bucket, config.depthFunc.reset(); config.depthTest = GL_TRUE; config.depthMask = GL_TRUE; + config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio! // Because we're drawing top-to-bottom, and we update the stencil mask // befrom, we have to draw the outline first (!) if (outline && pass == RenderPass::Translucent) { config.program = outlineShader->getID(); - outlineShader->u_matrix = vtxMatrix; - config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio! + outlineShader->u_matrix = vertexMatrix; - outlineShader->u_outline_color = stroke_color; + outlineShader->u_outline_color = strokeColor; outlineShader->u_opacity = opacity; // Draw the entire line - outlineShader->u_world = {{ - static_cast(frame.framebufferSize[0]), - static_cast(frame.framebufferSize[1]) - }}; + outlineShader->u_world = worldSize; setDepthSublayer(0); bucket.drawVertices(*outlineShader, store); } if (pattern) { - optional posA = spriteAtlas->getPosition(properties.fillPattern.value.from, true); - optional posB = spriteAtlas->getPosition(properties.fillPattern.value.to, true); + optional imagePosA = spriteAtlas->getPosition(properties.fillPattern.value.from, true); + optional imagePosB = spriteAtlas->getPosition(properties.fillPattern.value.to, true); // Image fill. - if (pass == RenderPass::Translucent && posA && posB) { + if (pass == RenderPass::Translucent && imagePosA && imagePosB) { config.program = patternShader->getID(); - patternShader->u_matrix = vtxMatrix; - patternShader->u_pattern_tl_a = (*posA).tl; - patternShader->u_pattern_br_a = (*posA).br; - patternShader->u_pattern_tl_b = (*posB).tl; - patternShader->u_pattern_br_b = (*posB).br; + patternShader->u_matrix = vertexMatrix; + patternShader->u_pattern_tl_a = imagePosA->tl; + patternShader->u_pattern_br_a = imagePosA->br; + patternShader->u_pattern_tl_b = imagePosB->tl; + patternShader->u_pattern_br_b = imagePosB->br; patternShader->u_opacity = properties.fillOpacity; patternShader->u_image = 0; patternShader->u_mix = properties.fillPattern.value.t; @@ -101,21 +102,17 @@ void Painter::renderFill(FillBucket& bucket, setDepthSublayer(0); bucket.drawElements(*patternShader, store); - if (properties.fillAntialias && stroke_color == fill_color) { + if (properties.fillAntialias && !isOutlineColorDefined) { config.program = outlinePatternShader->getID(); - outlinePatternShader->u_matrix = vtxMatrix; - config.lineWidth = 2.0f; + outlinePatternShader->u_matrix = vertexMatrix; // Draw the entire line - outlinePatternShader->u_world = {{ - static_cast(frame.framebufferSize[0]), - static_cast(frame.framebufferSize[1]) - }}; + outlineShader->u_world = worldSize; - outlinePatternShader->u_pattern_tl_a = (*posA).tl; - outlinePatternShader->u_pattern_br_a = (*posA).br; - outlinePatternShader->u_pattern_tl_b = (*posB).tl; - outlinePatternShader->u_pattern_br_b = (*posB).br; + outlinePatternShader->u_pattern_tl_a = imagePosA->tl; + outlinePatternShader->u_pattern_br_a = imagePosA->br; + outlinePatternShader->u_pattern_tl_b = imagePosB->tl; + outlinePatternShader->u_pattern_br_b = imagePosB->br; outlinePatternShader->u_opacity = properties.fillOpacity; outlinePatternShader->u_image = 0; outlinePatternShader->u_mix = properties.fillPattern.value.t; @@ -136,14 +133,14 @@ void Painter::renderFill(FillBucket& bucket, } } else if (!wireframe) { // No image fill. - if ((fill_color.a >= 1.0f && opacity >= 1.0f) == (pass == RenderPass::Opaque)) { + if ((fillColor.a >= 1.0f && opacity >= 1.0f) == (pass == RenderPass::Opaque)) { // Only draw the fill when it's either opaque and we're drawing opaque // fragments or when it's translucent and we're drawing translucent // fragments // Draw filling rectangle. config.program = plainShader->getID(); - plainShader->u_matrix = vtxMatrix; - plainShader->u_color = fill_color; + plainShader->u_matrix = vertexMatrix; + plainShader->u_color = fillColor; plainShader->u_opacity = opacity; // Draw the actual triangles into the color & stencil buffer. @@ -156,17 +153,13 @@ void Painter::renderFill(FillBucket& bucket, // below, we have to draw the outline first (!) if (fringeline && pass == RenderPass::Translucent) { config.program = outlineShader->getID(); - outlineShader->u_matrix = vtxMatrix; - config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio! + outlineShader->u_matrix = vertexMatrix; - outlineShader->u_outline_color = fill_color; + outlineShader->u_outline_color = fillColor; outlineShader->u_opacity = opacity; // Draw the entire line - outlineShader->u_world = {{ - static_cast(frame.framebufferSize[0]), - static_cast(frame.framebufferSize[1]) - }}; + outlineShader->u_world = worldSize; setDepthSublayer(2); bucket.drawVertices(*outlineShader, store);