Issue/1687 (#1697)
Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: mwilsnd <mwilsnd@gmail.com>
This commit is contained in:
@@ -18,8 +18,11 @@ namespace mbgl {
|
||||
|
||||
class Color;
|
||||
class PaintParameters;
|
||||
class LayerTweaker;
|
||||
enum class RenderPass : uint8_t;
|
||||
|
||||
using LayerTweakerPtr = std::shared_ptr<LayerTweaker>;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class ColorMode;
|
||||
@@ -234,6 +237,10 @@ public:
|
||||
/// Get drawable user-defined type
|
||||
size_t getType() const { return type; }
|
||||
|
||||
/// Associate the drawable with a layer tweaker. This is used to manage the lifetime of the tweaker.
|
||||
void setLayerTweaker(LayerTweakerPtr tweaker) { layerTweaker = std::move(tweaker); }
|
||||
const LayerTweakerPtr& getLayerTweaker() const { return layerTweaker; }
|
||||
|
||||
protected:
|
||||
bool enabled = true;
|
||||
bool enableColor = true;
|
||||
@@ -257,6 +264,7 @@ protected:
|
||||
|
||||
Textures textures;
|
||||
std::vector<DrawableTweakerPtr> tweakers;
|
||||
LayerTweakerPtr layerTweaker;
|
||||
|
||||
std::size_t type = 0;
|
||||
};
|
||||
|
||||
@@ -145,6 +145,9 @@ public:
|
||||
/// @param location A sampler location in the shader being used.
|
||||
void setTexture(const gfx::Texture2DPtr&, int32_t location);
|
||||
|
||||
/// Direct access to the current texture set
|
||||
const gfx::Drawable::Textures& getTextures() const { return textures; }
|
||||
|
||||
/// Add a tweaker to emitted drawable
|
||||
void addTweaker(DrawableTweakerPtr value) { tweakers.emplace_back(std::move(value)); }
|
||||
|
||||
@@ -225,5 +228,7 @@ protected:
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
using UniqueDrawableBuilder = std::unique_ptr<DrawableBuilder>;
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using StringIdentity = std::size_t;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class Context;
|
||||
@@ -138,12 +141,13 @@ public:
|
||||
|
||||
/// @brief Get a shader from the group by its set of data driven properties as uniforms.
|
||||
/// if no shader is found, create and register the shader.
|
||||
/// @param propertiesAsUniforms Vector of data driven properties as uniforms.
|
||||
/// @param propertiesAsUniforms Set of data driven properties as uniforms.
|
||||
/// @param firstAttribName Name of the first attribute
|
||||
/// @return A `gfx::ShaderPtr`
|
||||
virtual gfx::ShaderPtr getOrCreateShader(gfx::Context&,
|
||||
[[maybe_unused]] const std::vector<std::string>& propertiesAsUniforms,
|
||||
[[maybe_unused]] std::string_view firstAttribName = "a_pos") {
|
||||
virtual gfx::ShaderPtr getOrCreateShader(
|
||||
gfx::Context&,
|
||||
[[maybe_unused]] const std::unordered_set<StringIdentity>& propertiesAsUniforms,
|
||||
[[maybe_unused]] std::string_view firstAttribName = "a_pos") {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
@@ -364,9 +365,15 @@ public:
|
||||
}
|
||||
|
||||
/// Specialized DataDrivenPaintProperty reader
|
||||
/// @param binders Property binders for the target shader
|
||||
/// @param evaluated Evaluated properties
|
||||
/// @param propertiesAsUniforms [out] A set of string identities for the properties which will be constant, not
|
||||
/// attributes.
|
||||
/// @details The property name IDs refer to the "a\_" prefixed values to match the shader definitions.
|
||||
template <class... DataDrivenPaintProperty, class Binders, class Evaluated>
|
||||
std::vector<std::string> readDataDrivenPaintProperties(const Binders& binders, const Evaluated& evaluated) {
|
||||
std::vector<std::string> propertiesAsUniforms;
|
||||
void readDataDrivenPaintProperties(const Binders& binders,
|
||||
const Evaluated& evaluated,
|
||||
std::unordered_set<StringIdentity>& propertiesAsUniforms) {
|
||||
propertiesAsUniforms.reserve(sizeof...(DataDrivenPaintProperty));
|
||||
(
|
||||
[&](const auto& attributeNames) {
|
||||
@@ -377,15 +384,14 @@ public:
|
||||
using Type = typename Attribute::Type; // ::mbgl::gfx::AttributeType<type_, n_>
|
||||
using InterpType = ZoomInterpolatedAttributeType<Type>;
|
||||
|
||||
auto& attributeNameID = DataDrivenPaintProperty::AttributeNameIDs[attrIndex];
|
||||
if (!attributeNameID) {
|
||||
attributeNameID = StringIndexer::get(attributePrefix + attributeName.data());
|
||||
}
|
||||
|
||||
const auto vertexCount = binder->getVertexCount();
|
||||
const auto isConstant = evaluated.template get<DataDrivenPaintProperty>().isConstant();
|
||||
if (vertexCount > 0 && !isConstant) {
|
||||
auto& attributeNameID = DataDrivenPaintProperty::AttributeNameIDs[attrIndex];
|
||||
if (!attributeNameID) {
|
||||
static const std::string attributePrefix = "a_";
|
||||
attributeNameID = StringIndexer::get(attributePrefix + attributeName.data());
|
||||
}
|
||||
|
||||
if (auto& attr = getOrAdd(*attributeNameID)) {
|
||||
if (const auto& sharedVector = binder->getSharedVertexVector()) {
|
||||
const auto rawSize = static_cast<uint32_t>(sharedVector->getRawSize());
|
||||
@@ -402,15 +408,13 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
propertiesAsUniforms.emplace_back(std::string());
|
||||
} else {
|
||||
propertiesAsUniforms.emplace_back(attributeName);
|
||||
propertiesAsUniforms.emplace(*attributeNameID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}(DataDrivenPaintProperty::AttributeNames),
|
||||
...);
|
||||
return propertiesAsUniforms;
|
||||
}
|
||||
|
||||
/// Copy another collection into this one
|
||||
@@ -435,7 +439,8 @@ protected:
|
||||
|
||||
protected:
|
||||
AttributeMap attrs;
|
||||
static std::unique_ptr<VertexAttribute> nullref;
|
||||
static const std::unique_ptr<VertexAttribute> nullref;
|
||||
static const std::string attributePrefix;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace mbgl {
|
||||
class LayerGroupBase;
|
||||
class PaintParameters;
|
||||
class RenderOrchestrator;
|
||||
class RenderTree;
|
||||
class TileLayerGroup;
|
||||
|
||||
using LayerGroupBasePtr = std::shared_ptr<LayerGroupBase>;
|
||||
@@ -28,6 +29,7 @@ using UniqueDrawable = std::unique_ptr<Drawable>;
|
||||
|
||||
class LayerTweaker;
|
||||
using LayerTweakerPtr = std::shared_ptr<LayerTweaker>;
|
||||
using LayerTweakerWeakPtr = std::weak_ptr<LayerTweaker>;
|
||||
|
||||
/**
|
||||
A layer-like group of drawables, not a group of layers.
|
||||
@@ -86,16 +88,16 @@ public:
|
||||
/// @return The number of items removed
|
||||
virtual std::size_t removeDrawablesIf(const std::function<bool(gfx::Drawable&)>&& f) = 0;
|
||||
|
||||
/// Attach a tweaker to be run on this layer group for each frame
|
||||
void setLayerTweaker(LayerTweakerPtr tweaker) { layerTweaker = std::move(tweaker); }
|
||||
/// Attach a tweaker to be run on this layer group for each frame.
|
||||
/// Tweaker lifetime is controlled by the render layer and drawables, the layer group retains a weak reference.
|
||||
void addLayerTweaker(const LayerTweakerPtr& tweaker) { layerTweakers.emplace_back(tweaker); }
|
||||
|
||||
/// Get the tweaker attached to this layer group
|
||||
const LayerTweakerPtr& getLayerTweaker() const { return layerTweaker; }
|
||||
void runTweakers(const RenderTree&, PaintParameters&);
|
||||
|
||||
protected:
|
||||
bool enabled = true;
|
||||
int32_t layerIndex;
|
||||
LayerTweakerPtr layerTweaker;
|
||||
std::vector<LayerTweakerWeakPtr> layerTweakers;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/util/immutable.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
class UniformBuffer;
|
||||
using UniformBufferPtr = std::shared_ptr<UniformBuffer>;
|
||||
} // namespace gfx
|
||||
|
||||
namespace shaders {
|
||||
enum class AttributeSource : int32_t;
|
||||
struct ExpressionInputsUBO;
|
||||
} // namespace shaders
|
||||
|
||||
namespace style {
|
||||
class LayerProperties;
|
||||
enum class TranslateAnchorType : bool;
|
||||
} // namespace style
|
||||
|
||||
class TransformState;
|
||||
class LayerGroupBase;
|
||||
class PaintParameters;
|
||||
@@ -27,6 +33,7 @@ class RenderTree;
|
||||
class UnwrappedTileID;
|
||||
|
||||
using mat4 = std::array<double, 16>;
|
||||
using StringIdentity = std::size_t;
|
||||
|
||||
/**
|
||||
Base class for layer tweakers, which manipulate layer group per frame
|
||||
@@ -45,16 +52,20 @@ public:
|
||||
/// Build the common expression inupts UBO
|
||||
static shaders::ExpressionInputsUBO buildExpressionUBO(double zoom, uint64_t frameCount);
|
||||
|
||||
/// @brief Check whether a property name exists within the previously set collection.
|
||||
bool hasPropertyAsUniform(StringIdentity) const;
|
||||
shaders::AttributeSource getAttributeSource(StringIdentity) const;
|
||||
|
||||
template <shaders::BuiltIn ShaderType>
|
||||
shaders::AttributeSource getAttributeSource(size_t index) {
|
||||
using ShaderClass = shaders::ShaderSource<ShaderType, gfx::Backend::Type::Metal>;
|
||||
return getAttributeSource(ShaderClass::attributes[index].nameID);
|
||||
}
|
||||
#endif // MLN_RENDER_BACKEND_METAL
|
||||
|
||||
/// @brief Set the collection of attribute names which will be provided at uniform values rather than per-vertex
|
||||
/// attributes.
|
||||
/// @details These values should not have "a_" prefixes, as produced by `readDataDrivenPaintProperties`.
|
||||
void setPropertiesAsUniforms(std::vector<std::string>);
|
||||
|
||||
/// @brief Check whether a property name exists within the previously set collection.
|
||||
/// @details The string value provided is expected to have the "a_" prefix, as defined in the shader classes.
|
||||
bool hasPropertyAsUniform(std::string_view) const;
|
||||
shaders::AttributeSource getAttributeSource(const std::string_view& attribName) const;
|
||||
#endif // MLN_RENDER_BACKEND_METAL
|
||||
void setPropertiesAsUniforms(const std::unordered_set<StringIdentity>&);
|
||||
|
||||
void enableOverdrawInspector(bool);
|
||||
|
||||
@@ -63,6 +74,9 @@ public:
|
||||
void updateProperties(Immutable<style::LayerProperties>);
|
||||
|
||||
protected:
|
||||
/// Determine whether this tweaker should apply to the given drawable
|
||||
bool checkTweakDrawable(const gfx::Drawable&) const;
|
||||
|
||||
/// Calculate matrices for this tile.
|
||||
/// @param nearClipped If true, the near plane is moved further to enhance depth buffer precision.
|
||||
/// @param inViewportPixelUnits If false, the translation is scaled based on the current zoom.
|
||||
@@ -78,14 +92,15 @@ protected:
|
||||
protected:
|
||||
std::string id;
|
||||
Immutable<style::LayerProperties> evaluatedProperties;
|
||||
bool propertiesUpdated = true;
|
||||
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
// For Metal, whether a property is provided through attribtues or uniforms is specified in
|
||||
// a uniform buffer rather than by a shader compiled with different preprocessor definitions.
|
||||
std::vector<std::string> propertiesAsUniforms;
|
||||
std::unordered_set<StringIdentity> propertiesAsUniforms;
|
||||
#endif // MLN_RENDER_BACKEND_METAL
|
||||
|
||||
bool propertiesUpdated = true;
|
||||
|
||||
bool propertiesChanged = true;
|
||||
bool overdrawInspector = false;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <mbgl/shaders/gl/shader_program_gl.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/util/hash.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace mbgl {
|
||||
namespace gl {
|
||||
@@ -13,40 +17,61 @@ class ShaderGroupGL final : public gfx::ShaderGroup {
|
||||
public:
|
||||
ShaderGroupGL(const ProgramParameters& programParameters_)
|
||||
: ShaderGroup(),
|
||||
programParameters(programParameters_){};
|
||||
programParameters(programParameters_) {}
|
||||
~ShaderGroupGL() noexcept override = default;
|
||||
|
||||
gfx::ShaderPtr getOrCreateShader(gfx::Context& context,
|
||||
const std::vector<std::string>& propertiesAsUniforms,
|
||||
const std::unordered_set<StringIdentity>& propertiesAsUniforms,
|
||||
std::string_view firstAttribName) override {
|
||||
constexpr auto& name = shaders::ShaderSource<ShaderID, gfx::Backend::Type::OpenGL>::name;
|
||||
constexpr auto& vert = shaders::ShaderSource<ShaderID, gfx::Backend::Type::OpenGL>::vertex;
|
||||
constexpr auto& frag = shaders::ShaderSource<ShaderID, gfx::Backend::Type::OpenGL>::fragment;
|
||||
|
||||
uint32_t key = 0;
|
||||
// Generate a map key for the specified combination of properties
|
||||
const size_t key = util::order_independent_hash(propertiesAsUniforms.begin(), propertiesAsUniforms.end());
|
||||
|
||||
// We could cache these by key here to avoid creating a string key each time, but we
|
||||
// would need another mutex. We could also push string IDs down into `ShaderGroup`.
|
||||
const std::string shaderName = getShaderName(key);
|
||||
auto shader = get<gl::ShaderProgramGL>(shaderName);
|
||||
if (shader) {
|
||||
return shader;
|
||||
}
|
||||
|
||||
// No match, we need to create the shader.
|
||||
std::string additionalDefines;
|
||||
for (unsigned int i = 0; i < propertiesAsUniforms.size(); i++) {
|
||||
if (propertiesAsUniforms[i].empty()) {
|
||||
continue;
|
||||
additionalDefines.reserve(propertiesAsUniforms.size() * 48);
|
||||
for (const auto nameID : propertiesAsUniforms) {
|
||||
// We expect the names to be prefixed by "a_", but we need just the base here.
|
||||
const auto prefixedAttrName = StringIndexer::get(nameID);
|
||||
const auto* prefix = prefixedAttrName.data();
|
||||
if (prefix[0] == 'a' && prefix[1] == '_') {
|
||||
prefix += 2;
|
||||
}
|
||||
key |= 1 << i;
|
||||
|
||||
additionalDefines += "#define HAS_UNIFORM_u_";
|
||||
additionalDefines += propertiesAsUniforms[i];
|
||||
additionalDefines += prefix;
|
||||
additionalDefines += "\n";
|
||||
}
|
||||
const std::string shaderName = std::string(name) + "#" + std::to_string(key);
|
||||
auto shader = get<gl::ShaderProgramGL>(shaderName);
|
||||
if (!shader) {
|
||||
auto& glContext = static_cast<gl::Context&>(context);
|
||||
shader = ShaderProgramGL::create(
|
||||
glContext, programParameters, shaderName, firstAttribName, vert, frag, additionalDefines);
|
||||
if (!shader || !registerShader(shader, shaderName)) {
|
||||
throw std::runtime_error("Failed to register " + shaderName + " with shader group!");
|
||||
}
|
||||
|
||||
auto& glContext = static_cast<gl::Context&>(context);
|
||||
shader = ShaderProgramGL::create(
|
||||
glContext, programParameters, shaderName, firstAttribName, vert, frag, additionalDefines);
|
||||
if (!shader || !registerShader(shader, shaderName)) {
|
||||
throw std::runtime_error("Failed to register " + shaderName + " with shader group!");
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string getShaderName(std::size_t key) {
|
||||
constexpr auto& name = shaders::ShaderSource<ShaderID, gfx::Backend::Type::OpenGL>::name;
|
||||
|
||||
// This could be more efficient.
|
||||
std::ostringstream stream;
|
||||
stream << name << '#' << key;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
private:
|
||||
ProgramParameters programParameters;
|
||||
};
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#define MLN_STRINGIZE(X) #X
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
|
||||
@@ -14,14 +14,9 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Float3, 1, "a_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(1, true, true, BackgroundLayerUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(2, true, false, BackgroundDrawableUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#include <metal_stdlib>
|
||||
|
||||
@@ -9,11 +9,7 @@ template <>
|
||||
struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>
|
||||
: public ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto name = "BackgroundPatternShader";
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
{1, sizeof(BackgroundLayerUBO), true, false, "BackgroundLayerUBO"},
|
||||
{2, sizeof(BackgroundDrawableUBO), true, false, "BackgroundDrawableUBO"},
|
||||
{3, sizeof(BackgroundPatternLayerUBO), true, false, "BackgroundPatternLayerUBO"},
|
||||
};
|
||||
static const std::array<UniformBlockInfo, 3> uniforms;
|
||||
};
|
||||
|
||||
} // namespace shaders
|
||||
|
||||
@@ -14,25 +14,9 @@ struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Float2, 1, "a_color"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_radius"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_blur"},
|
||||
{4, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
{5, gfx::AttributeDataType::Float4, 1, "a_stroke_color"},
|
||||
{6, gfx::AttributeDataType::Float2, 1, "a_stroke_width"},
|
||||
{7, gfx::AttributeDataType::Float2, 1, "a_stroke_opacity"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, false, CircleDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, true, CirclePaintParamsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, true, CircleEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, false, CircleInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, true, CirclePermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(13, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 8> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
|
||||
@@ -20,13 +20,9 @@ struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Float3, 1, "a_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(1, true, false, ClipUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#include <metal_stdlib>
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define MLN_MTL_UNIFORM_BLOCK(idx, vert, frag, struc) \
|
||||
{ idx, vert, frag, sizeof(struc), MLN_STRINGIZE(struc) }
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
|
||||
@@ -14,24 +14,9 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Float2, 1, "a_color"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
|
||||
// This shader doesn't use it, but we need this so that the layer can assign the same
|
||||
// attributes to all the drawables. If/When `VertexAttributeArray::resolve` allows it,
|
||||
// this can be removed.
|
||||
{8, gfx::AttributeDataType::Float2, 1, "a_outline_color"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(3, true, false, FillDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(4, true, true, FillEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, FillInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, true, FillPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
@@ -104,22 +89,9 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Float2, 1, "a_outline_color"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
|
||||
// See `a_outline_color` in FillShader
|
||||
{8, gfx::AttributeDataType::Float2, 1, "a_color"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(3, true, false, FillOutlineDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(4, true, true, FillOutlineEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, FillOutlineInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, true, FillOutlinePermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
@@ -203,24 +175,9 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::UShort4, 1, "a_pattern_from"},
|
||||
{2, gfx::AttributeDataType::UShort4, 1, "a_pattern_to"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(4, true, true, FillPatternDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, FillPatternTilePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, true, FillPatternEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, FillPatternInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, true, FillPatternPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
@@ -341,24 +298,9 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::UShort4, 1, "a_pattern_from"},
|
||||
{2, gfx::AttributeDataType::UShort4, 1, "a_pattern_to"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(4, true, true, FillOutlinePatternDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, FillOutlinePatternTilePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, true, FillOutlinePatternEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, FillOutlinePatternInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, true, FillOutlinePatternPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 4> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
|
||||
@@ -14,21 +14,9 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Short4, 1, "a_normal_ed"},
|
||||
{2, gfx::AttributeDataType::Float4, 1, "a_color"},
|
||||
{3, gfx::AttributeDataType::Float, 1, "a_base"},
|
||||
{4, gfx::AttributeDataType::Float, 1, "a_height"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, FillExtrusionDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, false, FillExtrusionDrawablePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, FillExtrusionInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, false, FillExtrusionPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 5> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct alignas(16) FillExtrusionInterpolateUBO {
|
||||
|
||||
@@ -14,9 +14,9 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Met
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {};
|
||||
static constexpr UniformBlockInfo uniforms[] = {};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 0> attributes;
|
||||
static const std::array<UniformBlockInfo, 0> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
)";
|
||||
|
||||
@@ -14,19 +14,9 @@ struct ShaderSource<BuiltIn::HeatmapShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Float2, 1, "a_weight"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_radius"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(3, true, false, HeatmapDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(4, true, true, HeatmapEvaluatedPropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(5, true, false, HeatmapInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(6, true, true, HeatmapPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 3> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
|
||||
@@ -14,16 +14,10 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(1, true, true, HeatmapTextureDrawableUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
{1, "u_color_ramp"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 1> attributes;
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
struct VertexStage {
|
||||
|
||||
@@ -14,17 +14,9 @@ struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Short2, 1, "a_texture_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(2, true, true, HillshadeDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(3, false, true, HillshadeEvaluatedPropsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static const std::array<UniformBlockInfo, 2> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
|
||||
@@ -14,16 +14,10 @@ struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Metal>
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Short2, 1, "a_texture_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(2, true, true, HillshadePrepareDrawableUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
struct VertexStage {
|
||||
|
||||
@@ -14,24 +14,9 @@ struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos_normal"},
|
||||
{1, gfx::AttributeDataType::UByte4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Float4, 1, "a_color"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_blur"},
|
||||
{4, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
{5, gfx::AttributeDataType::Float2, 1, "a_gapwidth"},
|
||||
{6, gfx::AttributeDataType::Float2, 1, "a_offset"},
|
||||
{7, gfx::AttributeDataType::Float2, 1, "a_width"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, true, LineUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, false, LinePropertiesUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, false, LineInterpolationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, true, LinePermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {};
|
||||
static const std::array<AttributeInfo, 8> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 0> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
@@ -143,28 +128,9 @@ struct ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos_normal"},
|
||||
{1, gfx::AttributeDataType::UByte4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_blur"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
{4, gfx::AttributeDataType::Float2, 1, "a_gapwidth"},
|
||||
{5, gfx::AttributeDataType::Float2, 1, "a_offset"},
|
||||
{6, gfx::AttributeDataType::Float2, 1, "a_width"},
|
||||
{7, gfx::AttributeDataType::UShort4, 1, "a_pattern_from"},
|
||||
{8, gfx::AttributeDataType::UShort4, 1, "a_pattern_to"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, true, LinePatternUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, false, LinePatternPropertiesUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, false, LinePatternInterpolationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, false, LinePatternTilePropertiesUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(13, true, true, LinePermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(14, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
|
||||
@@ -14,25 +14,9 @@ struct ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos_normal"},
|
||||
{1, gfx::AttributeDataType::UByte4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Float2, 1, "a_blur"},
|
||||
{3, gfx::AttributeDataType::Float2, 1, "a_opacity"},
|
||||
{4, gfx::AttributeDataType::Float2, 1, "a_gapwidth"},
|
||||
{5, gfx::AttributeDataType::Float2, 1, "a_offset"},
|
||||
{6, gfx::AttributeDataType::Float2, 1, "a_width"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(7, true, true, LineGradientUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, false, LineGradientPropertiesUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, false, LineGradientInterpolationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, true, LinePermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 7> attributes;
|
||||
static const std::array<UniformBlockInfo, 5> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
|
||||
@@ -14,17 +14,10 @@ struct ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
{0, gfx::AttributeDataType::Short2, 1, "a_pos"},
|
||||
{1, gfx::AttributeDataType::Short2, 1, "a_texture_pos"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(2, true, true, RasterDrawableUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_image0"},
|
||||
{1, "u_image1"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 2> attributes;
|
||||
static const std::array<UniformBlockInfo, 1> uniforms;
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
|
||||
struct VertexStage {
|
||||
|
||||
@@ -22,32 +22,20 @@ public:
|
||||
~ShaderGroup() noexcept override = default;
|
||||
|
||||
gfx::ShaderPtr getOrCreateShader(gfx::Context& gfxContext,
|
||||
const std::vector<std::string>& propertiesAsUniforms,
|
||||
const std::unordered_set<StringIdentity>& propertiesAsUniforms,
|
||||
std::string_view /*firstAttribName*/) override {
|
||||
constexpr auto& name = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Metal>::name;
|
||||
constexpr auto& source = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Metal>::source;
|
||||
constexpr auto& vertMain = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Metal>::vertexMainFunction;
|
||||
constexpr auto& fragMain = shaders::ShaderSource<ShaderID, gfx::Backend::Type::Metal>::fragmentMainFunction;
|
||||
|
||||
uint32_t key = 0;
|
||||
assert(propertiesAsUniforms.size() < 32);
|
||||
std::unordered_map<std::string, std::string> additionalDefines(propertiesAsUniforms.size());
|
||||
for (unsigned int i = 0; i < propertiesAsUniforms.size(); i++) {
|
||||
if (!propertiesAsUniforms[i].empty()) {
|
||||
key |= 1U << i;
|
||||
auto name = std::string("HAS_UNIFORM_u_") + propertiesAsUniforms[i];
|
||||
additionalDefines.insert(std::make_pair(std::move(name), "1"));
|
||||
}
|
||||
}
|
||||
|
||||
const std::string shaderName = std::string(name); // + "#" + std::to_string(key);
|
||||
const std::string shaderName = std::string(name);
|
||||
const auto shaderSource = std::string(shaders::prelude) + source;
|
||||
|
||||
auto shader = get<mtl::ShaderProgram>(shaderName);
|
||||
if (!shader) {
|
||||
auto& context = static_cast<Context&>(gfxContext);
|
||||
shader = context.createProgram(
|
||||
shaderName, shaderSource, vertMain, fragMain, programParameters, additionalDefines);
|
||||
shader = context.createProgram(shaderName, shaderSource, vertMain, fragMain, programParameters, {});
|
||||
assert(shader);
|
||||
if (!shader || !registerShader(shader, shaderName)) {
|
||||
assert(false);
|
||||
|
||||
@@ -15,21 +15,27 @@
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
struct AttributeInfo {
|
||||
AttributeInfo(std::size_t index, gfx::AttributeDataType dataType, std::size_t count, std::string_view name);
|
||||
std::size_t index;
|
||||
gfx::AttributeDataType dataType;
|
||||
std::size_t count;
|
||||
std::string_view name;
|
||||
StringIdentity nameID;
|
||||
};
|
||||
struct UniformBlockInfo {
|
||||
UniformBlockInfo(std::size_t index, bool vertex, bool fragment, std::size_t size, std::string_view name);
|
||||
std::size_t index;
|
||||
bool vertex;
|
||||
bool fragment;
|
||||
std::size_t size;
|
||||
std::string_view name;
|
||||
StringIdentity nameID;
|
||||
};
|
||||
struct TextureInfo {
|
||||
TextureInfo(std::size_t index, std::string_view name);
|
||||
std::size_t index;
|
||||
std::string_view name;
|
||||
StringIdentity nameID;
|
||||
};
|
||||
} // namespace shaders
|
||||
namespace mtl {
|
||||
|
||||
@@ -14,28 +14,9 @@ struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
// always attributes
|
||||
{0, gfx::AttributeDataType::Short4, 1, "a_pos_offset"},
|
||||
{1, gfx::AttributeDataType::UShort4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Short4, 1, "a_pixeloffset"},
|
||||
{3, gfx::AttributeDataType::Float3, 1, "a_projected_pos"},
|
||||
{4, gfx::AttributeDataType::Float, 1, "a_fade_opacity"},
|
||||
|
||||
// sometimes uniforms
|
||||
{5, gfx::AttributeDataType::Float, 1, "a_opacity"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(8, true, true, SymbolDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, true, SymbolDrawablePaintUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, false, SymbolDrawableTilePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, false, SymbolDrawableInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, true, SymbolPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(13, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_texture"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 6> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
|
||||
@@ -14,32 +14,9 @@ struct ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal> {
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
// always attributes
|
||||
{0, gfx::AttributeDataType::Short4, 1, "a_pos_offset"},
|
||||
{1, gfx::AttributeDataType::UShort4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Short4, 1, "a_pixeloffset"},
|
||||
{3, gfx::AttributeDataType::Float3, 1, "a_projected_pos"},
|
||||
{4, gfx::AttributeDataType::Float, 1, "a_fade_opacity"},
|
||||
|
||||
// sometimes uniforms
|
||||
{5, gfx::AttributeDataType::Float4, 1, "a_fill_color"},
|
||||
{6, gfx::AttributeDataType::Float4, 1, "a_halo_color"},
|
||||
{7, gfx::AttributeDataType::Float, 1, "a_opacity"},
|
||||
{8, gfx::AttributeDataType::Float, 1, "a_halo_width"},
|
||||
{9, gfx::AttributeDataType::Float, 1, "a_halo_blur"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, true, SymbolDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, false, SymbolDrawablePaintUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, true, SymbolDrawableTilePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(13, true, false, SymbolDrawableInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(14, true, true, SymbolPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(15, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_texture"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 10> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 1> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
struct VertexStage {
|
||||
|
||||
@@ -14,32 +14,9 @@ struct ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal>
|
||||
static constexpr auto vertexMainFunction = "vertexMain";
|
||||
static constexpr auto fragmentMainFunction = "fragmentMain";
|
||||
|
||||
static constexpr AttributeInfo attributes[] = {
|
||||
// always attributes
|
||||
{0, gfx::AttributeDataType::Short4, 1, "a_pos_offset"},
|
||||
{1, gfx::AttributeDataType::UShort4, 1, "a_data"},
|
||||
{2, gfx::AttributeDataType::Float3, 1, "a_projected_pos"},
|
||||
{3, gfx::AttributeDataType::Float, 1, "a_fade_opacity"},
|
||||
|
||||
// sometimes uniforms
|
||||
{4, gfx::AttributeDataType::Float4, 1, "a_fill_color"},
|
||||
{5, gfx::AttributeDataType::Float4, 1, "a_halo_color"},
|
||||
{6, gfx::AttributeDataType::Float, 1, "a_opacity"},
|
||||
{7, gfx::AttributeDataType::Float, 1, "a_halo_width"},
|
||||
{8, gfx::AttributeDataType::Float, 1, "a_halo_blur"},
|
||||
};
|
||||
static constexpr UniformBlockInfo uniforms[] = {
|
||||
MLN_MTL_UNIFORM_BLOCK(9, true, true, SymbolDrawableUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(10, true, false, SymbolDrawablePaintUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(11, true, true, SymbolDrawableTilePropsUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(12, true, false, SymbolDrawableInterpolateUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(13, true, true, SymbolPermutationUBO),
|
||||
MLN_MTL_UNIFORM_BLOCK(14, true, false, ExpressionInputsUBO),
|
||||
};
|
||||
static constexpr TextureInfo textures[] = {
|
||||
{0, "u_texture"},
|
||||
{1, "u_texture_icon"},
|
||||
};
|
||||
static const std::array<AttributeInfo, 9> attributes;
|
||||
static const std::array<UniformBlockInfo, 6> uniforms;
|
||||
static const std::array<TextureInfo, 2> textures;
|
||||
|
||||
static constexpr auto source = R"(
|
||||
#define SDF 1.0
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using StringIdentity = size_t;
|
||||
using StringIdentity = std::size_t;
|
||||
|
||||
class StringIndexer {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user