diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-05-31 19:59:50 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-06-01 11:18:18 +0300 |
commit | 5e7736ce87f558e2d57869efef9512bcc3d2d1a5 (patch) | |
tree | d10027b3df03af2f048c0926c15b821902a26cc8 | |
parent | 64f4be635bc83d0925018a344404f9f387ba482d (diff) | |
download | qtlocation-mapboxgl-5e7736ce87f558e2d57869efef9512bcc3d2d1a5.tar.gz |
[core] Update icon shader code
Ported the following patch:
- [convert mat4 exMatrix to a vec2 extrudeScale](https://github.com/mapbox/mapbox-gl-shaders/commit/a8d549b7a41540d3a99767975ff1b7b18a6010e9)
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_symbol.cpp | 32 | ||||
-rw-r--r-- | src/mbgl/shader/icon_shader.hpp | 17 |
4 files changed, 21 insertions, 34 deletions
diff --git a/package.json b/package.json index 8eb1b16f7a..8f2a6ec852 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "devDependencies": { "aws-sdk": "^2.3.5", "express": "^4.11.1", - "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#13aad76282c1b6c4d38fd46f373325dfec69ab01", + "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#49022d5b92c067b8659f5700a04f376d75f2950e", "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#b3441d9a285ffbe9b876677acb13d7df07e5b975", "node-gyp": "^3.3.1", "request": "^2.72.0", diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 0f7d894e02..d8636a9f11 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -100,7 +100,9 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a // The extrusion matrix. matrix::ortho(extrudeMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, -1); - extrudeScale = {{ (2.0f / state.getWidth()) * state.getAltitude(), -2.0f / state.getHeight() * state.getAltitude() }}; + const float flippedY = state.getViewportMode() == ViewportMode::FlippedY; + extrudeScale = {{ 2.0f / state.getWidth() * state.getAltitude(), + (flippedY ? 2.0f : -2.0f) / state.getHeight() * state.getAltitude() }}; // The native matrix is a 1:1 matrix that paints the coordinates at the // same screen position as the vertex specifies. diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 59a543a987..6f628b9d16 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -183,35 +183,21 @@ void Painter::renderSymbol(SymbolBucket& bucket, mat4 vtxMatrix = translatedMatrix(matrix, paint.iconTranslate, tileID, paint.iconTranslateAnchor); - bool skewed = layout.iconRotationAlignment == RotationAlignmentType::Map; - mat4 exMatrix; - float s; - - if (skewed) { - matrix::identity(exMatrix); - s = tileID.pixelsToTileUnits(1, state.getZoom()); + float scale = fontScale; + std::array<float, 2> exScale = extrudeScale; + const bool alignedWithMap = layout.iconRotationAlignment == RotationAlignmentType::Map; + if (alignedWithMap) { + scale *= tileID.pixelsToTileUnits(1, state.getZoom()); + exScale.fill(scale); } else { - exMatrix = extrudeMatrix; - matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle()); - s = state.getAltitude(); + exScale = {{ exScale[0] * scale, exScale[1] * scale }}; } - const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY; - matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1); - - matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f); - - // calculate how much longer the real world distance is at the top of the screen - // than at the middle of the screen. - float topedgelength = std::sqrt(std::pow(state.getHeight(), 2) / 4.0f * (1.0f + std::pow(state.getAltitude(), 2))); - float x = state.getHeight() / 2.0f * std::tan(state.getPitch()); - float extra = (topedgelength + x) / topedgelength - 1; config.program = iconShader->getID(); iconShader->u_matrix = vtxMatrix; - iconShader->u_exmatrix = exMatrix; + iconShader->u_extrude_scale = exScale; iconShader->u_texsize = {{ float(activeSpriteAtlas->getWidth()) / 4.0f, float(activeSpriteAtlas->getHeight()) / 4.0f }}; - iconShader->u_skewed = skewed; - iconShader->u_extra = extra; + iconShader->u_skewed = alignedWithMap; iconShader->u_texture = 0; // adjust min/max zooms for variable font sies diff --git a/src/mbgl/shader/icon_shader.hpp b/src/mbgl/shader/icon_shader.hpp index 6e52f48aab..3388720da9 100644 --- a/src/mbgl/shader/icon_shader.hpp +++ b/src/mbgl/shader/icon_shader.hpp @@ -11,15 +11,14 @@ public: void bind(GLbyte *offset) final; - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<GLfloat> u_zoom = {"u_zoom", *this}; - Uniform<GLfloat> u_opacity = {"u_opacity", *this}; - Uniform<std::array<GLfloat, 2>> u_texsize = {"u_texsize", *this}; - Uniform<GLint> u_skewed = {"u_skewed", *this}; - Uniform<GLfloat> u_extra = {"u_extra", *this}; - Uniform<GLint> u_texture = {"u_texture", *this}; - Uniform<GLint> u_fadetexture = {"u_fadetexture", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<GLfloat, 2>> u_extrude_scale = {"u_extrude_scale", *this}; + Uniform<GLfloat> u_zoom = {"u_zoom", *this}; + Uniform<GLfloat> u_opacity = {"u_opacity", *this}; + Uniform<std::array<GLfloat, 2>> u_texsize = {"u_texsize", *this}; + Uniform<GLint> u_skewed = {"u_skewed", *this}; + Uniform<GLint> u_texture = {"u_texture", *this}; + Uniform<GLint> u_fadetexture = {"u_fadetexture", *this}; protected: GLint a_offset = -1; |