diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-06-01 10:50:45 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-06-01 11:18:43 +0300 |
commit | 59f9a9f93c01fc289eefd38f0805dbf3d6ee445b (patch) | |
tree | e3483d71304a74aa3062cb3339c49a392476f686 | |
parent | 5e7736ce87f558e2d57869efef9512bcc3d2d1a5 (diff) | |
download | qtlocation-mapboxgl-59f9a9f93c01fc289eefd38f0805dbf3d6ee445b.tar.gz |
[core] Update sdf 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.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_symbol.cpp | 36 | ||||
-rw-r--r-- | src/mbgl/shader/sdf_shader.hpp | 22 |
5 files changed, 28 insertions, 37 deletions
diff --git a/package.json b/package.json index 8f2a6ec852..7620e1d9d5 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#49022d5b92c067b8659f5700a04f376d75f2950e", + "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#36278b864e60e1dba937a6863064c03d69526854", "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 d8636a9f11..1e1b37ef44 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -97,9 +97,7 @@ 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 matrix. - matrix::ortho(extrudeMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, -1); - + // 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() }}; diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 6b86dfa69d..4401a95d6e 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -156,7 +156,6 @@ private: mat4 projMatrix; mat4 nativeMatrix; - mat4 extrudeMatrix; std::array<float, 2> extrudeScale; diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 6f628b9d16..d19d7bc498 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -36,34 +36,28 @@ void Painter::renderSDF(SymbolBucket &bucket, { mat4 vtxMatrix = translatedMatrix(matrix, translate, tileID, translateAnchor); - bool skewed = rotationAlignment == RotationAlignmentType::Map; - mat4 exMatrix; - float s; - float gammaScale; - - if (skewed) { - matrix::identity(exMatrix); - s = tileID.pixelsToTileUnits(1, state.getZoom()); - gammaScale = 1.0f / std::cos(state.getPitch()); - } else { - exMatrix = extrudeMatrix; - s = state.getAltitude(); - gammaScale = 1.0f; - matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle()); - } - const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY; - matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1); - // If layerStyle.size > bucket.info.fontSize then labels may collide float fontSize = paintSize; float fontScale = fontSize / sdfFontSize; - matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f); + + float scale = fontScale; + std::array<float, 2> exScale = extrudeScale; + bool alignedWithMap = rotationAlignment == RotationAlignmentType::Map; + float gammaScale = 1.0f; + + if (alignedWithMap) { + scale *= tileID.pixelsToTileUnits(1, state.getZoom()); + exScale.fill(scale); + gammaScale /= std::cos(state.getPitch()); + } else { + exScale = {{ exScale[0] * scale, exScale[1] * scale }}; + } config.program = sdfShader.getID(); sdfShader.u_matrix = vtxMatrix; - sdfShader.u_exmatrix = exMatrix; + sdfShader.u_extrude_scale = exScale; sdfShader.u_texsize = texsize; - sdfShader.u_skewed = skewed; + sdfShader.u_skewed = alignedWithMap; sdfShader.u_texture = 0; // adjust min/max zooms for variable font sies diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp index acef4d5755..c98734c0a4 100644 --- a/src/mbgl/shader/sdf_shader.hpp +++ b/src/mbgl/shader/sdf_shader.hpp @@ -9,17 +9,17 @@ class SDFShader : public Shader { public: SDFShader(gl::GLObjectStore&); - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; - Uniform<GLfloat> u_opacity = {"u_opacity", *this}; - Uniform<std::array<GLfloat, 2>> u_texsize = {"u_texsize", *this}; - Uniform<GLfloat> u_buffer = {"u_buffer", *this}; - Uniform<GLfloat> u_gamma = {"u_gamma", *this}; - Uniform<GLfloat> u_zoom = {"u_zoom", *this}; - Uniform<GLint> u_skewed = {"u_skewed", *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<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<GLfloat> u_opacity = {"u_opacity", *this}; + Uniform<std::array<GLfloat, 2>> u_texsize = {"u_texsize", *this}; + Uniform<GLfloat> u_buffer = {"u_buffer", *this}; + Uniform<GLfloat> u_gamma = {"u_gamma", *this}; + Uniform<GLfloat> u_zoom = {"u_zoom", *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; |