summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2014-04-02 16:09:31 -0700
committerJustin R. Miller <incanus@codesorcery.net>2014-04-02 16:09:31 -0700
commit2eca1c419b638a563f1178bcec49b109d2206b0b (patch)
tree0a07865ac27a3236e2a99f36edfb28c2ed35cc51
parent39c9b6323c304dc59768787dbded466300f6349e (diff)
downloadqtlocation-mapboxgl-2eca1c419b638a563f1178bcec49b109d2206b0b.tar.gz
add support for background opacity in style
-rw-r--r--include/llmr/shader/plain_shader.hpp3
-rw-r--r--include/llmr/style/properties.hpp3
-rw-r--r--src/renderer/painter.cpp6
-rw-r--r--src/shader/plain.fragment.glsl3
-rw-r--r--src/shader/plain_shader.cpp10
-rw-r--r--src/style/style.cpp1
-rw-r--r--src/style/style_parser.cpp4
7 files changed, 25 insertions, 5 deletions
diff --git a/include/llmr/shader/plain_shader.hpp b/include/llmr/shader/plain_shader.hpp
index bf768f8845..d833375eb5 100644
--- a/include/llmr/shader/plain_shader.hpp
+++ b/include/llmr/shader/plain_shader.hpp
@@ -13,12 +13,15 @@ public:
void setColor(float r, float g, float b, float a);
void setColor(const std::array<float, 4>& color);
+ void setOpacity(float opacity);
private:
int32_t a_pos = -1;
std::array<float, 4> color = {{}};
int32_t u_color = -1;
+ float opacity = 0.0f;
+ float u_opacity = 0.0f;
};
}
diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp
index 47b6ff195c..5632011779 100644
--- a/include/llmr/style/properties.hpp
+++ b/include/llmr/style/properties.hpp
@@ -128,11 +128,12 @@ struct TextProperties {
struct BackgroundClass {
Color color = {{ 1, 1, 1, 1 }};
+ FunctionProperty opacity = 1;
};
-
struct BackgroundProperties {
Color color = {{ 1, 1, 1, 1 }};
+ float opacity = 1.0;
};
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index 092f282f98..a04de17334 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -125,9 +125,9 @@ void Painter::prepareClippingMask() {
void Painter::drawClippingMask(const mat4& matrix, uint8_t clip_id, bool opaque) {
plainShader->setMatrix(matrix);
- if (opaque) {
- plainShader->setColor(style.computed.background.color);
- }
+
+ plainShader->setColor(style.computed.background.color);
+ plainShader->setOpacity(style.computed.background.opacity);
glStencilFunc(GL_ALWAYS, clip_id, 0xFF);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index());
diff --git a/src/shader/plain.fragment.glsl b/src/shader/plain.fragment.glsl
index 8df552c171..0761ea5e65 100644
--- a/src/shader/plain.fragment.glsl
+++ b/src/shader/plain.fragment.glsl
@@ -1,5 +1,6 @@
uniform vec4 u_color;
+uniform float u_opacity;
void main() {
- gl_FragColor = u_color;
+ gl_FragColor = u_color * u_opacity;
}
diff --git a/src/shader/plain_shader.cpp b/src/shader/plain_shader.cpp
index ac4b7edeb0..2b367dc501 100644
--- a/src/shader/plain_shader.cpp
+++ b/src/shader/plain_shader.cpp
@@ -20,11 +20,13 @@ PlainShader::PlainShader()
u_matrix = glGetUniformLocation(program, "u_matrix");
u_color = glGetUniformLocation(program, "u_color");
+ u_opacity = glGetUniformLocation(program, "u_opacity");
// fprintf(stderr, "PlainShader:\n");
// fprintf(stderr, " - a_pos: %d\n", a_pos);
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
// fprintf(stderr, " - u_color: %d\n", u_color);
+ // fprintf(stderr, " - u_opacity: %f\n", u_opacity);
}
void PlainShader::bind(char *offset) {
@@ -42,3 +44,11 @@ void PlainShader::setColor(const std::array<float, 4>& new_color) {
void PlainShader::setColor(float r, float g, float b, float a) {
setColor({{ r, g, b, a }});
}
+
+void PlainShader::setOpacity(float new_opacity) {
+ if (opacity != new_opacity) {
+ glUniform1f(u_opacity, new_opacity);
+ fprintf(stderr, "opacity: %f\n", new_opacity);
+ opacity = new_opacity;
+ }
+}
diff --git a/src/style/style.cpp b/src/style/style.cpp
index 7e72623f9f..0a63e9d5b8 100644
--- a/src/style/style.cpp
+++ b/src/style/style.cpp
@@ -94,6 +94,7 @@ void Style::cascade(float z) {
// Cascade background
computed.background.color = sheetClass.background.color;
+ computed.background.opacity = sheetClass.background.opacity.evaluate<float>(z);
}
}
diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp
index 0d2e371720..893e65ea70 100644
--- a/src/style/style_parser.cpp
+++ b/src/style/style_parser.cpp
@@ -509,6 +509,10 @@ BackgroundClass StyleParser::parseBackgroundClass(JSVal value) {
klass.color = parseColor(value["color"]);
}
+ if (value.HasMember("opacity")) {
+ klass.opacity = parseFunction(value["opacity"]);
+ }
+
return klass;
}