[core] Make extrudeScale calculations more similar to JS

This commit is contained in:
John Firebaugh
2016-07-05 12:26:50 -07:00
parent 2e10c0a866
commit c8e87128b1
4 changed files with 28 additions and 20 deletions

View File

@@ -114,10 +114,10 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
// Update the default matrices to the current viewport dimensions.
state.getProjMatrix(projMatrix);
// The extrusion scale.
const float flippedY = state.getViewportMode() == ViewportMode::FlippedY;
extrudeScale = {{ 2.0f / state.getWidth() * state.getAltitude(),
(flippedY ? 2.0f : -2.0f) / state.getHeight() * state.getAltitude() }};
pixelsToGLUnits = {{ 2.0f / state.getWidth(), -2.0f / state.getHeight() }};
if (state.getViewportMode() == ViewportMode::FlippedY) {
pixelsToGLUnits[1] *= -1;
}
// The native matrix is a 1:1 matrix that paints the coordinates at the
// same screen position as the vertex specifies.

View File

@@ -159,7 +159,7 @@ private:
mat4 projMatrix;
mat4 nativeMatrix;
std::array<float, 2> extrudeScale;
std::array<float, 2> pixelsToGLUnits;
// used to composite images and flips the geometry upside down
const mat4 flipMatrix = []{

View File

@@ -32,7 +32,10 @@ void Painter::renderCircle(CircleBucket& bucket,
config.program = circleShader.getID();
circleShader.u_matrix = vtxMatrix;
circleShader.u_extrude_scale = extrudeScale;
circleShader->u_extrude_scale = {{
pixelsToGLUnits[0] * state.getAltitude(),
pixelsToGLUnits[1] * state.getAltitude()
}};
circleShader.u_devicepixelratio = frame.pixelRatio;
circleShader.u_color = properties.circleColor;
circleShader.u_radius = properties.circleRadius;

View File

@@ -44,23 +44,26 @@ void Painter::renderSDF(SymbolBucket &bucket,
float fontSize = paintSize;
float fontScale = fontSize / sdfFontSize;
float scale = fontScale;
std::array<float, 2> exScale = extrudeScale;
bool rotateWithMap = rotationAlignment == AlignmentType::Map;
bool pitchWithMap = pitchAlignment == AlignmentType::Map;
float gammaScale = 1.0f;
std::array<float, 2> extrudeScale;
float gammaScale;
if (pitchWithMap) {
scale *= tileID.pixelsToTileUnits(1, state.getZoom());
exScale.fill(scale);
gammaScale /= std::cos(state.getPitch());
gammaScale = 1.0 / std::cos(state.getPitch());
extrudeScale.fill(tileID.pixelsToTileUnits(1, state.getZoom()) * fontScale);
} else {
exScale = {{ exScale[0] * scale, exScale[1] * scale }};
gammaScale = 1.0;
extrudeScale = {{
pixelsToGLUnits[0] * fontScale * state.getAltitude(),
pixelsToGLUnits[1] * fontScale * state.getAltitude()
}};
}
config.program = sdfShader.getID();
sdfShader.u_matrix = vtxMatrix;
sdfShader.u_extrude_scale = exScale;
sdfShader.u_extrude_scale = extrudeScale;
sdfShader.u_texsize = texsize;
sdfShader.u_rotate_with_map = rotateWithMap;
sdfShader.u_pitch_with_map = pitchWithMap;
@@ -189,14 +192,16 @@ void Painter::renderSymbol(SymbolBucket& bucket,
mat4 vtxMatrix =
translatedMatrix(matrix, paint.iconTranslate, tileID, paint.iconTranslateAnchor);
float scale = fontScale;
std::array<float, 2> exScale = extrudeScale;
std::array<float, 2> extrudeScale;
const bool alignedWithMap = layout.iconRotationAlignment == AlignmentType::Map;
if (alignedWithMap) {
scale *= tileID.pixelsToTileUnits(1, state.getZoom());
exScale.fill(scale);
extrudeScale.fill(tileID.pixelsToTileUnits(1, state.getZoom()) * fontScale);
} else {
exScale = {{ exScale[0] * scale, exScale[1] * scale }};
extrudeScale = {{
pixelsToGLUnits[0] * fontScale * state.getAltitude(),
pixelsToGLUnits[1] * fontScale * state.getAltitude()
}};
}
const bool overdraw = isOverdraw();
@@ -204,7 +209,7 @@ void Painter::renderSymbol(SymbolBucket& bucket,
config.program = iconShader.getID();
iconShader.u_matrix = vtxMatrix;
iconShader.u_extrude_scale = exScale;
iconShader.u_extrude_scale = extrudeScale;
iconShader.u_texsize = {{ float(activeSpriteAtlas->getWidth()) / 4.0f, float(activeSpriteAtlas->getHeight()) / 4.0f }};
iconShader.u_rotate_with_map = alignedWithMap;
iconShader.u_texture = 0;