From caee9cc12f20d65b32b351ac620084333fffb08a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 16:50:53 +0000 Subject: [PATCH] Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/gfx/drawable.hpp | 10 +- include/mbgl/gfx/drawable_builder.hpp | 5 +- include/mbgl/gfx/gfx_types.hpp | 1 - include/mbgl/gfx/shader.hpp | 4 +- include/mbgl/gfx/vertex_attribute.hpp | 47 +++-- include/mbgl/gl/drawable_gl.hpp | 17 +- include/mbgl/gl/drawable_gl_builder.hpp | 10 +- include/mbgl/gl/drawable_gl_tweaker.hpp | 2 +- include/mbgl/gl/vertex_attribute_gl.hpp | 34 ++-- include/mbgl/renderer/change_request.hpp | 37 ++-- include/mbgl/renderer/renderer_frontend.hpp | 2 +- include/mbgl/shaders/gl/shader_program_gl.hpp | 13 +- .../mbgl/shaders/mtl/shader_program_mtl.hpp | 13 +- include/mbgl/shaders/shader_program_base.hpp | 6 +- include/mbgl/util/identity.hpp | 9 +- include/mbgl/util/suppress_copies.hpp | 14 +- src/mbgl/gfx/context.hpp | 8 +- src/mbgl/gfx/drawable.cpp | 11 +- src/mbgl/gfx/drawable_builder.cpp | 21 +-- src/mbgl/gfx/drawable_builder_impl.hpp | 3 +- src/mbgl/gfx/vertex_attribute.cpp | 35 ++-- src/mbgl/gl/context.cpp | 4 +- src/mbgl/gl/drawable_gl.cpp | 14 +- src/mbgl/gl/drawable_gl_builder.cpp | 1 - src/mbgl/gl/drawable_gl_impl.hpp | 21 +-- src/mbgl/gl/drawable_gl_tweaker.cpp | 3 +- src/mbgl/gl/renderer_backend.cpp | 4 +- src/mbgl/gl/upload_pass.cpp | 91 +++++---- src/mbgl/gl/vertex_attribute_gl.cpp | 173 ++++++++++++------ src/mbgl/renderer/change_request.cpp | 2 +- .../layers/render_background_layer.cpp | 2 +- .../layers/render_background_layer.hpp | 6 +- src/mbgl/renderer/render_orchestrator.cpp | 22 +-- src/mbgl/renderer/render_orchestrator.hpp | 8 +- src/mbgl/renderer/renderer_impl.cpp | 22 +-- src/mbgl/shaders/gl/shader_program_gl.cpp | 119 ++++++------ src/mbgl/shaders/mtl/shader_program_mtl.cpp | 6 +- src/mbgl/shaders/shader_program_base.cpp | 1 - src/mbgl/style/layer_impl.hpp | 6 +- .../style/layers/background_layer_impl.cpp | 40 ++-- .../style/layers/background_layer_impl.hpp | 4 +- src/mbgl/util/identity.cpp | 12 +- src/mbgl/util/mat4.hpp | 8 +- 43 files changed, 454 insertions(+), 417 deletions(-) diff --git a/include/mbgl/gfx/drawable.hpp b/include/mbgl/gfx/drawable.hpp index cb0a96c89..7e0f4effd 100644 --- a/include/mbgl/gfx/drawable.hpp +++ b/include/mbgl/gfx/drawable.hpp @@ -35,7 +35,7 @@ public: const util::SimpleIdentity& getId() const { return uniqueID; } /// Draw the drawable - virtual void draw(const PaintParameters &) const = 0; + virtual void draw(const PaintParameters&) const = 0; /// Drawable name is used for debugging and troubleshooting const std::string& getName() const { return name; } @@ -57,7 +57,7 @@ public: DepthMaskType getDepthType() const { return depthType; } void setDepthType(DepthMaskType value) { depthType = value; } - + /// Get the number of vertexes std::size_t getVertexCount() const { return getVertexAttributes().getMaxCount(); } @@ -71,7 +71,9 @@ public: /// Attach a tweaker to be run on this drawable for each frame void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); } template - void addTweakers(TIter beg, TIter end) { tweakers.insert(tweakers.end(), beg, end); } + void addTweakers(TIter beg, TIter end) { + tweakers.insert(tweakers.end(), beg, end); + } /// Get the tweakers attached to this drawable const std::vector& getTweakers() const { return tweakers; } @@ -86,7 +88,7 @@ protected: mat4 matrix; //= matrix::identity4(); std::optional tileID; DrawPriority drawPriority = 0; - DepthMaskType depthType;// = DepthMaskType::ReadOnly; + DepthMaskType depthType; // = DepthMaskType::ReadOnly; std::vector tweakers; }; diff --git a/include/mbgl/gfx/drawable_builder.hpp b/include/mbgl/gfx/drawable_builder.hpp index f0468957b..f0f4e3601 100644 --- a/include/mbgl/gfx/drawable_builder.hpp +++ b/include/mbgl/gfx/drawable_builder.hpp @@ -60,7 +60,10 @@ public: const Color& getColor() const; void setColor(const Color& value); - enum class ColorMode { PerDrawable, PerVertex }; + enum class ColorMode { + PerDrawable, + PerVertex + }; /// Set how the color value is used /// This should not be changed while a build is in progress void setColorMode(ColorMode mode) { colorMode = mode; } diff --git a/include/mbgl/gfx/gfx_types.hpp b/include/mbgl/gfx/gfx_types.hpp index 2f87cf000..b0002c4c6 100644 --- a/include/mbgl/gfx/gfx_types.hpp +++ b/include/mbgl/gfx/gfx_types.hpp @@ -62,4 +62,3 @@ enum class AttributeDataType : uint8_t { } // namespace gfx } // namespace mbgl - diff --git a/include/mbgl/gfx/shader.hpp b/include/mbgl/gfx/shader.hpp index 665b83f52..a88d248bb 100644 --- a/include/mbgl/gfx/shader.hpp +++ b/include/mbgl/gfx/shader.hpp @@ -21,8 +21,8 @@ inline constexpr bool is_shader_v = std::is_base_of_v && /// @brief A shader is used as the base class for all programs across any supported /// backend API. Shaders are registered with a `gfx::ShaderRegistry` instance. class Shader { - public: - virtual ~Shader() noexcept = default; +public: + virtual ~Shader() noexcept = default; /// @brief Get the type name of this shader /// @return Shader type name diff --git a/include/mbgl/gfx/vertex_attribute.hpp b/include/mbgl/gfx/vertex_attribute.hpp index f2338d25e..06c57769a 100644 --- a/include/mbgl/gfx/vertex_attribute.hpp +++ b/include/mbgl/gfx/vertex_attribute.hpp @@ -14,9 +14,9 @@ namespace mbgl { -using mat2 = std::array; -using mat3 = std::array; -using mat4 = std::array; +using mat2 = std::array; +using mat3 = std::array; +using mat4 = std::array; namespace gfx { @@ -27,34 +27,29 @@ public: using float2 = std::array; using float3 = std::array; using float4 = std::array; - using matf2 = std::array; - using matf3 = std::array; - using matf4 = std::array; + using matf2 = std::array; + using matf3 = std::array; + using matf4 = std::array; using int2 = std::array; using int3 = std::array; using int4 = std::array; - using ElementType = std::variant; + using ElementType = std::variant; // Can only be created by VertexAttributeArray implementations protected: - VertexAttribute(int index_, AttributeDataType dataType_, - int size_, std::size_t count_, std::size_t stride_) + VertexAttribute(int index_, AttributeDataType dataType_, int size_, std::size_t count_, std::size_t stride_) : index(index_), size(size_), stride((int)stride_), dataType(dataType_), - items(count_) { - } - VertexAttribute(const VertexAttribute &) = default; + items(count_) {} + VertexAttribute(const VertexAttribute&) = default; VertexAttribute(VertexAttribute&& other) : index(other.index), size(other.size), dataType(other.dataType), - items(std::move(other.items)) { - } + items(std::move(other.items)) {} public: ~VertexAttribute() = default; @@ -77,7 +72,7 @@ public: const ElementType& set(std::size_t i, T value) { if (items.size() < i + 1) { items.resize(std::max(items.size(), i + 1)); - setDirty(); // need to rebuild the raw data next time + setDirty(); // need to rebuild the raw data next time } if (!isDirty()) { if (std::holds_alternative(items[i])) { @@ -135,7 +130,7 @@ public: using AttributeMap = std::unordered_map>; VertexAttributeArray(int initCapacity = 10); - VertexAttributeArray(VertexAttributeArray &&); + VertexAttributeArray(VertexAttributeArray&&); // Would need to use the virtual assignment operator VertexAttributeArray(const VertexAttributeArray&) = delete; virtual ~VertexAttributeArray() = default; @@ -175,7 +170,7 @@ public: // Set a value if the element is present template bool set(const std::string& name, std::size_t i, T value) { - if (auto *item = get(name)) { + if (auto* item = get(name)) { return item->set(i, value); } return false; @@ -183,8 +178,8 @@ public: /// Indicates whether any values have changed bool isDirty() const { - return std::any_of(attrs.begin(), attrs.end(), - [](const auto& kv){ return kv.second && kv.second->isDirty(); }); + return std::any_of( + attrs.begin(), attrs.end(), [](const auto& kv) { return kv.second && kv.second->isDirty(); }); } using ResolveDelegate = std::function; @@ -193,8 +188,8 @@ public: /// Apply to the active program virtual void applyUniforms(const ShaderProgramBase&) = 0; - - VertexAttributeArray& operator=(VertexAttributeArray &&); + + VertexAttributeArray& operator=(VertexAttributeArray&&); VertexAttributeArray& operator=(const VertexAttributeArray&); protected: @@ -208,8 +203,10 @@ protected: } } - virtual std::unique_ptr create(int index, AttributeDataType dataType, - int size, std::size_t count) = 0; + virtual std::unique_ptr create(int index, + AttributeDataType dataType, + int size, + std::size_t count) = 0; virtual std::unique_ptr copy(const VertexAttribute& attr) = 0; protected: diff --git a/include/mbgl/gl/drawable_gl.hpp b/include/mbgl/gl/drawable_gl.hpp index 18da71d51..754f4d200 100644 --- a/include/mbgl/gl/drawable_gl.hpp +++ b/include/mbgl/gl/drawable_gl.hpp @@ -25,11 +25,9 @@ public: DrawableGL(std::string name); ~DrawableGL() override; - void draw(const PaintParameters &) const override; + void draw(const PaintParameters&) const override; - void setIndexData(std::vector indexes, - std::size_t indexOffset = 0, - std::size_t indexLength = 0); + void setIndexData(std::vector indexes, std::size_t indexOffset = 0, std::size_t indexLength = 0); std::vector& getIndexData() const override; const gfx::VertexAttributeArray& getVertexAttributes() const override; @@ -49,18 +47,19 @@ public: static gfx::VertexAttribute::float4 colorAttrValue(const Color& color) { const auto components = color.toArray(); - return { static_cast(components[0]/255.0), - static_cast(components[1]/255.0), - static_cast(components[2]/255.0), - static_cast(components[3]) }; + return {static_cast(components[0] / 255.0), + static_cast(components[1] / 255.0), + static_cast(components[2] / 255.0), + static_cast(components[3])}; } + protected: class Impl; const std::unique_ptr impl; // For testing only. DrawableGL(std::unique_ptr); - + private: }; diff --git a/include/mbgl/gl/drawable_gl_builder.hpp b/include/mbgl/gl/drawable_gl_builder.hpp index 88f375722..1f954e678 100644 --- a/include/mbgl/gl/drawable_gl_builder.hpp +++ b/include/mbgl/gl/drawable_gl_builder.hpp @@ -11,20 +11,20 @@ namespace gl { */ class DrawableGLBuilder final : public gfx::DrawableBuilder { public: - DrawableGLBuilder(std::string name_) : gfx::DrawableBuilder(std::move(name_)) { - } + DrawableGLBuilder(std::string name_) + : gfx::DrawableBuilder(std::move(name_)) {} ~DrawableGLBuilder() override = default; const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; } void setVertexAttributes(const VertexAttributeArrayGL& value) { vertexAttributes = value; } void setVertexAttributes(VertexAttributeArrayGL&& value) { vertexAttributes = std::move(value); } - + protected: gfx::DrawablePtr createDrawable() const override; - + /// Setup the SDK-specific aspects after all the values are present void init() override; - + private: VertexAttributeArrayGL vertexAttributes; }; diff --git a/include/mbgl/gl/drawable_gl_tweaker.hpp b/include/mbgl/gl/drawable_gl_tweaker.hpp index 096b99f3f..c8113b003 100644 --- a/include/mbgl/gl/drawable_gl_tweaker.hpp +++ b/include/mbgl/gl/drawable_gl_tweaker.hpp @@ -5,7 +5,7 @@ namespace mbgl { namespace gfx { - class Drawable; +class Drawable; } namespace gl { diff --git a/include/mbgl/gl/vertex_attribute_gl.hpp b/include/mbgl/gl/vertex_attribute_gl.hpp index 2844c7733..d16f4da70 100644 --- a/include/mbgl/gl/vertex_attribute_gl.hpp +++ b/include/mbgl/gl/vertex_attribute_gl.hpp @@ -14,17 +14,14 @@ class VertexAttributeGL final : public gfx::VertexAttribute { private: friend VertexAttributeArrayGL; VertexAttributeGL(int index_, gfx::AttributeDataType dataType_, int size_, std::size_t count_) - : VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) { - } + : VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) {} VertexAttributeGL(const VertexAttributeGL& other) : VertexAttribute(other), - glType(other.glType) { - } + glType(other.glType) {} VertexAttributeGL(VertexAttributeGL&& other) : VertexAttribute(std::move(other)), - glType(other.glType) { - } - + glType(other.glType) {} + public: platform::GLenum getGLType() const { return glType; } void setGLType(platform::GLenum value); @@ -50,11 +47,13 @@ private: /// Stores a collection of vertex attributes by name class VertexAttributeArrayGL final : public gfx::VertexAttributeArray { public: - VertexAttributeArrayGL(int initCapacity = 10) : VertexAttributeArray(initCapacity) { } - VertexAttributeArrayGL(VertexAttributeArrayGL &&other) : VertexAttributeArray(std::move(other)) { } + VertexAttributeArrayGL(int initCapacity = 10) + : VertexAttributeArray(initCapacity) {} + VertexAttributeArrayGL(VertexAttributeArrayGL&& other) + : VertexAttributeArray(std::move(other)) {} VertexAttributeArrayGL(const VertexAttributeArrayGL&) = delete; - - VertexAttributeArrayGL& operator=(VertexAttributeArrayGL &&other) { + + VertexAttributeArrayGL& operator=(VertexAttributeArrayGL&& other) { VertexAttributeArray::operator=(std::move(other)); return *this; } @@ -62,18 +61,21 @@ public: VertexAttributeArray::operator=(other); return *this; } - + void applyUniforms(const gfx::ShaderProgramBase&) override; private: - std::unique_ptr create(int index, gfx::AttributeDataType dataType, - int size, std::size_t count) override { + std::unique_ptr create(int index, + gfx::AttributeDataType dataType, + int size, + std::size_t count) override { return std::unique_ptr(new VertexAttributeGL(index, dataType, size, count)); } std::unique_ptr copy(const gfx::VertexAttribute& attr) override { - return std::unique_ptr(new VertexAttributeGL(static_cast(attr))); + return std::unique_ptr( + new VertexAttributeGL(static_cast(attr))); } }; -} // namespace gfx +} // namespace gl } // namespace mbgl diff --git a/include/mbgl/renderer/change_request.hpp b/include/mbgl/renderer/change_request.hpp index 6539818ad..3a6699726 100644 --- a/include/mbgl/renderer/change_request.hpp +++ b/include/mbgl/renderer/change_request.hpp @@ -11,10 +11,9 @@ namespace mbgl { class RenderOrchestrator; namespace gfx { - class Drawable; - using DrawablePtr = std::shared_ptr; -} // namespace gfx - +class Drawable; +using DrawablePtr = std::shared_ptr; +} // namespace gfx /** Base class for changes to be made to the scene @@ -40,24 +39,22 @@ using UniqueChangeRequestVec = std::vector; */ class DrawableRefChangeRequest : public ChangeRequest { protected: - DrawableRefChangeRequest(util::SimpleIdentity id) : drawableID(id) { } - DrawableRefChangeRequest(const DrawableRefChangeRequest&) = default; + DrawableRefChangeRequest(util::SimpleIdentity id) + : drawableID(id) {} + DrawableRefChangeRequest(const DrawableRefChangeRequest &) = default; util::SimpleIdentity drawableID; }; - /** Add a new drawable to the scene */ class AddDrawableRequest : public ChangeRequest { public: AddDrawableRequest(gfx::DrawablePtr drawable_) - : drawable(std::move(drawable_)) { - } - AddDrawableRequest(AddDrawableRequest&& other) - : drawable(std::move(other.drawable)) { - } + : drawable(std::move(drawable_)) {} + AddDrawableRequest(AddDrawableRequest &&other) + : drawable(std::move(other.drawable)) {} void execute(RenderOrchestrator &) override; @@ -65,29 +62,27 @@ protected: gfx::DrawablePtr drawable; }; - /** Remove a drawable from the scene */ class RemoveDrawableRequest : public DrawableRefChangeRequest { public: - RemoveDrawableRequest(util::SimpleIdentity id) : DrawableRefChangeRequest(id) { } - RemoveDrawableRequest(const RemoveDrawableRequest&) = default; + RemoveDrawableRequest(util::SimpleIdentity id) + : DrawableRefChangeRequest(id) {} + RemoveDrawableRequest(const RemoveDrawableRequest &) = default; void execute(RenderOrchestrator &) override; }; - /** Change the color of all vertexes */ class ResetColorRequest : public DrawableRefChangeRequest { public: - ResetColorRequest(util::SimpleIdentity id, Color color) : - DrawableRefChangeRequest(id), - newColor(color) - { } - ResetColorRequest(const ResetColorRequest& other) = default; + ResetColorRequest(util::SimpleIdentity id, Color color) + : DrawableRefChangeRequest(id), + newColor(color) {} + ResetColorRequest(const ResetColorRequest &other) = default; void execute(RenderOrchestrator &) override; diff --git a/include/mbgl/renderer/renderer_frontend.hpp b/include/mbgl/renderer/renderer_frontend.hpp index b07822ef4..882927ef4 100644 --- a/include/mbgl/renderer/renderer_frontend.hpp +++ b/include/mbgl/renderer/renderer_frontend.hpp @@ -27,7 +27,7 @@ public: /// Coalescing updates is up to the implementer virtual void update(std::shared_ptr) = 0; - + protected: }; diff --git a/include/mbgl/shaders/gl/shader_program_gl.hpp b/include/mbgl/shaders/gl/shader_program_gl.hpp index d717d69d5..3732bc645 100644 --- a/include/mbgl/shaders/gl/shader_program_gl.hpp +++ b/include/mbgl/shaders/gl/shader_program_gl.hpp @@ -10,20 +10,17 @@ namespace gl { class ShaderProgramGL final : public gfx::ShaderProgramBase { public: ShaderProgramGL(UniqueProgram&& glProgram_); - ShaderProgramGL(UniqueProgram&&, - VertexAttributeArrayGL&& uniforms, - VertexAttributeArrayGL&& attributes); + ShaderProgramGL(UniqueProgram&&, VertexAttributeArrayGL&& uniforms, VertexAttributeArrayGL&& attributes); ShaderProgramGL(ShaderProgramGL&& other); ~ShaderProgramGL() noexcept override = default; static constexpr std::string_view Name{"GenericGLShader"}; const std::string_view typeName() const noexcept override { return Name; } - static std::shared_ptr create( - Context&, - std::string_view name, - std::string_view vertexSource, - std::string_view fragmentSource) noexcept(false); + static std::shared_ptr create(Context&, + std::string_view name, + std::string_view vertexSource, + std::string_view fragmentSource) noexcept(false); const gfx::VertexAttributeArray& getUniforms() const override { return uniforms; } diff --git a/include/mbgl/shaders/mtl/shader_program_mtl.hpp b/include/mbgl/shaders/mtl/shader_program_mtl.hpp index 20eb6e991..28a83100e 100644 --- a/include/mbgl/shaders/mtl/shader_program_mtl.hpp +++ b/include/mbgl/shaders/mtl/shader_program_mtl.hpp @@ -7,17 +7,18 @@ namespace mtl { class ShaderProgramMTL : public gfx::ShaderProgramBase { public: - ShaderProgramMTL() : ShaderProgramBase() { } + ShaderProgramMTL() + : ShaderProgramBase() {} ~ShaderProgramMTL() noexcept override = default; static constexpr std::string_view Name{"GenericMTLShader"}; const std::string_view typeName() const noexcept override { return Name; } - //bool compile(std::string_view vert, std::string_view frag); - // Load compiled Metal functions from the default library in a bundle - //bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName); - // Load compiled Metal functions from a specific library - //bool load(id, std::string_view vertFuncName, std::string_view fragFuncName); + // bool compile(std::string_view vert, std::string_view frag); + // Load compiled Metal functions from the default library in a bundle + // bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName); + // Load compiled Metal functions from a specific library + // bool load(id, std::string_view vertFuncName, std::string_view fragFuncName); protected: }; diff --git a/include/mbgl/shaders/shader_program_base.hpp b/include/mbgl/shaders/shader_program_base.hpp index 0b2564396..ef79f8dce 100644 --- a/include/mbgl/shaders/shader_program_base.hpp +++ b/include/mbgl/shaders/shader_program_base.hpp @@ -11,13 +11,13 @@ namespace gfx { class ShaderProgramBase : public gfx::Shader { protected: - ShaderProgramBase() { } - ShaderProgramBase(ShaderProgramBase&&) { } + ShaderProgramBase() {} + ShaderProgramBase(ShaderProgramBase&&) {} ~ShaderProgramBase() noexcept override = default; template bool set(gfx::VertexAttributeArray& attrs, const std::string& name, std::size_t i, T value) { - auto *item = attrs.get(name); + auto* item = attrs.get(name); if (item && i < item->getCount()) { item->set(i, value); return true; diff --git a/include/mbgl/util/identity.hpp b/include/mbgl/util/identity.hpp index c0e356124..8163a3a97 100644 --- a/include/mbgl/util/identity.hpp +++ b/include/mbgl/util/identity.hpp @@ -12,7 +12,9 @@ namespace util { */ class SimpleIdentity final { private: - constexpr SimpleIdentity(std::int64_t id) : uniqueID(id) { } + constexpr SimpleIdentity(std::int64_t id) + : uniqueID(id) {} + public: SimpleIdentity(); SimpleIdentity(const SimpleIdentity&) = default; @@ -35,7 +37,6 @@ private: std::int64_t uniqueID; }; - /** Base class for objects that inherit an automatically-assigned unique identity */ @@ -46,13 +47,13 @@ protected: virtual ~SimpleIdentifiable() = default; const util::SimpleIdentity& getId() const { return uniqueID; } - + protected: util::SimpleIdentity uniqueID; }; inline std::string toString(const util::SimpleIdentity& ident) { - return "{"+std::to_string(ident.id())+"}"; + return "{" + std::to_string(ident.id()) + "}"; } } // namespace util diff --git a/include/mbgl/util/suppress_copies.hpp b/include/mbgl/util/suppress_copies.hpp index cd4b5c332..a389084e7 100644 --- a/include/mbgl/util/suppress_copies.hpp +++ b/include/mbgl/util/suppress_copies.hpp @@ -5,13 +5,19 @@ namespace util { /// Wrapper that doesn't participate in copying. /// This allows a default-copyable object to have members that aren't copied -template struct SuppressCopies { +template +struct SuppressCopies { SuppressCopies() = default; SuppressCopies(SuppressCopies const&) {} - SuppressCopies(SuppressCopies&& other) : value(std::forward(other.value)) {} - SuppressCopies& operator=(SuppressCopies o) { std::swap(value, o.value); return *this; } + SuppressCopies(SuppressCopies&& other) + : value(std::forward(other.value)) {} + SuppressCopies& operator=(SuppressCopies o) { + std::swap(value, o.value); + return *this; + } operator T&() { return value; } - T& get() { return value; } + T& get() { return value; } + private: T value; }; diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp index b3c5a5e13..d3ba924db 100644 --- a/src/mbgl/gfx/context.hpp +++ b/src/mbgl/gfx/context.hpp @@ -31,7 +31,6 @@ using UniqueDrawableBuilder = std::unique_ptr; using DrawableTweakerPtr = std::shared_ptr; using ShaderProgramBasePtr = std::shared_ptr; - class Context { protected: Context(uint32_t maximumVertexBindingCount_) @@ -96,18 +95,17 @@ public: #endif virtual void clearStencilBuffer(int32_t) = 0; - - + public: /// Activate the shader, vertex attributes, etc., specified by the drawable virtual bool setupDraw(const PaintParameters&, const gfx::Drawable&) = 0; /// Create a new drawable builder virtual UniqueDrawableBuilder createDrawableBuilder(std::string name) = 0; - + /// Create a new drawable tweaker virtual DrawableTweakerPtr createDrawableTweaker() = 0; - + /// Get the generic shader with the specified name virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0; }; diff --git a/src/mbgl/gfx/drawable.cpp b/src/mbgl/gfx/drawable.cpp index 2c1b5043c..266940697 100644 --- a/src/mbgl/gfx/drawable.cpp +++ b/src/mbgl/gfx/drawable.cpp @@ -5,13 +5,10 @@ namespace mbgl { namespace gfx { -Drawable::Drawable(std::string name_) : - name(name_), - matrix(matrix::identity4()), - depthType(DepthMaskType::ReadOnly) -{ -} +Drawable::Drawable(std::string name_) + : name(name_), + matrix(matrix::identity4()), + depthType(DepthMaskType::ReadOnly) {} } // namespace gfx } // namespace mbgl - diff --git a/src/mbgl/gfx/drawable_builder.cpp b/src/mbgl/gfx/drawable_builder.cpp index 9616dcb20..c67798720 100644 --- a/src/mbgl/gfx/drawable_builder.cpp +++ b/src/mbgl/gfx/drawable_builder.cpp @@ -4,10 +4,9 @@ namespace mbgl { namespace gfx { -DrawableBuilder::DrawableBuilder(std::string name_) : - name(std::move(name_)), - impl(std::make_unique()) { -} +DrawableBuilder::DrawableBuilder(std::string name_) + : name(std::move(name_)), + impl(std::make_unique()) {} DrawableBuilder::~DrawableBuilder() = default; @@ -59,17 +58,17 @@ void DrawableBuilder::setDrawPriority(DrawPriority value) { void DrawableBuilder::resetDrawPriority(DrawPriority value) { setDrawPriority(value); - for (auto &drawble : drawables) { + for (auto& drawble : drawables) { drawble->setDrawPriority(value); } } void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) { const auto n = (uint16_t)impl->vertices.elements(); - impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}})); - impl->vertices.emplace_back(Impl::VT({{{ x1, y1 }}})); - impl->vertices.emplace_back(Impl::VT({{{ x2, y2 }}})); - impl->indexes.emplace_back(n, n+1, n+2); + impl->vertices.emplace_back(Impl::VT({{{x0, y0}}})); + impl->vertices.emplace_back(Impl::VT({{{x1, y1}}})); + impl->vertices.emplace_back(Impl::VT({{{x2, y2}}})); + impl->indexes.emplace_back(n, n + 1, n + 2); if (colorMode == ColorMode::PerVertex) { impl->colors.insert(impl->colors.end(), 3, impl->currentColor); } @@ -77,8 +76,8 @@ void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1 void DrawableBuilder::appendTriangle(int16_t x0, int16_t y0) { const auto n = (uint16_t)impl->vertices.elements(); - impl->vertices.emplace_back(Impl::VT({{{ x0, y0 }}})); - impl->indexes.emplace_back(n-2, n-1, n); + impl->vertices.emplace_back(Impl::VT({{{x0, y0}}})); + impl->indexes.emplace_back(n - 2, n - 1, n); if (colorMode == ColorMode::PerVertex) { impl->colors.emplace_back(impl->currentColor); } diff --git a/src/mbgl/gfx/drawable_builder_impl.hpp b/src/mbgl/gfx/drawable_builder_impl.hpp index 6b949e890..47a8c5bb9 100644 --- a/src/mbgl/gfx/drawable_builder_impl.hpp +++ b/src/mbgl/gfx/drawable_builder_impl.hpp @@ -10,7 +10,7 @@ namespace mbgl { namespace gfx { struct DrawableBuilder::Impl { - using VT = gfx::detail::VertexType>; + using VT = gfx::detail::VertexType>; gfx::VertexVector vertices; gfx::IndexVector indexes; SegmentVector> segments; @@ -20,4 +20,3 @@ struct DrawableBuilder::Impl { } // namespace gfx } // namespace mbgl - diff --git a/src/mbgl/gfx/vertex_attribute.cpp b/src/mbgl/gfx/vertex_attribute.cpp index 6abea9def..8e89625bc 100644 --- a/src/mbgl/gfx/vertex_attribute.cpp +++ b/src/mbgl/gfx/vertex_attribute.cpp @@ -8,21 +8,19 @@ namespace mbgl { namespace gfx { VertexAttributeArray::VertexAttributeArray(int initCapacity) - : attrs(initCapacity) { -} + : attrs(initCapacity) {} -VertexAttributeArray::VertexAttributeArray(VertexAttributeArray &&other) - : attrs(std::move(other.attrs)) { -} +VertexAttributeArray::VertexAttributeArray(VertexAttributeArray&& other) + : attrs(std::move(other.attrs)) {} -VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray &&other) { +VertexAttributeArray& VertexAttributeArray::operator=(VertexAttributeArray&& other) { attrs = std::move(other.attrs); return *this; } VertexAttributeArray& VertexAttributeArray::operator=(const VertexAttributeArray& other) { attrs.clear(); - for (const auto &kv : other.attrs) { + for (const auto& kv : other.attrs) { add(kv.first, copy(*kv.second)); } return *this; @@ -33,8 +31,8 @@ VertexAttribute* VertexAttributeArray::get(const std::string& name) const { return (result != attrs.end()) ? result->second.get() : nullptr; } -VertexAttribute* VertexAttributeArray::add(std::string name, int index, - AttributeDataType dataType, int size, std::size_t count) { +VertexAttribute* VertexAttributeArray::add( + std::string name, int index, AttributeDataType dataType, int size, std::size_t count) { const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr())); if (result.second) { result.first->second = create(index, dataType, size, count); @@ -44,15 +42,14 @@ VertexAttribute* VertexAttributeArray::add(std::string name, int index, } } -VertexAttribute* VertexAttributeArray::getOrAdd(std::string name, int index, - AttributeDataType dataType, int size, std::size_t count) { - //attrs.emplace_back(std::make_unique(dataType, count)); +VertexAttribute* VertexAttributeArray::getOrAdd( + std::string name, int index, AttributeDataType dataType, int size, std::size_t count) { + // attrs.emplace_back(std::make_unique(dataType, count)); const auto result = attrs.insert(std::make_pair(std::move(name), std::unique_ptr())); if (result.second) { result.first->second = create(index, dataType, size, count); } else if (result.first->second->getDataType() != dataType || - result.first->second->getSize() != (std::size_t)size || - result.first->second->getCount() != count) { + result.first->second->getSize() != (std::size_t)size || result.first->second->getCount() != count) { return nullptr; } return result.first->second.get(); @@ -65,14 +62,12 @@ std::size_t VertexAttributeArray::getTotalSize() const { } std::size_t VertexAttributeArray::getMaxCount() const { - return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0), - [](const auto acc, const auto& kv) { - return std::max(acc, kv.second->getCount()); - }); + return std::accumulate(attrs.begin(), attrs.end(), std::size_t(0), [](const auto acc, const auto& kv) { + return std::max(acc, kv.second->getCount()); + }); } -void VertexAttributeArray::resolve(const VertexAttributeArray& overrides, - ResolveDelegate delegate) const { +void VertexAttributeArray::resolve(const VertexAttributeArray& overrides, ResolveDelegate delegate) const { for (auto& kv : attrs) { delegate(kv.first, *kv.second, overrides.get(kv.first)); } diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 348a5b019..51cebedf3 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -453,7 +453,7 @@ void Context::setDirtyState() { } bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable& drawable) { - if (const auto &shader = drawable.getShader()) { + if (const auto& shader = drawable.getShader()) { const auto& shaderGL = static_cast(*shader); if (shaderGL.getGLProgramID() != program.getCurrentValue()) { program = shaderGL.getGLProgramID(); @@ -473,7 +473,7 @@ bool Context::setupDraw(const PaintParameters& parameters, const gfx::Drawable& auto& drawableGL = static_cast(drawable); auto& vao = drawableGL.getVertexArray(); if (vao.isValid()) { - bindVertexArray = vao.getID(); // glBindVertexArray + bindVertexArray = vao.getID(); // glBindVertexArray return true; } else { bindVertexArray = value::BindVertexArray::Default; diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index 904fbf6aa..3249a5ae7 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -5,19 +5,17 @@ namespace mbgl { namespace gl { -DrawableGL::DrawableGL(std::string name_) : - Drawable(std::move(name_)), - impl(std::make_unique()) { -} +DrawableGL::DrawableGL(std::string name_) + : Drawable(std::move(name_)), + impl(std::make_unique()) {} DrawableGL::~DrawableGL() { - impl->vertexArray = { { nullptr, false } }; - impl->indexBuffer = { 0, nullptr }; + impl->vertexArray = {{nullptr, false}}; + impl->indexBuffer = {0, nullptr}; impl->attributeBuffer.reset(); } -void DrawableGL::draw(const PaintParameters ¶meters) const -{ +void DrawableGL::draw(const PaintParameters& parameters) const { impl->draw(parameters); } diff --git a/src/mbgl/gl/drawable_gl_builder.cpp b/src/mbgl/gl/drawable_gl_builder.cpp index cba40f83f..b151d91d5 100644 --- a/src/mbgl/gl/drawable_gl_builder.cpp +++ b/src/mbgl/gl/drawable_gl_builder.cpp @@ -50,4 +50,3 @@ void DrawableGLBuilder::init() { } // namespace gl } // namespace mbgl - diff --git a/src/mbgl/gl/drawable_gl_impl.hpp b/src/mbgl/gl/drawable_gl_impl.hpp index a2c1196f7..15b693763 100644 --- a/src/mbgl/gl/drawable_gl_impl.hpp +++ b/src/mbgl/gl/drawable_gl_impl.hpp @@ -22,7 +22,6 @@ namespace gl { using namespace platform; class DrawableGL::Impl final { - public: Impl() = default; ~Impl() = default; @@ -33,19 +32,19 @@ public: } const gfx::Triangles drawMode; - //const gfx::DrawModeType type = gfx::DrawModeType::Triangles; + // const gfx::DrawModeType type = gfx::DrawModeType::Triangles; - //ShaderID shaderId; - //RenderbufferID renderTarget; + // ShaderID shaderId; + // RenderbufferID renderTarget; std::vector textures; - //std::vector vertData; + // std::vector vertData; std::vector indexes; VertexAttributeArrayGL vertexAttributes; - VertexArray vertexArray = { { nullptr, false } }; - gfx::IndexBuffer indexBuffer = { 0, nullptr }; + VertexArray vertexArray = {{nullptr, false}}; + gfx::IndexBuffer indexBuffer = {0, nullptr}; gfx::UniqueVertexBufferResource attributeBuffer; std::size_t indexOffset = 0; @@ -55,10 +54,10 @@ public: gfx::StencilMode stencilMode; gfx::ColorMode colorMode; gfx::CullFaceMode cullFaceMode; - //gfx::UniformValues::UniformList> uniformValues; - //Segment::AttributeList> segment; - //gfx::AttributeBindings::AttributeList> attributeBindings; - //gfx::TextureBindings::TextureList> textureBindings; + // gfx::UniformValues::UniformList> uniformValues; + // Segment::AttributeList> segment; + // gfx::AttributeBindings::AttributeList> attributeBindings; + // gfx::TextureBindings::TextureList> textureBindings; GLfloat pointSize = 0.0f; }; diff --git a/src/mbgl/gl/drawable_gl_tweaker.cpp b/src/mbgl/gl/drawable_gl_tweaker.cpp index c24b01324..94de85c11 100644 --- a/src/mbgl/gl/drawable_gl_tweaker.cpp +++ b/src/mbgl/gl/drawable_gl_tweaker.cpp @@ -5,7 +5,7 @@ namespace mbgl { namespace gl { -void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters &) { +void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters&) { auto& drawGL = (gl::DrawableGL&)drawable; // apply expressions based on current state, update attributes, uniforms, etc. drawGL.getId(); @@ -13,4 +13,3 @@ void DrawableGLTweaker::execute(gfx::Drawable& drawable, const PaintParameters & } // namespace gl } // namespace mbgl - diff --git a/src/mbgl/gl/renderer_backend.cpp b/src/mbgl/gl/renderer_backend.cpp index 2551a40be..49690d006 100644 --- a/src/mbgl/gl/renderer_backend.cpp +++ b/src/mbgl/gl/renderer_backend.cpp @@ -98,7 +98,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) { shader = gl::ShaderProgramGL::create(glContext, shaderName, vert, frag); if (shader) { // Set default values - //shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f }); + // shader->setAttribute("a_color", gfx::VertexAttribute::matf4{ 1.0f, 1.0f, 1.0f, 1.0f }); // Add to the registry if (!shaders.registerShader(shader, shaderName)) { @@ -109,7 +109,7 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders) { Log::Warning(Event::General, "Shader create failed - " + std::string(shaderName)); return; } - } catch (const std::runtime_error& ex) { + } catch (const std::runtime_error& ex) { Log::Warning(Event::General, "Shader create exception - " + std::string(ex.what())); return; } diff --git a/src/mbgl/gl/upload_pass.cpp b/src/mbgl/gl/upload_pass.cpp index be3dca1ec..cf4ef60ce 100644 --- a/src/mbgl/gl/upload_pass.cpp +++ b/src/mbgl/gl/upload_pass.cpp @@ -132,12 +132,11 @@ static void pad(std::vector& vector, std::size_t size, T value) { } gfx::AttributeBindingArray UploadPass::buildAttributeBindings( - const std::size_t vertexCount, - const gfx::VertexAttributeArray& defaults, - const gfx::VertexAttributeArray& overrides, - const gfx::BufferUsageType usage, - /*out*/ std::unique_ptr& outBuffer) { - + const std::size_t vertexCount, + const gfx::VertexAttributeArray& defaults, + const gfx::VertexAttributeArray& overrides, + const gfx::BufferUsageType usage, + /*out*/ std::unique_ptr& outBuffer) { AttributeBindingArray bindings; bindings.resize(defaults.size()); @@ -148,55 +147,55 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( allData.reserve(defaults.getTotalSize() * vertexCount); // For each attribute in the program, with the corresponding default and optional override... - defaults.resolve(overrides, [&](const std::string& name, - const gfx::VertexAttribute& defaultAttr, - const gfx::VertexAttribute* overrideAttr)->void { + defaults.resolve(overrides, + [&](const std::string& name, + const gfx::VertexAttribute& defaultAttr, + const gfx::VertexAttribute* overrideAttr) -> void { + const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr; + const auto& effectiveGL = static_cast(effectiveAttr); + const auto& defaultGL = static_cast(defaultAttr); + const auto stride = defaultAttr.getStride(); + const auto offset = static_cast(allData.size()); - const auto& effectiveAttr = overrideAttr ? *overrideAttr : defaultAttr; - const auto& effectiveGL = static_cast(effectiveAttr); - const auto& defaultGL = static_cast(defaultAttr); - const auto stride = defaultAttr.getStride(); - const auto offset = static_cast(allData.size()); + // Get the raw data for the values in the desired format + const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType()); - // Get the raw data for the values in the desired format - const auto& rawData = effectiveGL.getRaw(defaultGL.getGLType()); + if (rawData.size() == stride * vertexCount) { + // The override provided a value for each vertex, append it as-is + allData.insert(allData.end(), rawData.begin(), rawData.end()); + } else if (rawData.size() == stride) { + // We only have one value, append a copy for each vertex + for (std::size_t i = 0; i < vertexCount; ++i) { + allData.insert(allData.end(), rawData.begin(), rawData.end()); + } + } else { + // something else, the binding is invalid + // TODO: throw? + Log::Warning(Event::General, + "Got " + util::toString(rawData.size()) + " bytes for attribute '" + name + + "' (" + util::toString(defaultGL.getIndex()) + "), expected " + + util::toString(stride) + " or " + util::toString(stride * vertexCount)); + return; + } - if (rawData.size() == stride * vertexCount) { - // The override provided a value for each vertex, append it as-is - allData.insert(allData.end(), rawData.begin(), rawData.end()); - } else if (rawData.size() == stride) { - // We only have one value, append a copy for each vertex - for (std::size_t i = 0; i < vertexCount; ++i) { - allData.insert(allData.end(), rawData.begin(), rawData.end()); - } - } else { - // something else, the binding is invalid - // TODO: throw? - Log::Warning(Event::General, - "Got " + util::toString(rawData.size()) + " bytes for attribute '" + name + - "' (" + util::toString(defaultGL.getIndex()) + "), expected " + - util::toString(stride) + " or " + util::toString(stride * vertexCount)); - return; - } + bindings[defaultGL.getIndex()] = { + /*.attribute = */ {defaultAttr.getDataType(), offset}, + /*.vertexStride = */ static_cast(stride), + /*.vertexBufferResource = */ nullptr, // buffer pointer established later + /*.vertexOffset = */ 0, + }; - bindings[defaultGL.getIndex()] = { - /*.attribute = */ { defaultAttr.getDataType(), offset }, - /*.vertexStride = */ static_cast(stride), - /*.vertexBufferResource = */nullptr, // buffer pointer established later - /*.vertexOffset = */ 0, - }; - - pad(allData, align, padding); - }); + pad(allData, align, padding); + }); auto vertBuf = createVertexBufferResource(allData.data(), allData.size(), usage); // Go back and fill in the newly-allocated buffer in each binding that was generated std::for_each(bindings.begin(), bindings.end(), [&](auto& b) { - if (b) { - b->vertexBufferResource = vertBuf.get(); - } - }); + if (b) { + b->vertexBufferResource = vertBuf.get(); + } + }); outBuffer = std::move(vertBuf); return bindings; diff --git a/src/mbgl/gl/vertex_attribute_gl.cpp b/src/mbgl/gl/vertex_attribute_gl.cpp index e8f7affbc..1a23abcdf 100644 --- a/src/mbgl/gl/vertex_attribute_gl.cpp +++ b/src/mbgl/gl/vertex_attribute_gl.cpp @@ -17,33 +17,55 @@ using namespace platform; int VertexAttributeGL::getSize(GLenum glType) { switch (glType) { - case GL_FLOAT: return 4*1; - case GL_FLOAT_VEC2: return 4*2; - case GL_FLOAT_VEC3: return 4*3; - case GL_FLOAT_VEC4: return 4*4; - case GL_FLOAT_MAT2: return 4*4; - case GL_INT: return 4*1; - case GL_UNSIGNED_INT: return 4*1; - case GL_INT_VEC2: return 4*2; - case GL_INT_VEC3: return 4*3; - case GL_INT_VEC4: return 4*4; - default: return 0; + case GL_FLOAT: + return 4 * 1; + case GL_FLOAT_VEC2: + return 4 * 2; + case GL_FLOAT_VEC3: + return 4 * 3; + case GL_FLOAT_VEC4: + return 4 * 4; + case GL_FLOAT_MAT2: + return 4 * 4; + case GL_INT: + return 4 * 1; + case GL_UNSIGNED_INT: + return 4 * 1; + case GL_INT_VEC2: + return 4 * 2; + case GL_INT_VEC3: + return 4 * 3; + case GL_INT_VEC4: + return 4 * 4; + default: + return 0; } } int VertexAttributeGL::getStride(GLenum glType) { switch (glType) { - case GL_FLOAT: return 4*1; - case GL_FLOAT_VEC2: return 4*2; - case GL_FLOAT_VEC3: return 4*4; - case GL_FLOAT_VEC4: return 4*4; - case GL_FLOAT_MAT2: return 4*4; - case GL_INT: return 4*1; - case GL_UNSIGNED_INT: return 4*1; - case GL_INT_VEC2: return 4*2; - case GL_INT_VEC3: return 4*4; - case GL_INT_VEC4: return 4*4; - default: return 0; + case GL_FLOAT: + return 4 * 1; + case GL_FLOAT_VEC2: + return 4 * 2; + case GL_FLOAT_VEC3: + return 4 * 4; + case GL_FLOAT_VEC4: + return 4 * 4; + case GL_FLOAT_MAT2: + return 4 * 4; + case GL_INT: + return 4 * 1; + case GL_UNSIGNED_INT: + return 4 * 1; + case GL_INT_VEC2: + return 4 * 2; + case GL_INT_VEC3: + return 4 * 4; + case GL_INT_VEC4: + return 4 * 4; + default: + return 0; } } @@ -60,40 +82,56 @@ static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffe // Copy the value into the buffer with a simple cast, returning true if it works. template static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { - return get(element, buffer, [](T x)->R{ return static_cast(x); }); + return get(element, buffer, [](T x) -> R { return static_cast(x); }); } // Copy a particular type from the variant into the specified buffer, returning true if it works. template static bool get(const gfx::VertexAttribute::ElementType& element, uint8_t* buffer) { - return get(element, buffer, [](T x)->T{ return x; }); + return get(element, buffer, [](T x) -> T { return x; }); } -template R cast(T x) { return static_cast(x); } +template +R cast(T x) { + return static_cast(x); +} // Copy the variant value into the buffer, converting the type if necessary and possible bool VertexAttributeGL::get(const gfx::VertexAttribute::ElementType& element, GLenum glType, uint8_t* buffer) { // TODO: do we need to handle unsigned inputs? switch (glType) { - case GL_FLOAT: return gl::get(element, buffer) || - gl::get(element, buffer); - case GL_FLOAT_VEC2: return gl::get(element, buffer) || - gl::get(element, buffer, [](int2 x){ return float2{(float)x[0],(float)x[1]}; }); - case GL_FLOAT_VEC3: return gl::get(element, buffer); + case GL_FLOAT: + return gl::get(element, buffer) || gl::get(element, buffer); + case GL_FLOAT_VEC2: + return gl::get(element, buffer) || gl::get(element, buffer, [](int2 x) { + return float2{(float)x[0], (float)x[1]}; + }); + case GL_FLOAT_VEC3: + return gl::get(element, buffer); case GL_FLOAT_VEC4: - case GL_FLOAT_MAT2: return gl::get(element, buffer); - case GL_INT: return gl::get(element, buffer) || - gl::get (element, buffer); - case GL_UNSIGNED_INT: return gl::get(element, buffer) || - gl::get(element, buffer); - case GL_INT_VEC2: return gl::get(element, buffer) || - gl::get(element, buffer, [](float2 x){ return int2{(std::int32_t)x[0],(std::int32_t)x[1]}; }); - case GL_UNSIGNED_INT_VEC2: return false; // TODO - case GL_INT_VEC3: return gl::get(element, buffer); - case GL_UNSIGNED_INT_VEC3: return false; // TODO - case GL_INT_VEC4: return gl::get(element, buffer); - case GL_UNSIGNED_INT_VEC4: return false; // TODO - default: return false; + case GL_FLOAT_MAT2: + return gl::get(element, buffer); + case GL_INT: + return gl::get(element, buffer) || gl::get(element, buffer); + case GL_UNSIGNED_INT: + return gl::get(element, buffer) || + gl::get(element, buffer); + case GL_INT_VEC2: + return gl::get(element, buffer) || gl::get(element, buffer, [](float2 x) { + return int2{(std::int32_t)x[0], (std::int32_t)x[1]}; + }); + case GL_UNSIGNED_INT_VEC2: + return false; // TODO + case GL_INT_VEC3: + return gl::get(element, buffer); + case GL_UNSIGNED_INT_VEC3: + return false; // TODO + case GL_INT_VEC4: + return gl::get(element, buffer); + case GL_UNSIGNED_INT_VEC4: + return false; // TODO + default: + return false; } } @@ -109,7 +147,7 @@ std::size_t VertexAttributeGL::getStride() const { const std::vector& VertexAttributeGL::getRaw(platform::GLenum type) const { if (dirty || rawType != type) { const auto count = getCount(); - //const auto size_ = getSize(type); + // const auto size_ = getSize(type); const auto stride_ = getStride(type); rawData.resize(stride_ * count); @@ -132,24 +170,38 @@ const std::vector& VertexAttributeGL::getRaw(platform::GLenum type } namespace { - template void applyUniform(GLint, const T&); - template <> void applyUniform(GLint, const std::int32_t&) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::int2&) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::int3&) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::int4&) { } - template <> void applyUniform(GLint, const float& ) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::float2& ) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::float3& ) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::float4& ) { } - template <> void applyUniform(GLint, const gfx::VertexAttribute::matf3& ) { } - template <> void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) { - MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data())); - } +template +void applyUniform(GLint, const T&); +template <> +void applyUniform(GLint, const std::int32_t&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::int2&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::int3&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::int4&) {} +template <> +void applyUniform(GLint, const float&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::float2&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::float3&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::float4&) {} +template <> +void applyUniform(GLint, const gfx::VertexAttribute::matf3&) {} +template <> +void applyUniform(GLint location, const gfx::VertexAttribute::matf4& value) { + MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, value.data())); } +} // namespace struct ApplyUniform { GLint location; - template void operator()(const T& value) { applyUniform(location, value); } + template + void operator()(const T& value) { + applyUniform(location, value); + } }; void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader) { @@ -165,10 +217,9 @@ void VertexAttributeArrayGL::applyUniforms(const gfx::ShaderProgramBase& shader) Log::Warning(Event::General, "Uniform '" + name + "' = " + std::to_string(index)); uniform->setIndex(index); } - std::visit(ApplyUniform { uniform->getIndex() }, uniform->get(0)); + std::visit(ApplyUniform{uniform->getIndex()}, uniform->get(0)); } } -} // namespace gfx +} // namespace gl } // namespace mbgl - diff --git a/src/mbgl/renderer/change_request.cpp b/src/mbgl/renderer/change_request.cpp index da7a4ad55..df67fd8ed 100644 --- a/src/mbgl/renderer/change_request.cpp +++ b/src/mbgl/renderer/change_request.cpp @@ -12,7 +12,7 @@ void RemoveDrawableRequest::execute(RenderOrchestrator &orchestrator) { } void ResetColorRequest::execute(RenderOrchestrator &orchestrator) { - if (auto& drawable = orchestrator.getDrawable(drawableID)) { + if (auto &drawable = orchestrator.getDrawable(drawableID)) { drawable->resetColor(newColor); } } diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index 1ca51e62b..fc5b3f081 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -165,7 +165,7 @@ std::optional RenderBackgroundLayer::getSolidBackground() const { } return std::nullopt; - //return { evaluated.get() * evaluated.get() }; + // return { evaluated.get() * evaluated.get() }; } namespace { diff --git a/src/mbgl/renderer/layers/render_background_layer.hpp b/src/mbgl/renderer/layers/render_background_layer.hpp index e7ad07ac3..896f0c605 100644 --- a/src/mbgl/renderer/layers/render_background_layer.hpp +++ b/src/mbgl/renderer/layers/render_background_layer.hpp @@ -12,9 +12,9 @@ namespace mbgl { namespace gfx { - class Drawable; - using DrawablePtr = std::shared_ptr; -} // namespace gfc +class Drawable; +using DrawablePtr = std::shared_ptr; +} // namespace gfx class ChangeRequest; diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 08b7a72da..40a576f86 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -138,7 +138,6 @@ void RenderOrchestrator::setObserver(RendererObserver* observer_) { std::unique_ptr RenderOrchestrator::createRenderTree( const std::shared_ptr& updateParameters) { - layersAdded.clear(); layersRemoved.clear(); @@ -723,8 +722,8 @@ bool RenderOrchestrator::isLoaded() const { if (!imageManager->isLoaded()) { return false; } - - for (const auto& entry: renderSources) { + + for (const auto& entry : renderSources) { if (!entry.second->isLoaded()) { return false; } @@ -751,9 +750,8 @@ void RenderOrchestrator::clearData() { } void RenderOrchestrator::addChanges(UniqueChangeRequestVec& changes) { - pendingChanges.insert(pendingChanges.end(), - std::make_move_iterator(changes.begin()), - std::make_move_iterator(changes.end())); + pendingChanges.insert( + pendingChanges.end(), std::make_move_iterator(changes.begin()), std::make_move_iterator(changes.end())); changes.clear(); } @@ -780,25 +778,25 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders, gfx::Context& context, const TransformState& state, const std::shared_ptr& updateParameters) { - const bool isMapModeContinuous = updateParameters->mode == MapMode::Continuous; - const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions : style::TransitionOptions(); + const auto transitionOptions = isMapModeContinuous ? updateParameters->transitionOptions + : style::TransitionOptions(); const auto defDuration = isMapModeContinuous ? util::DEFAULT_TRANSITION_DURATION : Duration::zero(); - const PropertyEvaluationParameters evalParameters { + const PropertyEvaluationParameters evalParameters{ getZoomHistory(), updateParameters->timePoint, transitionOptions.duration.value_or(defDuration), }; std::vector> changes; - + for (auto& kv : layersRemoved) { kv.second->layerRemoved(changes); } for (auto& kv : layersAdded) { kv.second->layerAdded(shaders, context, state, evalParameters, changes); } - + for (auto& impl : *layerImpls) { impl->update(context, state, evalParameters, changes); } @@ -808,7 +806,7 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders, void RenderOrchestrator::processChanges() { auto localChanges = std::move(pendingChanges); - for (auto &change : localChanges) { + for (auto& change : localChanges) { change->execute(*this); } } diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index 1301bf45f..b24faf839 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -35,11 +35,11 @@ class CrossTileSymbolIndex; class RenderTree; namespace gfx { - class Drawable; - class ShaderRegistry; +class Drawable; +class ShaderRegistry; - using DrawablePtr = std::shared_ptr; -} // namespace gfx +using DrawablePtr = std::shared_ptr; +} // namespace gfx namespace style { class LayerProperties; diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index b6863a6e1..f3dd1b418 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -104,7 +104,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) { staticData->upload(*uploadPass); renderTree.getLineAtlas().upload(*uploadPass); renderTree.getPatternAtlas().upload(*uploadPass); - + for (const auto& pair : orchestrator.getDrawables()) { auto& drawable = *pair.second; @@ -117,35 +117,30 @@ void Renderer::Impl::render(const RenderTree& renderTree) { auto& shader = drawable.getShader(); // Generate a vertex array object for the drawable state, if necessary - if (shader && (!drawableGL.getVertexArray().isValid() || - drawableGL.getVertexAttributes().isDirty())) { + if (shader && (!drawableGL.getVertexArray().isValid() || drawableGL.getVertexAttributes().isDirty())) { const auto usage = gfx::BufferUsageType::StaticDraw; // Build index buffer const auto& indexData = drawable.getIndexData(); - auto indexBuffer = gfx::IndexBuffer { + auto indexBuffer = gfx::IndexBuffer{ indexData.size(), uploadPass->createIndexBufferResource( - indexData.data(), - indexData.size() * sizeof(indexData[0]), - usage) - }; + indexData.data(), indexData.size() * sizeof(indexData[0]), usage)}; // Apply drawable values to shader defaults const auto& defaults = shader->getVertexAttributes(); const auto& overrides = drawable.getVertexAttributes(); const auto vertexCount = drawable.getVertexCount(); std::unique_ptr vertexBuffer; - auto bindings = uploadPass->buildAttributeBindings(vertexCount, defaults, overrides, usage, vertexBuffer); + auto bindings = uploadPass->buildAttributeBindings( + vertexCount, defaults, overrides, usage, vertexBuffer); auto& glContext = static_cast(context); auto vertexArray = glContext.createVertexArray(); vertexArray.bind(glContext, indexBuffer, bindings); glContext.bindVertexArray = gl::value::BindVertexArray::Default; - drawableGL.setVertexArray(std::move(vertexArray), - std::move(vertexBuffer), - std::move(indexBuffer)); + drawableGL.setVertexArray(std::move(vertexArray), std::move(vertexBuffer), std::move(indexBuffer)); } } } @@ -203,7 +198,7 @@ void Renderer::Impl::render(const RenderTree& renderTree) { parameters.depthRangeSize = 1 - (1 + 2) * parameters.numSublayers * parameters.depthEpsilon; const auto debugGroup(parameters.renderPass->createDebugGroup("drawables")); - for (const auto &pair : orchestrator.getDrawables()) { + for (const auto& pair : orchestrator.getDrawables()) { const auto& drawable = *pair.second; if (!context.setupDraw(parameters, drawable)) { @@ -234,7 +229,6 @@ void Renderer::Impl::render(const RenderTree& renderTree) { // - OPAQUE PASS ------------------------------------------------------------------------------- // Render everything top-to-bottom by using reverse iterators. Render opaque objects first. { - parameters.pass = RenderPass::Opaque; const auto debugGroup(parameters.renderPass->createDebugGroup("opaque")); diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index d534d8467..c5ce04687 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -14,58 +14,72 @@ namespace gl { static gfx::AttributeDataType mapType(platform::GLenum attrType) { using T = gfx::AttributeDataType; switch (attrType) { - case GL_FLOAT: return T::Float; - case GL_FLOAT_VEC2: return T::Float2; - case GL_FLOAT_VEC3: return T::Float3; - case GL_FLOAT_VEC4: return T::Float4; - case GL_FLOAT_MAT2: return T::Float4; // does that work ? + case GL_FLOAT: + return T::Float; + case GL_FLOAT_VEC2: + return T::Float2; + case GL_FLOAT_VEC3: + return T::Float3; + case GL_FLOAT_VEC4: + return T::Float4; + case GL_FLOAT_MAT2: + return T::Float4; // does that work ? case GL_FLOAT_MAT3: - case GL_FLOAT_MAT4: return T::Float4; - case GL_INT: return T::Int; - case GL_INT_VEC2: return T::Int2; - case GL_INT_VEC3: return T::Int3; - case GL_INT_VEC4: return T::Int4; - case GL_UNSIGNED_INT: return T::UInt; + case GL_FLOAT_MAT4: + return T::Float4; + case GL_INT: + return T::Int; + case GL_INT_VEC2: + return T::Int2; + case GL_INT_VEC3: + return T::Int3; + case GL_INT_VEC4: + return T::Int4; + case GL_UNSIGNED_INT: + return T::UInt; // ES3 stuff that isn't defined yet: - //case GL_FLOAT_MAT2x3: - //case GL_FLOAT_MAT2x4: - //case GL_FLOAT_MAT3x2: - //case GL_FLOAT_MAT3x4: - //case GL_FLOAT_MAT4x2: - //case GL_FLOAT_MAT4x3: return T::Invalid; - //case GL_UNSIGNED_INT_VEC2: return T::UInt2; - //case GL_UNSIGNED_INT_VEC3: return T::UInt3; - //case GL_UNSIGNED_INT_VEC4: return T::UInt4; - //case GL_DOUBLE: return T::Float; - //case GL_DOUBLE_VEC2: return T::Float2; - //case GL_DOUBLE_VEC3: return T::Float3; - //case GL_DOUBLE_VEC4: return T::Float4; - //case GL_DOUBLE_MAT2: return T::Float4; - //case GL_DOUBLE_MAT3: - //case GL_DOUBLE_MAT4: - //case GL_DOUBLE_MAT2x3: - //case GL_DOUBLE_MAT2x4: - //case GL_DOUBLE_MAT3x2: - //case GL_DOUBLE_MAT3x4: - //case GL_DOUBLE_MAT4x2: - //case GL_DOUBLE_MAT4x3: - default: return T::Invalid; + // case GL_FLOAT_MAT2x3: + // case GL_FLOAT_MAT2x4: + // case GL_FLOAT_MAT3x2: + // case GL_FLOAT_MAT3x4: + // case GL_FLOAT_MAT4x2: + // case GL_FLOAT_MAT4x3: return T::Invalid; + // case GL_UNSIGNED_INT_VEC2: return T::UInt2; + // case GL_UNSIGNED_INT_VEC3: return T::UInt3; + // case GL_UNSIGNED_INT_VEC4: return T::UInt4; + // case GL_DOUBLE: return T::Float; + // case GL_DOUBLE_VEC2: return T::Float2; + // case GL_DOUBLE_VEC3: return T::Float3; + // case GL_DOUBLE_VEC4: return T::Float4; + // case GL_DOUBLE_MAT2: return T::Float4; + // case GL_DOUBLE_MAT3: + // case GL_DOUBLE_MAT4: + // case GL_DOUBLE_MAT2x3: + // case GL_DOUBLE_MAT2x4: + // case GL_DOUBLE_MAT3x2: + // case GL_DOUBLE_MAT3x4: + // case GL_DOUBLE_MAT4x2: + // case GL_DOUBLE_MAT4x3: + default: + return T::Invalid; } } // No `AttributeDataType` for 4x4, so we have to account for it separately... static int mapCount(const platform::GLenum attrType) { switch (attrType) { - case GL_FLOAT_MAT3: return 3; - case GL_FLOAT_MAT4: return 4; - default: return 1; + case GL_FLOAT_MAT3: + return 3; + case GL_FLOAT_MAT4: + return 4; + default: + return 1; } } ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_) : ShaderProgramBase(), - glProgram(std::move(glProgram_)) { -} + glProgram(std::move(glProgram_)) {} ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program, VertexAttributeArrayGL&& uniforms_, @@ -73,20 +87,18 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program, : ShaderProgramBase(), glProgram(std::move(program)), uniforms(std::move(uniforms_)), - vertexAttributes(std::move(attributes_)) { -} + vertexAttributes(std::move(attributes_)) {} ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other) : ShaderProgramBase(std::forward(other)), glProgram(std::move(other.glProgram)), uniforms(std::move(other.uniforms)), - vertexAttributes(std::move(other.vertexAttributes)) { -} + vertexAttributes(std::move(other.vertexAttributes)) {} using namespace platform; -static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index, - GLsizei length, GLint count, GLenum glType) { +static void addAttr( + VertexAttributeArrayGL& attrs, const char* name, GLint index, GLsizei length, GLint count, GLenum glType) { const auto elementType = mapType(glType); const auto elementCount = mapCount(glType); // number of `elementType`, hopefully temporary if (elementType != gfx::AttributeDataType::Invalid && length > 0) { @@ -97,22 +109,21 @@ static void addAttr(VertexAttributeArrayGL& attrs, const char* name, GLint index } } -std::shared_ptr ShaderProgramGL::create( - Context& context, - std::string_view /*name*/, - std::string_view vertexSource, - std::string_view fragmentSource) noexcept(false) { - +std::shared_ptr ShaderProgramGL::create(Context& context, + std::string_view /*name*/, + std::string_view vertexSource, + std::string_view fragmentSource) noexcept(false) { const auto firstAttrib = "a_pos"; // throws on compile error auto vertProg = context.createShader(ShaderType::Vertex, std::initializer_list{vertexSource.data()}); - auto fragProg = context.createShader(ShaderType::Fragment, std::initializer_list{fragmentSource.data()}); + auto fragProg = context.createShader(ShaderType::Fragment, + std::initializer_list{fragmentSource.data()}); auto program = context.createProgram(vertProg, fragProg, firstAttrib); // GLES3.1 - //GLint numAttribs; - //glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs); + // GLint numAttribs; + // glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs); VertexAttributeArrayGL uniforms; diff --git a/src/mbgl/shaders/mtl/shader_program_mtl.cpp b/src/mbgl/shaders/mtl/shader_program_mtl.cpp index 01ad8c832..164d793d4 100644 --- a/src/mbgl/shaders/mtl/shader_program_mtl.cpp +++ b/src/mbgl/shaders/mtl/shader_program_mtl.cpp @@ -3,9 +3,9 @@ namespace mbgl { namespace mtl { -//bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) { -// return false; -//} +// bool ShaderProgramMTL::compile(std::string_view vert, std::string_view frag) { +// return false; +// } } // namespace mtl } // namespace mbgl diff --git a/src/mbgl/shaders/shader_program_base.cpp b/src/mbgl/shaders/shader_program_base.cpp index ed841b21c..52222f870 100644 --- a/src/mbgl/shaders/shader_program_base.cpp +++ b/src/mbgl/shaders/shader_program_base.cpp @@ -1,4 +1,3 @@ #include #include - diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 12daafa14..91969c256 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -66,14 +66,14 @@ public: virtual void update(gfx::Context&, const TransformState&, const PropertyEvaluationParameters&, - UniqueChangeRequestVec&) const { } + UniqueChangeRequestVec&) const {} virtual void layerAdded(gfx::ShaderRegistry&, gfx::Context&, const TransformState&, const PropertyEvaluationParameters&, - UniqueChangeRequestVec&) const { } - virtual void layerRemoved(UniqueChangeRequestVec&) const { } + UniqueChangeRequestVec&) const {} + virtual void layerRemoved(UniqueChangeRequestVec&) const {} std::string id; std::string source; diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp index e1bc7e731..1419f4a04 100644 --- a/src/mbgl/style/layers/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -5,8 +5,8 @@ #include #include #include -//#include -//#include +// #include +// #include #include #include #include @@ -17,13 +17,11 @@ namespace mbgl { namespace style { -BackgroundLayer::Impl::Impl(const Impl& other) : - Layer::Impl(other), - tileDrawables(other.tileDrawables), - lastColor(other.lastColor), - paint(other.paint) -{ -} +BackgroundLayer::Impl::Impl(const Impl& other) + : Layer::Impl(other), + tileDrawables(other.tileDrawables), + lastColor(other.lastColor), + paint(other.paint) {} bool BackgroundLayer::Impl::hasLayoutDifference(const Layer::Impl&) const { return false; @@ -55,8 +53,7 @@ void BackgroundLayer::Impl::layerRemoved(UniqueChangeRequestVec& changes) const } removeDrawables( - localDrawables.cbegin(), localDrawables.cend(), changes, - [](auto& ii) { return ii->second->getId(); }); + localDrawables.cbegin(), localDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); }); } void BackgroundLayer::Impl::update(gfx::Context& context, @@ -71,7 +68,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context, const auto evaluated = unevaluated->evaluate(evalParameters); // TODO: If background is solid, we can skip drawables and rely on the clear color - //const auto passes = eval.get() == 0.0f + // const auto passes = eval.get() == 0.0f // ? RenderPass::None // : (!uneval.get().isUndefined() // || eval.get() < 1.0f @@ -79,8 +76,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context, // ? RenderPass::Translucent // : RenderPass::Opaque | RenderPass::Translucent; // evaluated based on opaquePassCutoff in render() - //unevaluated.hasTransition(); - //getCrossfade(evaluatedProperties).t != 1; + // unevaluated.hasTransition(); + // getCrossfade(evaluatedProperties).t != 1; std::optional color; if (evaluated.get().from.empty()) { @@ -93,8 +90,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context, // If the result is transparent or missing, just remove any existing drawables and stop if (!color) { removeDrawables( - tileDrawables.cbegin(), tileDrawables.cend(), changes, - [](auto& ii) { return ii->second->getId(); }); + tileDrawables.cbegin(), tileDrawables.cend(), changes, [](auto& ii) { return ii->second->getId(); }); tileDrawables.clear(); return; } @@ -106,7 +102,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context, const auto tileCover = util::tileCover(state, zoom); // Drawables per overscaled or canonical tile? - //const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped(); + // const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped(); // Put the tile cover into a searchable form. // TODO: Likely better to sort and `std::binary_search` the vector. @@ -114,14 +110,15 @@ void BackgroundLayer::Impl::update(gfx::Context& context, const std::unordered_set newTileIDs(tileCover.begin(), tileCover.end()); // For each existing tile drawable... - for (auto iter = tileDrawables.begin(); iter != tileDrawables.end(); ) { + for (auto iter = tileDrawables.begin(); iter != tileDrawables.end();) { const auto& drawable = iter->second; // Has this tile dropped out of the cover set? if (newTileIDs.find(iter->first) == newTileIDs.end()) { // remove it changes.emplace_back(std::make_unique(drawable->getId())); - //Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " + std::to_string(stats.tileDrawablesRemoved+1)); + // Log::Warning(Event::General, "Removing drawable for " + util::toString(iter->first) + " total " + + // std::to_string(stats.tileDrawablesRemoved+1)); iter = tileDrawables.erase(iter); ++stats.tileDrawablesRemoved; continue; @@ -158,7 +155,7 @@ void BackgroundLayer::Impl::update(gfx::Context& context, // Tile coordinates are fixed... builder->addQuad(0, 0, util::EXTENT, util::EXTENT); - + // ... they're placed with the matrix in the uniforms, which changes with the view builder->setMatrix(/*parameters.matrixForTile(tileID.toUnwrapped())*/ matrix::identity4()); @@ -171,7 +168,8 @@ void BackgroundLayer::Impl::update(gfx::Context& context, result.first->second = drawable; changes.emplace_back(std::make_unique(std::move(drawable))); ++stats.tileDrawablesAdded; - //Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " + std::to_string(stats.tileDrawablesAdded+1)); + // Log::Warning(Event::General, "Adding drawable for " + util::toString(tileID) + " total " + + // std::to_string(stats.tileDrawablesAdded+1)); } } } diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index 80bba1d9c..8f7d972cf 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -49,7 +49,9 @@ public: private: // Add a deletion change request for each drawable in a collection template - static void removeDrawables(T beg, const T end, UniqueChangeRequestVec& changes, + static void removeDrawables(T beg, + const T end, + UniqueChangeRequestVec& changes, std::function f) { for (; beg != end; ++beg) { changes.emplace_back(std::make_unique(f(beg))); diff --git a/src/mbgl/util/identity.cpp b/src/mbgl/util/identity.cpp index 9580db97e..7ebb47ec7 100644 --- a/src/mbgl/util/identity.cpp +++ b/src/mbgl/util/identity.cpp @@ -3,9 +3,9 @@ #include namespace { - // This is not in the class declaration to minimize include dependencies - std::atomic nextId = 1; -} // anonymous namespace +// This is not in the class declaration to minimize include dependencies +std::atomic nextId = 1; +} // anonymous namespace namespace mbgl { namespace util { @@ -13,11 +13,7 @@ namespace util { const SimpleIdentity SimpleIdentity::Empty = {emptyID}; SimpleIdentity::SimpleIdentity() - : uniqueID(nextId++) -{ -} - + : uniqueID(nextId++) {} } // namespace util } // namespace mbgl - diff --git a/src/mbgl/util/mat4.hpp b/src/mbgl/util/mat4.hpp index 52e6b5246..c3e8c0e18 100644 --- a/src/mbgl/util/mat4.hpp +++ b/src/mbgl/util/mat4.hpp @@ -33,8 +33,12 @@ using matf4 = std::array; namespace matrix { void identity(mat4& out); -constexpr mat4 identity4() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; } -constexpr matf4 identity4f() { return { 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 }; } +constexpr mat4 identity4() { + return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; +} +constexpr matf4 identity4f() { + return {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; +} bool invert(mat4& out, const mat4& a); void ortho(mat4& out, double left, double right, double bottom, double top, double near, double far);