Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] fix rendering of dashed lines with round caps #15947

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/mbgl/geometry/line_atlas.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/math/minmax.hpp>
#include <mbgl/util/hash.hpp>
#include <mbgl/util/logging.hpp>
Expand Down Expand Up @@ -107,8 +108,25 @@ DashPatternTexture::DashPatternTexture(const std::vector<float>& from_,
const LinePatternCap cap) {
const bool patternsIdentical = from_ == to_;
const int32_t patternHeight = cap == LinePatternCap::Round ? 15 : 1;

AlphaImage image({256, static_cast<uint32_t>((patternsIdentical ? 1 : 2) * patternHeight)});
const uint32_t height = (patternsIdentical ? 1 : 2) * patternHeight;

// The OpenGL ES 2.0 spec, section 3.8.2 states:
//
// Calling a sampler from a fragment shader will return (R,G,B,A) = (0,0,0,1) if any of the
// following conditions are true:
// […]
// - A two-dimensional sampler is called, the corresponding texture image is a
// non-power-of-two image […], and either the texture wrap mode is not CLAMP_TO_EDGE, or
// the minification filter is neither NEAREST nor LINEAR.
// […]
//
// This means that texture lookups won't work for NPOT textures unless they use GL_CLAMP_TO_EDGE.
// We're using GL_CLAMP_TO_EDGE for the vertical direction, but GL_REPEAT for the horizontal
// direction, which means that we need a power-of-two texture for our line dash patterns to work
// on OpenGL ES 2.0 conforming implementations. Fortunately, this just means changing the height
// from 15 to 16, and from 30 to 32, so we don't waste many pixels.
const uint32_t textureHeight = 1 << util::ceil_log2(height);
AlphaImage image({256, textureHeight});

from = addDashPattern(image, 0, from_, cap);
to = patternsIdentical ? from : addDashPattern(image, patternHeight, to_, cap);
Expand Down