summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-24 17:57:08 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-25 21:37:58 -0700
commitc568a8ad77320c869d8e7c23b86426c094aceb6c (patch)
tree24b821b4cd8f374344feaba4d3be51e9cc37d1a8
parentd7a477b16586d830d9b0862f732302c4ae06aca5 (diff)
downloadqtlocation-mapboxgl-c568a8ad77320c869d8e7c23b86426c094aceb6c.tar.gz
[core] Port "separate u_opacity from u_color"
https://github.com/mapbox/mapbox-gl-shaders/commit/0d3412519618a3a1672db9fa21f96f90070cf84c https://github.com/mapbox/mapbox-gl-js/commit/1f5afa7db08a2bdcc492a46e500ff5d020e6f4a2
-rw-r--r--package.json2
-rw-r--r--src/mbgl/renderer/painter_background.cpp17
-rw-r--r--src/mbgl/renderer/painter_circle.cpp9
-rw-r--r--src/mbgl/renderer/painter_fill.cpp18
-rw-r--r--src/mbgl/renderer/painter_line.cpp8
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp18
-rw-r--r--src/mbgl/shader/circle_shader.hpp1
-rw-r--r--src/mbgl/shader/line_shader.hpp1
-rw-r--r--src/mbgl/shader/linesdf_shader.hpp1
-rw-r--r--src/mbgl/shader/outline_shader.hpp1
-rw-r--r--src/mbgl/shader/plain_shader.hpp1
-rw-r--r--src/mbgl/shader/sdf_shader.hpp1
12 files changed, 25 insertions, 53 deletions
diff --git a/package.json b/package.json
index 10b90ee547..a71e2d5ee1 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#0eda4509d2893adb3aaf92ac68301cdc7722e7b1",
+ "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#d3cdb7f427c7f36ad234b45732b9c77c73440dad",
"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_background.cpp b/src/mbgl/renderer/painter_background.cpp
index 5054722e79..9f5e83d38c 100644
--- a/src/mbgl/renderer/painter_background.cpp
+++ b/src/mbgl/renderer/painter_background.cpp
@@ -43,13 +43,10 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
} else {
if (wireframe) {
plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
+ plainShader->u_opacity = 1.0f;
} else {
- Color color = properties.backgroundColor;
- color[0] *= properties.backgroundOpacity;
- color[1] *= properties.backgroundOpacity;
- color[2] *= properties.backgroundOpacity;
- color[3] *= properties.backgroundOpacity;
- plainShader->u_color = color;
+ plainShader->u_color = properties.backgroundColor;
+ plainShader->u_opacity = properties.backgroundOpacity;
}
config.program = plainShader->getID();
@@ -102,18 +99,10 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
patternShader->u_offset_a = std::array<float, 2>{{offsetAx, offsetAy}};
patternShader->u_offset_b = std::array<float, 2>{{offsetBx, offsetBy}};
-
-
} else {
plainShader->u_matrix = vtxMatrix;
- if (wireframe) {
- plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
- } else {
- plainShader->u_color = properties.backgroundColor;
- }
}
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)tileStencilBuffer.index()));
}
-
}
diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp
index 9e15c6a756..d1258d2142 100644
--- a/src/mbgl/renderer/painter_circle.cpp
+++ b/src/mbgl/renderer/painter_circle.cpp
@@ -24,12 +24,6 @@ void Painter::renderCircle(CircleBucket& bucket,
mat4 vtxMatrix = translatedMatrix(matrix, properties.circleTranslate, tileID,
properties.circleTranslateAnchor);
- Color color = properties.circleColor;
- color[0] *= properties.circleOpacity;
- color[1] *= properties.circleOpacity;
- color[2] *= properties.circleOpacity;
- color[3] *= properties.circleOpacity;
-
// Antialiasing factor: this is a minimum blur distance that serves as
// a faux-antialiasing for the circle. since blur is a ratio of the circle's
// size and the intent is to keep the blur at roughly 1px, the two
@@ -40,7 +34,8 @@ void Painter::renderCircle(CircleBucket& bucket,
circleShader->u_matrix = vtxMatrix;
circleShader->u_exmatrix = extrudeMatrix;
- circleShader->u_color = color;
+ circleShader->u_color = properties.circleColor;
+ circleShader->u_opacity = properties.circleOpacity;
circleShader->u_blur = std::max<float>(properties.circleBlur, antialiasing);
circleShader->u_size = properties.circleRadius;
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index 1ac90a2806..ed0b3eec53 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -18,19 +18,11 @@ void Painter::renderFill(FillBucket& bucket,
translatedMatrix(matrix, properties.fillTranslate, tileID, properties.fillTranslateAnchor);
Color fill_color = properties.fillColor;
- fill_color[0] *= properties.fillOpacity;
- fill_color[1] *= properties.fillOpacity;
- fill_color[2] *= properties.fillOpacity;
- fill_color[3] *= properties.fillOpacity;
+ float opacity = properties.fillOpacity;
Color stroke_color = properties.fillOutlineColor;
if (stroke_color[3] < 0) {
stroke_color = fill_color;
- } else {
- stroke_color[0] *= properties.fillOpacity;
- stroke_color[1] *= properties.fillOpacity;
- stroke_color[2] *= properties.fillOpacity;
- stroke_color[3] *= properties.fillOpacity;
}
bool pattern = !properties.fillPattern.value.from.empty();
@@ -41,6 +33,7 @@ void Painter::renderFill(FillBucket& bucket,
if (wireframe) {
fill_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
stroke_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
+ opacity = 1.0f;
pattern = false;
outline = true;
fringeline = true;
@@ -60,6 +53,7 @@ void Painter::renderFill(FillBucket& bucket,
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!
outlineShader->u_color = stroke_color;
+ outlineShader->u_opacity = opacity;
// Draw the entire line
outlineShader->u_world = {{
@@ -164,7 +158,7 @@ void Painter::renderFill(FillBucket& bucket,
}
} else if (!wireframe) {
// No image fill.
- if ((fill_color[3] >= 1.0f) == (pass == RenderPass::Opaque)) {
+ if ((fill_color[3] >= 1.0f && opacity >= 1.0f) == (pass == RenderPass::Opaque)) {
// Only draw the fill when it's either opaque and we're drawing opaque
// fragments or when it's translucent and we're drawing translucent
// fragments
@@ -172,6 +166,7 @@ void Painter::renderFill(FillBucket& bucket,
config.program = plainShader->getID();
plainShader->u_matrix = vtxMatrix;
plainShader->u_color = fill_color;
+ plainShader->u_opacity = opacity;
// Draw the actual triangles into the color & stencil buffer.
setDepthSublayer(1);
@@ -187,7 +182,8 @@ void Painter::renderFill(FillBucket& bucket,
config.lineWidth = 2.0f; // This is always fixed and does not depend on the pixelRatio!
outlineShader->u_color = fill_color;
-
+ outlineShader->u_opacity = opacity;
+
// Draw the entire line
outlineShader->u_world = {{
static_cast<float>(frame.framebufferSize[0]),
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index c0706dcdd7..f1f8403a42 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -49,12 +49,10 @@ void Painter::renderLine(LineBucket& bucket,
float outset = offset + edgeWidth + antialiasing / 2.0 + shift;
Color color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
+ float opacity = 1.0f;
if (!wireframe) {
color = properties.lineColor;
- color[0] *= properties.lineOpacity;
- color[1] *= properties.lineOpacity;
- color[2] *= properties.lineOpacity;
- color[3] *= properties.lineOpacity;
+ opacity = properties.lineOpacity;
}
const float ratio = 1.0 / tileID.pixelsToTileUnits(1.0, state.getZoom());
@@ -85,6 +83,7 @@ void Painter::renderLine(LineBucket& bucket,
linesdfShader->u_ratio = ratio;
linesdfShader->u_blur = blur;
linesdfShader->u_color = color;
+ linesdfShader->u_opacity = opacity;
LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, layout.lineCap == LineCapType::Round, glObjectStore);
LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, layout.lineCap == LineCapType::Round, glObjectStore);
@@ -167,6 +166,7 @@ void Painter::renderLine(LineBucket& bucket,
lineShader->u_antialiasingmatrix = antialiasingMatrix;
lineShader->u_color = color;
+ lineShader->u_opacity = opacity;
bucket.drawLines(*lineShader, glObjectStore);
}
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 5e23a835dd..59a543a987 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -87,15 +87,8 @@ void Painter::renderSDF(SymbolBucket &bucket,
// to draw the halo first.
if (haloColor[3] > 0.0f && haloWidth > 0.0f) {
sdfShader.u_gamma = (haloBlur * blurOffset / fontScale / sdfPx + gamma) * gammaScale;
-
- if (opacity < 1.0f) {
- haloColor[0] *= opacity;
- haloColor[1] *= opacity;
- haloColor[2] *= opacity;
- haloColor[3] *= opacity;
- }
-
sdfShader.u_color = haloColor;
+ sdfShader.u_opacity = opacity;
sdfShader.u_buffer = (haloOffset - haloWidth / fontScale) / sdfPx;
setDepthSublayer(0);
@@ -105,15 +98,8 @@ void Painter::renderSDF(SymbolBucket &bucket,
// Then, we draw the text/icon over the halo
if (color[3] > 0.0f) {
sdfShader.u_gamma = gamma * gammaScale;
-
- if (opacity < 1.0f) {
- color[0] *= opacity;
- color[1] *= opacity;
- color[2] *= opacity;
- color[3] *= opacity;
- }
-
sdfShader.u_color = color;
+ sdfShader.u_opacity = opacity;
sdfShader.u_buffer = (256.0f - 64.0f) / 256.0f;
setDepthSublayer(1);
diff --git a/src/mbgl/shader/circle_shader.hpp b/src/mbgl/shader/circle_shader.hpp
index 6e3cbacc62..6cb484aeb2 100644
--- a/src/mbgl/shader/circle_shader.hpp
+++ b/src/mbgl/shader/circle_shader.hpp
@@ -14,6 +14,7 @@ public:
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};
};
diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp
index 54bdee3f31..4a6d86381c 100644
--- a/src/mbgl/shader/line_shader.hpp
+++ b/src/mbgl/shader/line_shader.hpp
@@ -14,6 +14,7 @@ public:
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_linewidth = {"u_linewidth", *this};
Uniform<GLfloat> u_ratio = {"u_ratio", *this};
Uniform<GLfloat> u_blur = {"u_blur", *this};
diff --git a/src/mbgl/shader/linesdf_shader.hpp b/src/mbgl/shader/linesdf_shader.hpp
index ec271f1751..65d8e74b3a 100644
--- a/src/mbgl/shader/linesdf_shader.hpp
+++ b/src/mbgl/shader/linesdf_shader.hpp
@@ -14,6 +14,7 @@ public:
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_linewidth = {"u_linewidth", *this};
Uniform<GLfloat> u_ratio = {"u_ratio", *this};
Uniform<GLfloat> u_blur = {"u_blur", *this};
diff --git a/src/mbgl/shader/outline_shader.hpp b/src/mbgl/shader/outline_shader.hpp
index 8128dbca5b..ba6937bb9f 100644
--- a/src/mbgl/shader/outline_shader.hpp
+++ b/src/mbgl/shader/outline_shader.hpp
@@ -13,6 +13,7 @@ public:
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this};
+ Uniform<GLfloat> u_opacity = {"u_opacity", *this};
Uniform<std::array<GLfloat, 2>> u_world = {"u_world", *this};
};
diff --git a/src/mbgl/shader/plain_shader.hpp b/src/mbgl/shader/plain_shader.hpp
index 5aecde9b49..bb6a81b7eb 100644
--- a/src/mbgl/shader/plain_shader.hpp
+++ b/src/mbgl/shader/plain_shader.hpp
@@ -13,6 +13,7 @@ public:
UniformMatrix<4> u_matrix = {"u_matrix", *this};
Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this};
+ Uniform<GLfloat> u_opacity = {"u_opacity", *this};
};
} // namespace mbgl
diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp
index a33ee5e4d4..acef4d5755 100644
--- a/src/mbgl/shader/sdf_shader.hpp
+++ b/src/mbgl/shader/sdf_shader.hpp
@@ -12,6 +12,7 @@ public:
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};