Skip to content

Commit

Permalink
Merge pull request #572 from openmobilemaps/bugfix/dash-caps
Browse files Browse the repository at this point in the history
Fix stairs on iOS
  • Loading branch information
maurhofer-ubique authored Jan 22, 2024
2 parents 4787352 + 000b471 commit 8410049
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,16 @@ std::string ColorLineGroup2dShaderOpenGl::getFragmentShader() {
int iCapType = int(floor(lineValues[int(fStyleIndexBase) + 12] + 0.5));
float lineLength = length(pointBDeltaA);
float t = dot(pointDeltaA, normalize(pointBDeltaA)) / lineLength;

int dashBase = int(fStyleIndexBase) + 13;
// dash values: {int numDashInfo, vec4 dashArray} -> stride = 5
int numDashInfos = int(floor(lineValues[dashBase] + 0.5));

float d;
if (t < 0.0 || t > 1.0) {
if (numDashInfos > 0) {
discard;
}
if (segmentType == 0 || iCapType == 1 || (segmentType == 2 && t < 0.0) || (segmentType == 1 && t > 1.0)) {
d = min(length(pointDeltaA), length(pointDeltaA - pointBDeltaA));
} else if (iCapType == 2) {
Expand All @@ -216,9 +224,6 @@ std::string ColorLineGroup2dShaderOpenGl::getFragmentShader() {
vec4 fragColor = color;
float opacity = lineValues[int(fStyleIndexBase) + 10];

int dashBase = int(fStyleIndexBase) + 13;
// dash values: {int numDashInfo, vec4 dashArray} -> stride = 5
int numDashInfos = int(floor(lineValues[dashBase] + 0.5));
if (numDashInfos > 0) {
int gapColorIndexBase = int(fStyleIndexBase) + 5;
vec4 gapColor = vec4(lineValues[gapColorIndexBase], lineValues[gapColorIndexBase + 1],
Expand Down
7 changes: 5 additions & 2 deletions ios/graphics/Shader/Metal/LineShader.metal
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ lineGroupFragmentShader(LineVertexOut in [[stage_in]],
int capType = int(styling[in.stylingIndex + 12]);
char segmentType = in.segmentType;

float numDash = styling[in.stylingIndex + 13];

float d;

if (t < 0.0 || t > 1.0) {
if (numDash > 0) {
discard_fragment();
}
if (segmentType == 0 || capType == 1 || (segmentType == 2 && t < 0.0) || (segmentType == 1 && t > 1.0)) {
d = min(length(in.lineA), length(in.lineA - in.lineB));
} else if (capType == 2) {
Expand Down Expand Up @@ -176,8 +181,6 @@ lineGroupFragmentShader(LineVertexOut in [[stage_in]],
}
}

float numDash = styling[in.stylingIndex + 13];

if(numDash > 0) {
float dashArray[4] = { styling[in.stylingIndex + 14],
styling[in.stylingIndex + 15],
Expand Down

0 comments on commit 8410049

Please sign in to comment.