diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 14:49:11 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 14:49:11 +0100 |
commit | 29f0214eea44042193340a04be3444edf86a384b (patch) | |
tree | be12fbd1233a9c1f5cd77592f137923b87f7e356 /src | |
parent | 72d7ca0776f06029206df899e41fdf3f3a1cab46 (diff) | |
download | qtlocation-mapboxgl-29f0214eea44042193340a04be3444edf86a384b.tar.gz |
linear fades
Diffstat (limited to 'src')
-rw-r--r-- | src/renderer/painter.cpp | 8 | ||||
-rw-r--r-- | src/resources/style.cpp | 55 | ||||
-rw-r--r-- | src/style/properties.cpp | 26 | ||||
-rw-r--r-- | src/style/style.cpp | 18 |
4 files changed, 71 insertions, 36 deletions
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 68eca999ae..f3e265c69b 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -349,6 +349,12 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name) { double inset = fmax(-1, offset - width / 2 - 0.5) + 1; double outset = offset + width / 2 + 0.5; + Color color = properties.color; + color[0] *= properties.opacity; + color[1] *= properties.opacity; + color[2] *= properties.opacity; + color[3] *= properties.opacity; + // var imagePos = properties.image && imageSprite.getPosition(properties.image); // var shader; bool imagePos = false; @@ -387,7 +393,7 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name) { // color[3] = Infinity; // glUniform4fv(lineShader->u_color, color); // } else { - glUniform4fv(lineShader->u_color, 1, properties.color.data()); + glUniform4fv(lineShader->u_color, 1, color.data()); // } diff --git a/src/resources/style.cpp b/src/resources/style.cpp index b59643f8cf..8bd1ca1297 100644 --- a/src/resources/style.cpp +++ b/src/resources/style.cpp @@ -39,30 +39,35 @@ const unsigned char resources::style[] = { 116, 121, 112, 101, 50, 9, 10, 7, 65, 108, 99, 111, 104, 111, 108, 18, 12, 10, 4, 112, 97, 114, 107, 18, 4, 112, 97, 114, 107, 18, 12, 10, 4, 119, 111, 111, 100, 18, 4, 119, 111, 111, 100, 18, 14, 10, 5, 119, - 97, 116, 101, 114, 18, 5, 119, 97, 116, 101, 114, 18, 28, 10, 12, 114, - 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, 12, 114, 111, 97, - 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, 28, 10, 12, 114, 111, 97, - 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, 12, 114, 111, 97, 100, 95, - 114, 101, 103, 117, 108, 97, 114, 18, 24, 10, 10, 114, 111, 97, 100, 95, - 108, 97, 114, 103, 101, 18, 10, 114, 111, 97, 100, 95, 108, 97, 114, 103, - 101, 18, 18, 10, 7, 97, 108, 99, 111, 104, 111, 108, 18, 7, 97, 108, - 99, 111, 104, 111, 108, 26, 144, 2, 10, 7, 100, 101, 102, 97, 117, 108, - 116, 18, 21, 10, 4, 112, 97, 114, 107, 34, 8, 8, 2, 18, 4, 0, - 0, 128, 63, 45, 255, 159, 223, 200, 18, 31, 10, 4, 119, 111, 111, 100, - 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 102, 170, 51, 58, - 8, 8, 2, 18, 4, 205, 204, 204, 61, 18, 22, 10, 5, 119, 97, 116, - 101, 114, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 230, 182, - 115, 26, 41, 10, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, - 100, 29, 255, 187, 187, 187, 34, 20, 8, 3, 18, 16, 0, 0, 0, 0, - 0, 0, 128, 63, 0, 0, 240, 65, 0, 0, 128, 63, 26, 65, 10, 12, - 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 29, 255, 153, 153, - 153, 34, 44, 8, 3, 18, 40, 0, 0, 0, 0, 0, 0, 0, 63, 0, - 0, 80, 65, 0, 0, 0, 63, 0, 0, 128, 65, 0, 0, 0, 64, 0, - 0, 160, 65, 0, 0, 0, 66, 0, 0, 240, 65, 0, 0, 0, 66, 26, - 71, 10, 10, 114, 111, 97, 100, 95, 108, 97, 114, 103, 101, 29, 255, 102, - 102, 102, 34, 52, 8, 3, 18, 48, 0, 0, 0, 0, 0, 0, 0, 63, - 0, 0, 48, 65, 0, 0, 0, 63, 0, 0, 80, 65, 0, 0, 128, 63, - 0, 0, 128, 65, 0, 0, 128, 64, 0, 0, 160, 65, 0, 0, 128, 66, - 0, 0, 240, 65, 0, 0, 128, 66 + 97, 116, 101, 114, 18, 5, 119, 97, 116, 101, 114, 18, 20, 10, 8, 98, + 117, 105, 108, 100, 105, 110, 103, 18, 8, 98, 117, 105, 108, 100, 105, 110, + 103, 18, 28, 10, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, + 100, 18, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, + 28, 10, 12, 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, + 12, 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, 24, 10, + 10, 114, 111, 97, 100, 95, 108, 97, 114, 103, 101, 18, 10, 114, 111, 97, + 100, 95, 108, 97, 114, 103, 101, 18, 18, 10, 7, 97, 108, 99, 111, 104, + 111, 108, 18, 7, 97, 108, 99, 111, 104, 111, 108, 26, 197, 2, 10, 7, + 100, 101, 102, 97, 117, 108, 116, 18, 21, 10, 4, 112, 97, 114, 107, 34, + 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 159, 223, 200, 18, 31, + 10, 4, 119, 111, 111, 100, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, + 45, 255, 102, 170, 51, 58, 8, 8, 2, 18, 4, 205, 204, 204, 61, 18, + 22, 10, 5, 119, 97, 116, 101, 114, 34, 8, 8, 2, 18, 4, 0, 0, + 128, 63, 45, 255, 230, 182, 115, 18, 51, 10, 8, 98, 117, 105, 108, 100, + 105, 110, 103, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 0, + 0, 0, 58, 24, 8, 4, 18, 20, 0, 0, 80, 65, 0, 0, 0, 0, + 205, 204, 204, 61, 0, 0, 0, 0, 205, 204, 204, 61, 26, 41, 10, 12, + 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 29, 255, 187, 187, + 187, 34, 20, 8, 3, 18, 16, 0, 0, 0, 0, 0, 0, 128, 63, 0, + 0, 240, 65, 0, 0, 128, 63, 26, 65, 10, 12, 114, 111, 97, 100, 95, + 114, 101, 103, 117, 108, 97, 114, 29, 255, 153, 153, 153, 34, 44, 8, 3, + 18, 40, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 80, 65, 0, 0, + 0, 63, 0, 0, 128, 65, 0, 0, 0, 64, 0, 0, 160, 65, 0, 0, + 0, 66, 0, 0, 240, 65, 0, 0, 0, 66, 26, 71, 10, 10, 114, 111, + 97, 100, 95, 108, 97, 114, 103, 101, 29, 255, 102, 102, 102, 34, 52, 8, + 3, 18, 48, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 48, 65, 0, + 0, 0, 63, 0, 0, 80, 65, 0, 0, 128, 63, 0, 0, 128, 65, 0, + 0, 128, 64, 0, 0, 160, 65, 0, 0, 128, 66, 0, 0, 240, 65, 0, + 0, 128, 66 }; const unsigned long resources::style_size = sizeof(resources::style); diff --git a/src/style/properties.cpp b/src/style/properties.cpp index 499f0c7276..a0f2a659df 100644 --- a/src/style/properties.cpp +++ b/src/style/properties.cpp @@ -46,10 +46,12 @@ float functions::stops(float z, const std::vector<float>& stops) { } if (smaller && larger) { + if (larger_z == smaller_z || larger_val == smaller_val) return smaller_val; + float factor = (z - smaller_z) / (larger_z - smaller_z); + // Linear interpolation if base is 0 + if (smaller_val == 0) return factor * larger_val; // Exponential interpolation between the values - if (larger_z == smaller_z) return smaller_val; - float val = smaller_val * pow(larger_val / smaller_val, (z - smaller_z) / (larger_z - smaller_z)); - return val; + return smaller_val * pow(larger_val / smaller_val, factor); } else if (larger || smaller) { // Do not draw a line. return -std::numeric_limits<float>::infinity(); @@ -68,3 +70,21 @@ bool functions::stops(float z, const std::vector<bool>& values) { return false; } +float functions::linear(float z, const std::vector<float>& values) { + if (values.size() != 5) { + return 0; + } + + const float z_base = values[0]; + const float val = values[1]; + const float slope = values[2]; + const float min = values[3]; + const float max = values[4]; + + return fmin(fmax(min, val + (z - z_base) * slope), max); +} + +bool functions::linear(float z, const std::vector<bool>&) { + // TODO + return false; +} diff --git a/src/style/style.cpp b/src/style/style.cpp index 3b95fb8792..3f6982feb0 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -144,8 +144,10 @@ std::pair<std::string, LineClass> Style::parseLineClass(pbf data) { stroke.color = parseColor(data); } else if (data.tag == 4) { // width stroke.width = parseProperty<float>(data.message()); - } else if (data.tag == 5) { // opacity + } else if (data.tag == 5) { // offset stroke.offset = parseProperty<float>(data.message()); + } else if (data.tag == 6) { // opacity + stroke.opacity = parseProperty<float>(data.message()); } else { data.skip(); } @@ -158,11 +160,12 @@ std::pair<std::string, LineClass> Style::parseLineClass(pbf data) { Color Style::parseColor(pbf& data) { uint32_t rgba = data.fixed<uint32_t, 4>(); return {{ - (float)((rgba >> 24) & 0xFF) / 0xFF, - (float)((rgba >> 16) & 0xFF) / 0xFF, - (float)((rgba >> 8) & 0xFF) / 0xFF, - (float)((rgba >> 0) & 0xFF) / 0xFF - }}; + (float)((rgba >> 24) & 0xFF) / 0xFF, + (float)((rgba >> 16) & 0xFF) / 0xFF, + (float)((rgba >> 8) & 0xFF) / 0xFF, + (float)((rgba >> 0) & 0xFF) / 0xFF + } + }; } template <typename T> FunctionProperty<T> Style::parseProperty(pbf data) { @@ -170,10 +173,11 @@ template <typename T> FunctionProperty<T> Style::parseProperty(pbf data) { while (data.next()) { if (data.tag == 1) { // function - switch((Property)data.varint()) { + switch ((Property)data.varint()) { case Property::Null: property.function = &functions::null; break; case Property::Constant: property.function = &functions::constant; break; case Property::Stops: property.function = &functions::stops; break; + case Property::Linear: property.function = &functions::linear; break; default: property.function = &functions::null; break; } } else if (data.tag == 2) { // value |