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

Commit

Permalink
[core] Update circle shader code
Browse files Browse the repository at this point in the history
Ported the following patches:
 - [convert mat4 exMatrix to a vec2 extrudeScale](mapbox/mapbox-gl-shaders@a8d549b)
 - [Enabled data-driven styling for circle-radius](mapbox/mapbox-gl-shaders@4356e41)
 - [Reduce shader boilerplate, refactor "Bucket"](mapbox/mapbox-gl-shaders@7d3da8f)
  • Loading branch information
brunoabinader committed May 31, 2016
1 parent b94a125 commit 62b4dd5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"aws-sdk": "^2.3.5",
"express": "^4.11.1",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#4a567b438be303fbbf13e5ddf49d72d8debd811d",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#13aad76282c1b6c4d38fd46f373325dfec69ab01",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#b3441d9a285ffbe9b876677acb13d7df07e5b975",
"node-gyp": "^3.3.1",
"request": "^2.72.0",
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ 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() }};

// The native matrix is a 1:1 matrix that paints the coordinates at the
// same screen position as the vertex specifies.
matrix::identity(nativeMatrix);
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class Painter : private util::noncopyable {
mat4 nativeMatrix;
mat4 extrudeMatrix;

std::array<float, 2> extrudeScale;

// used to composite images and flips the geometry upside down
const mat4 flipMatrix = []{
mat4 flip;
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/renderer/painter_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ void Painter::renderCircle(CircleBucket& bucket,
config.program = circleShader->getID();

circleShader->u_matrix = vtxMatrix;
circleShader->u_exmatrix = extrudeMatrix;
circleShader->u_extrude_scale = extrudeScale;
circleShader->u_devicepixelratio = frame.pixelRatio;
circleShader->u_color = properties.circleColor;
circleShader->u_opacity = properties.circleOpacity;
circleShader->u_radius = properties.circleRadius;
circleShader->u_blur = std::max<float>(properties.circleBlur, antialiasing);
circleShader->u_size = properties.circleRadius;
circleShader->u_opacity = properties.circleOpacity;

bucket.drawCircles(*circleShader, glObjectStore);
}
13 changes: 7 additions & 6 deletions src/mbgl/shader/circle_shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class CircleShader : public Shader {

void bind(GLbyte *offset) final;

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<GLfloat> u_size = {"u_size", *this};
Uniform<GLfloat> u_blur = {"u_blur", *this};
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<GLfloat, 2>> u_extrude_scale = {"u_extrude_scale", *this};
Uniform<GLfloat> u_devicepixelratio = {"u_devicepixelratio", *this};
Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this};
Uniform<GLfloat> u_radius = {"u_radius", *this};
Uniform<GLfloat> u_blur = {"u_blur", *this};
Uniform<GLfloat> u_opacity = {"u_opacity", *this};
};

} // namespace mbgl

0 comments on commit 62b4dd5

Please sign in to comment.