background-opacity support

This commit is contained in:
John Firebaugh
2014-08-28 10:34:10 -07:00
parent e2c2ab843e
commit 9f734ee61d
7 changed files with 21 additions and 9 deletions

View File

@@ -60,6 +60,7 @@ enum class PropertyKey {
RasterContrast,
RasterFade,
BackgroundOpacity,
BackgroundColor
};

View File

@@ -92,6 +92,7 @@ struct RasterProperties {
struct BackgroundProperties {
inline BackgroundProperties() {}
float opacity = 1.0f;
Color color = {{ 0, 0, 0, 1 }};
};

View File

@@ -626,7 +626,6 @@ void Map::renderLayers(std::shared_ptr<StyleLayerGroup> group) {
void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id, const mat4* matrix) {
if (layer_desc->type == StyleLayerType::Background) {
// This layer defines a background color/image.
if (pass == RenderPass::Translucent) return;
if (debug::renderTree) {
std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " ("

View File

@@ -186,15 +186,23 @@ void Painter::renderTileLayer(const Tile& tile, std::shared_ptr<StyleLayer> laye
void Painter::renderBackground(std::shared_ptr<StyleLayer> layer_desc) {
const BackgroundProperties& properties = layer_desc->getProperties<BackgroundProperties>();
useProgram(plainShader->program);
plainShader->setMatrix(identityMatrix);
plainShader->setColor(properties.color);
backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0));
Color color = properties.color;
color[0] *= properties.opacity;
color[1] *= properties.opacity;
color[2] *= properties.opacity;
color[3] *= properties.opacity;
glDisable(GL_STENCIL_TEST);
depthRange(strata + strata_epsilon, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glEnable(GL_STENCIL_TEST);
if ((color[3] >= 1.0f) == (pass == RenderPass::Opaque)) {
useProgram(plainShader->program);
plainShader->setMatrix(identityMatrix);
plainShader->setColor(color);
backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0));
glDisable(GL_STENCIL_TEST);
depthRange(strata + strata_epsilon, 1.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glEnable(GL_STENCIL_TEST);
}
}
const mat4 &Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor) {

View File

@@ -52,6 +52,7 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::RasterContrast, defaultStyleProperties<RasterProperties>().contrast },
{ PropertyKey::RasterFade, defaultStyleProperties<RasterProperties>().fade },
{ PropertyKey::BackgroundOpacity, defaultStyleProperties<BackgroundProperties>().opacity },
{ PropertyKey::BackgroundColor, defaultStyleProperties<BackgroundProperties>().color },
};

View File

@@ -233,6 +233,7 @@ template <>
void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const timestamp now) {
properties.set<BackgroundProperties>();
BackgroundProperties &background = properties.get<BackgroundProperties>();
applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now);
applyTransitionedStyleProperty(PropertyKey::BackgroundColor, background.color, z, now);
}

View File

@@ -636,6 +636,7 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) {
parseOptionalProperty<Function<float>>("raster-fade-duration", Key::RasterFade, klass, value);
parseOptionalProperty<PropertyTransition>("transition-raster-fade-duration", Key::RasterFade, klass, value);
parseOptionalProperty<Function<float>>("background-opacity", Key::BackgroundOpacity, klass, value);
parseOptionalProperty<Function<Color>>("background-color", Key::BackgroundColor, klass, value);
}