diff options
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/paint_property_binder.hpp | 60 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_background.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_circle.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_clipping.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill_extrusion.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_line.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_symbol.cpp | 2 |
10 files changed, 55 insertions, 29 deletions
diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index a4bea24bbf..062b77888e 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -6,6 +6,8 @@ #include <mbgl/util/type_list.hpp> #include <mbgl/renderer/paint_property_statistics.hpp> +#include <bitset> + namespace mbgl { /* @@ -54,8 +56,7 @@ std::array<float, N*2> zoomInterpolatedAttributeValue(const std::array<float, N> * For _constant_ properties -- those whose value is a constant, or the constant result of evaluating a camera function at a particular camera position -- we - don't need a vertex buffer, and can instead use a constant attribute binding - via the `glVertexAttrib*` family of functions. + don't need a vertex buffer, and instead use a uniform. * For source functions, we use a vertex buffer with a single attribute value, the evaluated result of the source function for the given feature. * For composite functions, we use a vertex buffer with two attributes: min and @@ -66,15 +67,8 @@ std::array<float, N*2> zoomInterpolatedAttributeValue(const std::array<float, N> between the min and max value at the final displayed zoom level. The use of a uniform allows us to cheaply update the value on every frame. - Note that the shader source is the same regardless of the strategy used to bind - the attribute -- in all cases the attribute is declared as a vec2, in order to - support composite min and max values (color attributes use a vec4 with special - packing). When the constant or source function strategies are used, the - interpolation uniform value is set to zero, and the second attribute element is - unused. This differs from the GL JS implementation, which dynamically generates - shader source based on the strategy used. We found that in WebGL, using - `glVertexAttrib*` was unnacceptably slow. Additionally, in GL Native we have - implemented binary shader caching, which works better if the shaders are constant. + Note that the shader source varies depending on whether we're using a uniform or + attribute. Like GL JS, we dynamically compile shaders at runtime to accomodate this. */ template <class T, class A> class PaintPropertyBinder { @@ -170,9 +164,13 @@ public: return 0.0f; } - T uniformValue(const PossiblyEvaluatedPropertyValue<T>&) const override { - // Uniform values for vertex attribute arrays are unused. - return {}; + T uniformValue(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override { + if (currentValue.isConstant()) { + return *currentValue.constant(); + } else { + // Uniform values for vertex attribute arrays are unused. + return {}; + } } private: @@ -230,9 +228,13 @@ public: return util::interpolationFactor(1.0f, std::get<0>(coveringRanges), currentZoom); } - T uniformValue(const PossiblyEvaluatedPropertyValue<T>&) const override { - // Uniform values for vertex attribute arrays are unused. - return {}; + T uniformValue(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override { + if (currentValue.isConstant()) { + return *currentValue.constant(); + } else { + // Uniform values for vertex attribute arrays are unused. + return {}; + } } private: @@ -342,6 +344,30 @@ public: return binders.template get<P>()->statistics; } + + using Bitset = std::bitset<sizeof...(Ps)>; + + template <class EvaluatedProperties> + static Bitset constants(const EvaluatedProperties& currentProperties) { + Bitset result; + util::ignore({ + result.set(TypeIndex<Ps, Ps...>::value, + currentProperties.template get<Ps>().isConstant())... + }); + return result; + } + + template <class EvaluatedProperties> + static std::vector<std::string> defines(const EvaluatedProperties& currentProperties) { + std::vector<std::string> result; + util::ignore({ + (result.push_back(currentProperties.template get<Ps>().isConstant() + ? std::string("#define HAS_UNIFORM_") + Ps::Uniform::name() + : std::string()), 0)... + }); + return result; + } + private: Binders binders; }; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index eed3bfcd8b..da4903864b 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -93,7 +93,7 @@ static gl::VertexVector<ExtrusionTextureLayoutVertex> extrusionTextureVertices() Painter::Painter(gl::Context& context_, const TransformState& state_, float pixelRatio, - const std::string& programCacheDir) + const optional<std::string>& programCacheDir) : context(context_), state(state_), tileVertexBuffer(context.createVertexBuffer(tileVertices())), diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 47b469d971..4658f0c206 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -74,7 +74,7 @@ struct FrameData { class Painter : private util::noncopyable { public: - Painter(gl::Context&, const TransformState&, float pixelRatio, const std::string& programCacheDir); + Painter(gl::Context&, const TransformState&, float pixelRatio, const optional<std::string>& programCacheDir); ~Painter(); void render(const style::Style&, diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 7cd9cbac5f..d01696ee3e 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -33,7 +33,7 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou spriteAtlas->bind(true, context, 0); for (const auto& tileID : util::tileCover(state, state.getIntegerZoom())) { - parameters.programs.fillPattern.draw( + parameters.programs.fillPattern.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), @@ -58,7 +58,7 @@ void Painter::renderBackground(PaintParameters& parameters, const RenderBackgrou } } else { for (const auto& tileID : util::tileCover(state, state.getIntegerZoom())) { - parameters.programs.fill.draw( + parameters.programs.fill.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 7c9194f6dd..13acb5f7fe 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -23,7 +23,7 @@ void Painter::renderCircle(PaintParameters& parameters, const CirclePaintProperties::Evaluated& properties = layer.evaluated; const bool scaleWithMap = properties.get<CirclePitchScale>() == CirclePitchScaleType::Map; - parameters.programs.circle.draw( + parameters.programs.circle.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp index 0d3b5f1504..b3a2d77b1a 100644 --- a/src/mbgl/renderer/painter_clipping.cpp +++ b/src/mbgl/renderer/painter_clipping.cpp @@ -8,7 +8,7 @@ namespace mbgl { void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& clip) { static const style::FillPaintProperties::Evaluated properties {}; static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); - programs->fill.draw( + programs->fill.get(properties).draw( context, gl::Triangles(), gl::DepthMode::disabled(), diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 622f6386ef..e1b59d8839 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -38,7 +38,7 @@ void Painter::renderFill(PaintParameters& parameters, const auto& drawMode, const auto& indexBuffer, const auto& segments) { - program.draw( + program.get(properties).draw( context, drawMode, depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), @@ -85,7 +85,7 @@ void Painter::renderFill(PaintParameters& parameters, const auto& drawMode, const auto& indexBuffer, const auto& segments) { - program.draw( + program.get(properties).draw( context, drawMode, depthModeForSublayer(sublayer, gl::DepthMode::ReadWrite), diff --git a/src/mbgl/renderer/painter_fill_extrusion.cpp b/src/mbgl/renderer/painter_fill_extrusion.cpp index af98cae569..95617525c7 100644 --- a/src/mbgl/renderer/painter_fill_extrusion.cpp +++ b/src/mbgl/renderer/painter_fill_extrusion.cpp @@ -36,7 +36,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, spriteAtlas->bind(true, context, 0); - parameters.programs.fillExtrusionPattern.draw( + parameters.programs.fillExtrusionPattern.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadWrite), @@ -62,7 +62,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, state.getZoom()); } else { - parameters.programs.fillExtrusion.draw( + parameters.programs.fillExtrusion.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadWrite), diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 4d7a27d0f6..9152ac8512 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -24,7 +24,7 @@ void Painter::renderLine(PaintParameters& parameters, const LinePaintProperties::Evaluated& properties = layer.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { - program.draw( + program.get(properties).draw( context, gl::Triangles(), depthModeForSublayer(0, gl::DepthMode::ReadOnly), diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 5a66d1e62f..86b2146b9f 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -41,7 +41,7 @@ void Painter::renderSymbol(PaintParameters& parameters, // We clip symbols to their tile extent in still mode. const bool needsClipping = frame.mapMode == MapMode::Still; - program.draw( + program.get(paintProperties).draw( context, gl::Triangles(), values_.pitchAlignment == AlignmentType::Map |