diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 1ef5fee83..eb5f42789 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -46,7 +45,6 @@ class PrerenderedTexture; struct FillProperties; struct RasterProperties; -struct CompositeProperties; class LayerDescription; class RasterTileData; @@ -111,13 +109,11 @@ public: void drawClippingMasks(const std::set> &sources); void drawClippingMask(const mat4& matrix, const ClipID& clip); - void clearFramebuffers(); void resetFramebuffer(); void bindFramebuffer(); void pushFramebuffer(); GLuint popFramebuffer(); void discardFramebuffers(); - void drawComposite(GLuint texture, const CompositeProperties &properties); bool needsAnimation() const; private: @@ -172,7 +168,6 @@ public: std::unique_ptr rasterShader; std::unique_ptr textShader; std::unique_ptr dotShader; - std::unique_ptr compositeShader; std::unique_ptr gaussianShader; // Set up the stencil quad we're using to generate the stencil mask. @@ -193,7 +188,6 @@ public: VertexArrayObject coveringRasterArray; VertexArrayObject coveringGaussianArray; - VertexArrayObject compositeArray; VertexArrayObject matteArray; // Set up the tile boundary lines we're using to draw the tile outlines. diff --git a/include/mbgl/shader/composite_shader.hpp b/include/mbgl/shader/composite_shader.hpp deleted file mode 100644 index c0c1704f3..000000000 --- a/include/mbgl/shader/composite_shader.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_SHADER_COMPOSITE_SHADER -#define MBGL_SHADER_COMPOSITE_SHADER - -#include - -namespace mbgl { - -class CompositeShader : public Shader { -public: - CompositeShader(); - - void bind(char *offset); - - void setImage(int32_t image); - void setOpacity(float opacity); - -private: - int32_t a_pos = -1; - - int32_t image = 0; - int32_t u_image = -1; - - float opacity = 0; - int32_t u_opacity = -1; -}; - -} - -#endif diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp index aee5db038..ec68ea991 100644 --- a/include/mbgl/style/property_key.hpp +++ b/include/mbgl/style/property_key.hpp @@ -51,8 +51,6 @@ enum class PropertyKey { TextTranslateY, TextTranslateAnchor, - CompositeOpacity, - RasterOpacity, RasterHueRotate, RasterBrightness, // for transitions only diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index f12ab430e..742ae63f0 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -76,16 +76,6 @@ struct SymbolProperties { } }; - -struct CompositeProperties { - inline CompositeProperties() {} - float opacity = 1.0f; - - inline bool isVisible() const { - return opacity > 0; - } -}; - struct RasterProperties { inline RasterProperties() {} float opacity = 1.0f; @@ -109,7 +99,6 @@ typedef util::variant< FillProperties, LineProperties, SymbolProperties, - CompositeProperties, RasterProperties, BackgroundProperties, std::false_type diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 55b7685fd..fa21f819a 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -19,7 +19,6 @@ enum class StyleLayerType : uint8_t { Line, Symbol, Raster, - Composite, Background }; @@ -29,7 +28,6 @@ MBGL_DEFINE_ENUM_CLASS(StyleLayerTypeClass, StyleLayerType, { { StyleLayerType::Line, "line" }, { StyleLayerType::Symbol, "symbol" }, { StyleLayerType::Raster, "raster" }, - { StyleLayerType::Composite, "composite" }, { StyleLayerType::Background, "background" }, { StyleLayerType(-1), "unknown" }, }); diff --git a/src/map/map.cpp b/src/map/map.cpp index b974c1532..dfac1ae6c 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -539,10 +539,6 @@ void Map::prepare() { bool dimensionsChanged = oldState.getFramebufferWidth() != state.getFramebufferWidth() || oldState.getFramebufferHeight() != state.getFramebufferHeight(); - if (pixelRatioChanged || dimensionsChanged) { - painter.clearFramebuffers(); - } - animationTime = util::now(); updateSources(); style->updateProperties(state.getNormalizedZoom(), animationTime); @@ -564,8 +560,6 @@ void Map::render() { painter.clear(); - painter.resetFramebuffer(); - painter.resize(); painter.changeMatrix(); @@ -639,33 +633,7 @@ void Map::renderLayers(std::shared_ptr group) { } void Map::renderLayer(std::shared_ptr layer_desc, RenderPass pass, const Tile::ID* id, const mat4* matrix) { - if (layer_desc->layers && layer_desc->type != StyleLayerType::Raster) { - // This is a layer group. We render them during our translucent render pass. - if (pass == RenderPass::Translucent) { - const CompositeProperties &properties = layer_desc->getProperties(); - if (properties.isVisible()) { - gl::group group(std::string("group: ") + layer_desc->id); - - if (debug::renderTree) { - std::cout << std::string(indent++ * 4, ' ') << "+ " << layer_desc->id - << " (Composite) {" << std::endl; - } - - painter.pushFramebuffer(); - - renderLayers(layer_desc->layers); - - GLuint texture = painter.popFramebuffer(); - - // Render the previous texture onto the screen. - painter.drawComposite(texture, properties); - - if (debug::renderTree) { - std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; - } - } - } - } else if (layer_desc->type == StyleLayerType::Background) { + if (layer_desc->type == StyleLayerType::Background) { // This layer defines the background color. } else { // This is a singular layer. diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 5aba3b1b8..e813ad24e 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -45,7 +45,6 @@ void Painter::setup() { assert(rasterShader); assert(textShader); assert(dotShader); - assert(compositeShader); assert(gaussianShader); @@ -76,12 +75,10 @@ void Painter::setupShaders() { if (!rasterShader) rasterShader = std::make_unique(); if (!textShader) textShader = std::make_unique(); if (!dotShader) dotShader = std::make_unique(); - if (!compositeShader) compositeShader = std::make_unique(); if (!gaussianShader) gaussianShader = std::make_unique(); } void Painter::cleanup() { - clearFramebuffers(); } void Painter::resize() { diff --git a/src/renderer/painter_composite.cpp b/src/renderer/painter_composite.cpp deleted file mode 100644 index 42d0ad559..000000000 --- a/src/renderer/painter_composite.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include - -using namespace mbgl; - -void Painter::drawComposite(GLuint texture, const CompositeProperties &properties) { - // We're doing full-screen framebuffer blending, so no need to do stencil testing here. - glDisable(GL_STENCIL_TEST); - - useProgram(compositeShader->program); - compositeShader->setMatrix(nativeMatrix); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texture); - compositeShader->setImage(0); - - // TODO: translate - compositeShader->setOpacity(properties.opacity); - - // Draw the full screen texture. - // TODO: Do more blend effects like multiply + blur - compositeArray.bind(*compositeShader, tileStencilBuffer, BUFFER_OFFSET(0)); - glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()); - - glBindTexture(GL_TEXTURE_2D, 0); - - // Reset back. - glEnable(GL_STENCIL_TEST); -} diff --git a/src/renderer/painter_framebuffers.cpp b/src/renderer/painter_framebuffers.cpp deleted file mode 100644 index f221b884c..000000000 --- a/src/renderer/painter_framebuffers.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace mbgl; - - -void Painter::clearFramebuffers() { - glBindFramebuffer(GL_FRAMEBUFFER, map.view.root_fbo()); - - // Delete any framebuffers that we might have allocated - glDeleteTextures((int)fbos_color.size(), fbos.data()); - fbos_color.clear(); - - if (fbo_depth_stencil != 0) { - glDeleteRenderbuffers(1, &fbo_depth_stencil); - fbo_depth_stencil = 0; - } - - glDeleteFramebuffers((int)fbos.size(), fbos.data()); - fbos.clear(); -} - -void Painter::bindFramebuffer() { - if (fbo_level < 0) { - glBindFramebuffer(GL_FRAMEBUFFER, map.view.root_fbo()); - } else if (fbos.size() > (size_t) fbo_level) { - GLuint fbo = fbos[fbo_level]; - glBindFramebuffer(GL_FRAMEBUFFER, fbo); -#if GL_EXT_discard_framebuffer - const GLenum discards[] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT }; - glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, discards); -#endif - } else { - // TODO: Convert this to textures so we can composite them and use them in blend operations - - GLuint fbo_color; - glGenTextures(1, &fbo_color); - glBindTexture(GL_TEXTURE_2D, fbo_color); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, map.getState().getFramebufferWidth(), map.getState().getFramebufferHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - glBindTexture(GL_TEXTURE_2D, 0); - fbos_color.emplace_back(fbo_color); - - // Use a shared depth/stencil buffer for all framebuffer objects - if (fbo_depth_stencil == 0) { - // Create depth/stencil buffer - glGenRenderbuffers(1, &fbo_depth_stencil); - glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_stencil); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, map.getState().getFramebufferWidth(), map.getState().getFramebufferHeight()); - glBindRenderbuffer(GL_RENDERBUFFER, 0); - } - - // Allocate new framebuffer - GLuint fbo = 0; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - fbos.emplace_back(fbo); - - // Assemble the FBO - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo_color, 0); -#ifdef GL_ES_VERSION_2_0 - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil); -#else - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_depth_stencil); -#endif - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - fprintf(stderr, "Couldn't create framebuffer: "); - switch (status) { - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: fprintf(stderr, "incomplete attachment\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: fprintf(stderr, "incomplete missing attachment\n"); break; -#ifdef GL_ES_VERSION_2_0 - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: fprintf(stderr, "incomplete dimensions\n"); break; -#else - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: fprintf(stderr, "incomplete draw buffer\n"); break; -#endif - case GL_FRAMEBUFFER_UNSUPPORTED: fprintf(stderr, "unsupported\n"); break; - default: fprintf(stderr, "other\n"); break; - } - return; - } - } -} - -void Painter::resetFramebuffer() { - if (fbo_level >= 0) { - fbo_level = -1; - bindFramebuffer(); - } - - fbo_depth_stencil_valid = false; -} - -void Painter::pushFramebuffer() { - fbo_level++; - bindFramebuffer(); - - if (fbo_depth_stencil_valid) { - glClear(GL_COLOR_BUFFER_BIT); - } else { - depthMask(true); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - glColorMask(false, false, false, false); - - drawClippingMasks(map.getActiveSources()); - - glColorMask(true, true, true, true); - fbo_depth_stencil_valid = true; - } -} - -GLuint Painter::popFramebuffer() { - GLuint texture = fbos_color[fbo_level]; - fbo_level--; - bindFramebuffer(); - return texture; -} diff --git a/src/shader/composite.fragment.glsl b/src/shader/composite.fragment.glsl deleted file mode 100644 index d5adc402e..000000000 --- a/src/shader/composite.fragment.glsl +++ /dev/null @@ -1,9 +0,0 @@ -uniform sampler2D u_image; -uniform float u_opacity; - -varying vec2 v_pos; - -void main() { - vec4 color = texture2D(u_image, v_pos); - gl_FragColor = color * u_opacity; -} diff --git a/src/shader/composite.vertex.glsl b/src/shader/composite.vertex.glsl deleted file mode 100644 index d7e8f0a8a..000000000 --- a/src/shader/composite.vertex.glsl +++ /dev/null @@ -1,9 +0,0 @@ -attribute vec2 a_pos; - -uniform mat4 u_matrix; -varying vec2 v_pos; - -void main() { - gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (gl_Position.xy + 1.0) / 2.0; -} diff --git a/src/shader/composite_shader.cpp b/src/shader/composite_shader.cpp deleted file mode 100644 index 9ed0a1b83..000000000 --- a/src/shader/composite_shader.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include - -#include - -using namespace mbgl; - -CompositeShader::CompositeShader() - : Shader( - "composite", - shaders[COMPOSITE_SHADER].vertex, - shaders[COMPOSITE_SHADER].fragment - ) { - if (!valid) { - fprintf(stderr, "invalid composite shader\n"); - return; - } - - a_pos = glGetAttribLocation(program, "a_pos"); - - u_matrix = glGetUniformLocation(program, "u_matrix"); - u_image = glGetUniformLocation(program, "u_image"); - u_opacity = glGetUniformLocation(program, "u_opacity"); - - // fprintf(stderr, "CompositeShader:\n"); - // fprintf(stderr, " - u_matrix: %d\n", u_matrix); - // fprintf(stderr, " - u_image: %d\n", u_image); - // fprintf(stderr, " - u_opacity: %f\n", u_opacity); -} - -void CompositeShader::bind(char *offset) { - glEnableVertexAttribArray(a_pos); - glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset); -} - -void CompositeShader::setImage(int32_t new_image) { - if (image != new_image) { - glUniform1i(u_image, new_image); - image = new_image; - } -} - -void CompositeShader::setOpacity(float new_opacity) { - if (opacity != new_opacity) { - glUniform1f(u_opacity, new_opacity); - opacity = new_opacity; - } -} diff --git a/src/style/property_fallback.cpp b/src/style/property_fallback.cpp index 4028980cb..0f8335dd6 100644 --- a/src/style/property_fallback.cpp +++ b/src/style/property_fallback.cpp @@ -44,8 +44,6 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::TextTranslateY, defaultStyleProperties().text.translate[1] }, { PropertyKey::TextTranslateAnchor, defaultStyleProperties().text.translate_anchor }, - { PropertyKey::CompositeOpacity, defaultStyleProperties().opacity }, - { PropertyKey::RasterOpacity, defaultStyleProperties().opacity }, { PropertyKey::RasterHueRotate, defaultStyleProperties().hue_rotate }, { PropertyKey::RasterBrightnessLow, defaultStyleProperties().brightness[0] }, diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 520c18378..d4e6d19db 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -216,13 +216,6 @@ void StyleLayer::applyStyleProperties(const float z, const tim } -template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { - properties.set(); - CompositeProperties &composite = properties.get(); - applyStyleProperty(PropertyKey::CompositeOpacity, composite.opacity, z, now); -} - template <> void StyleLayer::applyStyleProperties(const float z, const timestamp now) { properties.set(); @@ -255,7 +248,6 @@ void StyleLayer::updateProperties(float z, const timestamp now) { case StyleLayerType::Line: applyStyleProperties(z, now); break; case StyleLayerType::Symbol: applyStyleProperties(z, now); break; case StyleLayerType::Raster: applyStyleProperties(z, now); break; - case StyleLayerType::Composite: applyStyleProperties(z, now); break; case StyleLayerType::Background: applyStyleProperties(z, now); break; default: properties.set(); break; } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 02a783535..0c0636695 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -628,9 +628,6 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { parseOptionalProperty>("text-translate", { Key::TextTranslateX, Key::TextTranslateY }, klass, value); parseOptionalProperty("transition-text-translate", Key::TextTranslate, klass, value); - parseOptionalProperty>("composite-opacity", Key::CompositeOpacity, klass, value); - parseOptionalProperty("transition-composite-opacity", Key::CompositeOpacity, klass, value); - parseOptionalProperty>("raster-opacity", Key::RasterOpacity, klass, value); parseOptionalProperty("transition-raster-opacity", Key::RasterOpacity, klass, value); parseOptionalProperty>("raster-hue-rotate", Key::RasterHueRotate, klass, value); diff --git a/src/style/style_properties.cpp b/src/style/style_properties.cpp index 1b05528d2..29730fb85 100644 --- a/src/style/style_properties.cpp +++ b/src/style/style_properties.cpp @@ -5,7 +5,6 @@ namespace mbgl { template<> const FillProperties &defaultStyleProperties() { static const FillProperties p; return p; } template<> const LineProperties &defaultStyleProperties() { static const LineProperties p; return p; } template<> const SymbolProperties &defaultStyleProperties() { static const SymbolProperties p; return p; } -template<> const CompositeProperties &defaultStyleProperties() { static const CompositeProperties p; return p; } template<> const RasterProperties &defaultStyleProperties() { static const RasterProperties p; return p; } template<> const BackgroundProperties &defaultStyleProperties() { static const BackgroundProperties p; return p; } diff --git a/styles/bright/style.json b/styles/bright/style.json index 4d6dad99c..d132efe98 100644 --- a/styles/bright/style.json +++ b/styles/bright/style.json @@ -11,6 +11,7 @@ "@land": "#f8f4f0", "@water": "#a0c8f0", "@admin": "#446", + "@admin-opacity": 0.5, "@park": "#d8e8c8", "@cemetary": "#e0e4dd", "@hospital": "#fde", @@ -700,6 +701,7 @@ }, "style": { "line-color": "@admin", + "line-opacity": "@admin-opacity", "line-dasharray": [10, 3], "line-width": "@admin_level_3_width" }, @@ -718,6 +720,7 @@ }, "style": { "line-color": "@admin", + "line-opacity": "@admin-opacity", "line-width": "@admin_level_2_width" }, "type": "line" @@ -735,6 +738,7 @@ }, "style": { "line-color": "@admin", + "line-opacity": "@admin-opacity", "line-dasharray": [4, 4], "line-width": "@admin_level_2_width" }, @@ -752,6 +756,7 @@ }, "style": { "line-color": "@water", + "line-opacity": "@admin-opacity", "line-dasharray": [10, 3], "line-width": "@admin_level_3_width" }, @@ -769,6 +774,7 @@ }, "style": { "line-color": "@water", + "line-opacity": "@admin-opacity", "line-width": "@admin_level_2_width" }, "type": "line" @@ -1326,4 +1332,4 @@ }, "type": "symbol" }] -} \ No newline at end of file +} diff --git a/test/enums.cpp b/test/enums.cpp index f909631e3..dce20ca59 100644 --- a/test/enums.cpp +++ b/test/enums.cpp @@ -15,7 +15,6 @@ TEST(Enums, StyleLayerType) { ASSERT_EQ(StyleLayerType::Line, StyleLayerTypeClass("line")); ASSERT_EQ(StyleLayerType::Symbol, StyleLayerTypeClass("symbol")); ASSERT_EQ(StyleLayerType::Raster, StyleLayerTypeClass("raster")); - ASSERT_EQ(StyleLayerType::Composite, StyleLayerTypeClass("composite")); ASSERT_EQ(StyleLayerType::Background, StyleLayerTypeClass("background")); ASSERT_EQ(StyleLayerType::Unknown, StyleLayerTypeClass(StyleLayerType::Unknown)); @@ -23,7 +22,6 @@ TEST(Enums, StyleLayerType) { ASSERT_EQ(StyleLayerType::Line, StyleLayerTypeClass(StyleLayerType::Line)); ASSERT_EQ(StyleLayerType::Symbol, StyleLayerTypeClass(StyleLayerType::Symbol)); ASSERT_EQ(StyleLayerType::Raster, StyleLayerTypeClass(StyleLayerType::Raster)); - ASSERT_EQ(StyleLayerType::Composite, StyleLayerTypeClass(StyleLayerType::Composite)); ASSERT_EQ(StyleLayerType::Background, StyleLayerTypeClass(StyleLayerType::Background)); ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Unknown), StyleLayerTypeClass(StyleLayerType::Unknown)); @@ -31,7 +29,6 @@ TEST(Enums, StyleLayerType) { ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Line), StyleLayerTypeClass(StyleLayerType::Line)); ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Symbol), StyleLayerTypeClass(StyleLayerType::Symbol)); ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Raster), StyleLayerTypeClass(StyleLayerType::Raster)); - ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Composite), StyleLayerTypeClass(StyleLayerType::Composite)); ASSERT_EQ(StyleLayerTypeClass(StyleLayerType::Background), StyleLayerTypeClass(StyleLayerType::Background)); ASSERT_EQ(false, StyleLayerTypeClass("").valid());