Texture by index instead of map (#2107)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Alex Cristici
2024-02-15 21:28:20 +02:00
committed by GitHub
parent 1d00e5b9ea
commit 612b256821
54 changed files with 416 additions and 347 deletions

View File

@@ -1143,8 +1143,8 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/line_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/line_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/raster_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/raster_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/shader_defines.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/symbol_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/symbol_layer_ubo.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/ubo_max_count.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl_builder.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl_builder.hpp

View File

@@ -990,9 +990,9 @@ MLN_DRAWABLES_HEADERS = [
"include/mbgl/shaders/layer_ubo.hpp", "include/mbgl/shaders/layer_ubo.hpp",
"include/mbgl/shaders/line_layer_ubo.hpp", "include/mbgl/shaders/line_layer_ubo.hpp",
"include/mbgl/shaders/raster_layer_ubo.hpp", "include/mbgl/shaders/raster_layer_ubo.hpp",
"include/mbgl/shaders/shader_defines.hpp",
"include/mbgl/shaders/shader_program_base.hpp", "include/mbgl/shaders/shader_program_base.hpp",
"include/mbgl/shaders/symbol_layer_ubo.hpp", "include/mbgl/shaders/symbol_layer_ubo.hpp",
"include/mbgl/shaders/ubo_max_count.hpp",
"include/mbgl/util/identity.hpp", "include/mbgl/util/identity.hpp",
"include/mbgl/util/suppress_copies.hpp", "include/mbgl/util/suppress_copies.hpp",
"include/mbgl/style/layers/custom_drawable_layer.hpp", "include/mbgl/style/layers/custom_drawable_layer.hpp",

View File

@@ -44,8 +44,8 @@ using VertexAttributeArrayPtr = std::shared_ptr<VertexAttributeArray>;
class Drawable { class Drawable {
public: public:
/// @brief Map from sampler location to texture info /// @brief Array of textures to bind
using Textures = mbgl::unordered_map<int32_t, gfx::Texture2DPtr>; using Textures = std::array<gfx::Texture2DPtr, shaders::maxTextureCountPerShader>;
protected: protected:
Drawable(std::string name); Drawable(std::string name);
@@ -99,26 +99,18 @@ public:
/// Set line width /// Set line width
void setLineWidth(int32_t value) { lineWidth = value; } void setLineWidth(int32_t value) { lineWidth = value; }
/// @brief Remove an attached texture from this drawable at the given sampler location /// @brief Get the texture at the given internal ID.
/// @param location Texture sampler location const gfx::Texture2DPtr& getTexture(size_t id) const;
void removeTexture(int32_t location);
/// @brief Return the textures attached to this drawable
/// @return Texture and sampler location pairs
const Textures& getTextures() const { return textures; };
/// @brief Get the texture at the given sampler location.
const gfx::Texture2DPtr& getTexture(int32_t location) const;
/// @brief Set the collection of textures bound to this drawable /// @brief Set the collection of textures bound to this drawable
/// @param textures_ A Textures collection to set /// @param textures_ A Textures collection to set
void setTextures(const Textures& textures_) noexcept { textures = textures_; } void setTextures(const Textures& textures_) noexcept { textures = textures_; }
void setTextures(Textures&& textures_) noexcept { textures = std::move(textures_); } void setTextures(Textures&& textures_) noexcept { textures = std::move(textures_); }
/// @brief Attach the given texture to this drawable at the given sampler location. /// @brief Attach the given texture to this drawable at the given internal ID.
/// @param texture Texture2D instance /// @param texture Texture2D instance
/// @param location A sampler location in the shader being used with this drawable. /// @param id Internal ID of the texture.
void setTexture(gfx::Texture2DPtr texture, int32_t location); void setTexture(gfx::Texture2DPtr texture, size_t id);
/// Whether the drawble should be drawn /// Whether the drawble should be drawn
bool getEnabled() const { return enabled; } bool getEnabled() const { return enabled; }

View File

@@ -24,22 +24,22 @@ class Drawable;
class DrawableAtlasesTweaker : public gfx::DrawableTweaker { class DrawableAtlasesTweaker : public gfx::DrawableTweaker {
public: public:
DrawableAtlasesTweaker(TileAtlasTexturesPtr atlases_, DrawableAtlasesTweaker(TileAtlasTexturesPtr atlases_,
const std::optional<StringIdentity> iconNameId_, const std::optional<size_t> iconTextureId_,
const std::optional<StringIdentity> glyphNameId_, const std::optional<size_t> glyphTextureId_,
bool isText_, bool isText_,
const bool sdfIcons_, const bool sdfIcons_,
const style::AlignmentType rotationAlignment_, const style::AlignmentType rotationAlignment_,
const bool iconScaled_, const bool iconScaled_,
const bool textSizeIsZoomConstant_) const bool textSizeIsZoomConstant_)
: atlases(std::move(atlases_)), : atlases(std::move(atlases_)),
iconNameId(iconNameId_), iconTextureId(iconTextureId_),
glyphNameId(glyphNameId_), glyphTextureId(glyphTextureId_),
isText(isText_), isText(isText_),
sdfIcons(sdfIcons_), sdfIcons(sdfIcons_),
rotationAlignment(rotationAlignment_), rotationAlignment(rotationAlignment_),
iconScaled(iconScaled_), iconScaled(iconScaled_),
textSizeIsZoomConstant(textSizeIsZoomConstant_) { textSizeIsZoomConstant(textSizeIsZoomConstant_) {
assert(iconNameId_ != glyphNameId_); assert(iconTextureId_ != glyphTextureId_);
} }
~DrawableAtlasesTweaker() override = default; ~DrawableAtlasesTweaker() override = default;
@@ -51,8 +51,8 @@ protected:
void setupTextures(Drawable&, const bool); void setupTextures(Drawable&, const bool);
TileAtlasTexturesPtr atlases; TileAtlasTexturesPtr atlases;
std::optional<StringIdentity> iconNameId; std::optional<size_t> iconTextureId;
std::optional<StringIdentity> glyphNameId; std::optional<size_t> glyphTextureId;
bool isText; bool isText;
const bool sdfIcons; const bool sdfIcons;

View File

@@ -140,13 +140,13 @@ public:
/// The attribute names for vertex/position attributes /// The attribute names for vertex/position attributes
void setVertexAttrNameId(const StringIdentity id) { vertexAttrNameId = id; } void setVertexAttrNameId(const StringIdentity id) { vertexAttrNameId = id; }
/// @brief Attach the given texture at the given sampler location. /// @brief Get the texture at the given internal ID.
/// @param texture Texture2D instance const gfx::Texture2DPtr& getTexture(size_t id) const;
/// @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 /// @brief Attach the given texture at the given internal ID.
const gfx::Drawable::Textures& getTextures() const { return textures; } /// @param texture Texture2D instance
/// @param id Internal ID of the texture.
void setTexture(const gfx::Texture2DPtr&, size_t id);
/// Add a tweaker to emitted drawable /// Add a tweaker to emitted drawable
void addTweaker(DrawableTweakerPtr value) { tweakers.emplace_back(std::move(value)); } void addTweaker(DrawableTweakerPtr value) { tweakers.emplace_back(std::move(value)); }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <mbgl/shaders/ubo_max_count.hpp> #include <mbgl/shaders/shader_defines.hpp>
namespace mbgl { namespace mbgl {
namespace gfx { namespace gfx {

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <mbgl/shaders/ubo_max_count.hpp> #include <mbgl/shaders/shader_defines.hpp>
#include <mbgl/util/string_indexer.hpp>
namespace mbgl { namespace mbgl {
namespace gfx { namespace gfx {

View File

@@ -4,6 +4,7 @@
#include <mbgl/gfx/draw_mode.hpp> #include <mbgl/gfx/draw_mode.hpp>
#include <mbgl/mtl/upload_pass.hpp> #include <mbgl/mtl/upload_pass.hpp>
#include <mbgl/programs/segment.hpp> #include <mbgl/programs/segment.hpp>
#include <mbgl/util/string_indexer.hpp>
#include <memory> #include <memory>

View File

@@ -55,9 +55,9 @@ public:
auto& glContext = static_cast<gl::Context&>(context); auto& glContext = static_cast<gl::Context&>(context);
shader = ShaderProgramGL::create(glContext, shader = ShaderProgramGL::create(glContext,
programParameters, programParameters,
shaderName,
firstAttribName, firstAttribName,
shaders::ShaderInfo<ShaderID, gfx::Backend::Type::OpenGL>::uniformBlocks, shaders::ShaderInfo<ShaderID, gfx::Backend::Type::OpenGL>::uniformBlocks,
shaders::ShaderInfo<ShaderID, gfx::Backend::Type::OpenGL>::textures,
vert, vert,
frag, frag,
additionalDefines); additionalDefines);

View File

@@ -15,132 +15,163 @@ struct UniformBlockInfo {
std::size_t binding; std::size_t binding;
}; };
struct TextureInfo {
TextureInfo(std::string_view name, std::size_t id);
std::string_view name;
std::size_t id;
};
template <BuiltIn T, gfx::Backend::Type> template <BuiltIn T, gfx::Backend::Type>
struct ShaderInfo; struct ShaderInfo;
template <> template <>
struct ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
}; static const std::vector<TextureInfo> textures;
template <>
struct ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
};
template <>
struct ShaderInfo<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
};
template <>
struct ShaderInfo<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
};
template <>
struct ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
};
template <>
struct ShaderInfo<BuiltIn::LineBasicShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::LineBasicShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
template <> template <>
struct ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL> { struct ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks; static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
}; };
} // namespace shaders } // namespace shaders

View File

@@ -17,13 +17,13 @@ namespace gl {
class ShaderProgramGL final : public gfx::ShaderProgramBase { class ShaderProgramGL final : public gfx::ShaderProgramBase {
public: public:
using SamplerLocationMap = std::unordered_map<StringIdentity, int>; using SamplerLocationArray = std::array<std::optional<size_t>, shaders::maxTextureCountPerShader>;
ShaderProgramGL(UniqueProgram&& glProgram_); ShaderProgramGL(UniqueProgram&& glProgram_);
ShaderProgramGL(UniqueProgram&&, ShaderProgramGL(UniqueProgram&&,
UniformBlockArrayGL&& uniformBlocks, UniformBlockArrayGL&& uniformBlocks,
VertexAttributeArrayGL&& attributes, VertexAttributeArrayGL&& attributes,
SamplerLocationMap&& samplerLocations); SamplerLocationArray&& samplerLocations);
ShaderProgramGL(ShaderProgramGL&& other); ShaderProgramGL(ShaderProgramGL&& other);
~ShaderProgramGL() noexcept override = default; ~ShaderProgramGL() noexcept override = default;
@@ -32,14 +32,14 @@ public:
static std::shared_ptr<ShaderProgramGL> create(Context&, static std::shared_ptr<ShaderProgramGL> create(Context&,
const ProgramParameters& programParameters, const ProgramParameters& programParameters,
const std::string& name,
const std::string_view firstAttribName, const std::string_view firstAttribName,
const std::vector<shaders::UniformBlockInfo>& uniformBlocksInfo, const std::vector<shaders::UniformBlockInfo>& uniformBlocksInfo,
const std::vector<shaders::TextureInfo>& texturesInfo,
const std::string& vertexSource, const std::string& vertexSource,
const std::string& fragmentSource, const std::string& fragmentSource,
const std::string& additionalDefines = "") noexcept(false); const std::string& additionalDefines = "") noexcept(false);
std::optional<uint32_t> getSamplerLocation(const StringIdentity id) const override; std::optional<size_t> getSamplerLocation(const size_t id) const override;
const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; } const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; }
@@ -55,7 +55,7 @@ protected:
UniformBlockArrayGL uniformBlocks; UniformBlockArrayGL uniformBlocks;
VertexAttributeArrayGL vertexAttributes; VertexAttributeArrayGL vertexAttributes;
SamplerLocationMap samplerLocations; SamplerLocationArray samplerLocations;
}; };
} // namespace gl } // namespace gl

View File

@@ -29,10 +29,9 @@ struct UniformBlockInfo {
std::size_t id; std::size_t id;
}; };
struct TextureInfo { struct TextureInfo {
TextureInfo(std::size_t index, std::string_view name); TextureInfo(std::size_t index, std::size_t id);
std::size_t index; std::size_t index;
std::string_view name; std::size_t id;
StringIdentity nameID;
}; };
} // namespace shaders } // namespace shaders
namespace mtl { namespace mtl {
@@ -56,7 +55,7 @@ public:
const MTLVertexDescriptorPtr&, const MTLVertexDescriptorPtr&,
const gfx::ColorMode& colorMode) const; const gfx::ColorMode& colorMode) const;
std::optional<uint32_t> getSamplerLocation(const StringIdentity id) const override; std::optional<size_t> getSamplerLocation(const size_t id) const override;
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; } const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
@@ -74,7 +73,7 @@ protected:
MTLFunctionPtr fragmentFunction; MTLFunctionPtr fragmentFunction;
UniformBlockArray uniformBlocks; UniformBlockArray uniformBlocks;
VertexAttributeArray vertexAttributes; VertexAttributeArray vertexAttributes;
std::unordered_map<StringIdentity, std::size_t> textureBindings; std::array<std::optional<size_t>, shaders::maxTextureCountPerShader> textureBindings;
}; };
} // namespace mtl } // namespace mtl

View File

@@ -40,5 +40,73 @@ static constexpr auto maxUBOCountPerShader = std::max({static_cast<size_t>(backg
static_cast<size_t>(rasterUBOCount), static_cast<size_t>(rasterUBOCount),
static_cast<size_t>(symbolUBOCount)}); static_cast<size_t>(symbolUBOCount)});
enum {
idBackgroundImageTexture,
backgroundTextureCount
};
enum {
circleTextureCount
};
enum {
collisionTextureCount
};
enum {
idDebugOverlayTexture,
debugTextureCount
};
enum {
idFillExtrusionImageTexture,
fillExtrusionTextureCount
};
enum {
idFillImageTexture,
fillTextureCount
};
enum {
idHeatmapImageTexture,
idHeatmapColorRampTexture,
heatmapTextureCount
};
enum {
idHillshadeImageTexture,
hillshadeTextureCount
};
enum {
idLineImageTexture,
lineTextureCount
};
enum {
idRasterImage0Texture,
idRasterImage1Texture,
rasterTextureCount
};
enum {
idSymbolImageTexture,
idSymbolImageIconTexture,
symbolTextureCount
};
static constexpr auto maxTextureCountPerShader = std::max({static_cast<size_t>(backgroundTextureCount),
static_cast<size_t>(circleTextureCount),
static_cast<size_t>(collisionTextureCount),
static_cast<size_t>(debugTextureCount),
static_cast<size_t>(fillTextureCount),
static_cast<size_t>(fillExtrusionTextureCount),
static_cast<size_t>(heatmapTextureCount),
static_cast<size_t>(hillshadeTextureCount),
static_cast<size_t>(lineTextureCount),
static_cast<size_t>(rasterTextureCount),
static_cast<size_t>(symbolTextureCount)});
} // namespace shaders } // namespace shaders
} // namespace mbgl } // namespace mbgl

View File

@@ -33,7 +33,7 @@ public:
/// @brief Gets the sampler location /// @brief Gets the sampler location
/// @param name uniform name /// @param name uniform name
virtual std::optional<uint32_t> getSamplerLocation(const StringIdentity) const = 0; virtual std::optional<size_t> getSamplerLocation(const size_t) const = 0;
/// Get the available uniform blocks attached to this shader /// Get the available uniform blocks attached to this shader
virtual const gfx::UniformBlockArray& getUniformBlocks() const = 0; virtual const gfx::UniformBlockArray& getUniformBlocks() const = 0;

View File

@@ -45,17 +45,16 @@ void Drawable::setIndexData(std::vector<std::uint16_t> indexes, std::vector<Uniq
static const gfx::Texture2DPtr noTexture; static const gfx::Texture2DPtr noTexture;
const gfx::Texture2DPtr& Drawable::getTexture(int32_t location) const { const gfx::Texture2DPtr& Drawable::getTexture(size_t id) const {
const auto hit = textures.find(location); return (id < textures.size()) ? textures[id] : noTexture;
return (hit != textures.end()) ? hit->second : noTexture;
} }
void Drawable::setTexture(std::shared_ptr<gfx::Texture2D> texture, int32_t location) { void Drawable::setTexture(std::shared_ptr<gfx::Texture2D> texture, size_t id) {
textures.insert(std::make_pair(location, gfx::Texture2DPtr{})).first->second = std::move(texture); assert(id < textures.size());
} if (id >= textures.size()) {
return;
void Drawable::removeTexture(int32_t location) { }
textures.erase(location); textures[id] = std::move(texture);
} }
} // namespace gfx } // namespace gfx

View File

@@ -8,16 +8,9 @@
namespace mbgl { namespace mbgl {
namespace gfx { namespace gfx {
namespace {
std::optional<int> getSamplerLocation(const gfx::ShaderProgramBasePtr& shader,
const std::optional<StringIdentity>& nameId) {
return nameId ? shader->getSamplerLocation(*nameId) : std::nullopt;
}
} // namespace
void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable, const bool linearFilterForIcons) { void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable, const bool linearFilterForIcons) {
if (const auto& shader = drawable.getShader()) { if (const auto& shader = drawable.getShader()) {
if (const auto samplerLocation = getSamplerLocation(shader, glyphNameId)) { if (glyphTextureId) {
if (atlases) { if (atlases) {
atlases->glyph->setSamplerConfiguration( atlases->glyph->setSamplerConfiguration(
{TextureFilterType::Linear, TextureWrapType::Clamp, TextureWrapType::Clamp}); {TextureFilterType::Linear, TextureWrapType::Clamp, TextureWrapType::Clamp});
@@ -26,12 +19,12 @@ void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable, const bool l
TextureWrapType::Clamp, TextureWrapType::Clamp,
TextureWrapType::Clamp}); TextureWrapType::Clamp});
} }
if (const auto iconSamplerLocation = getSamplerLocation(shader, iconNameId)) { if (iconTextureId && shader->getSamplerLocation(*iconTextureId)) {
assert(*samplerLocation != *iconSamplerLocation); assert(*glyphTextureId != *iconTextureId);
drawable.setTexture(atlases ? atlases->glyph : nullptr, *samplerLocation); drawable.setTexture(atlases ? atlases->glyph : nullptr, *glyphTextureId);
drawable.setTexture(atlases ? atlases->icon : nullptr, *iconSamplerLocation); drawable.setTexture(atlases ? atlases->icon : nullptr, *iconTextureId);
} else { } else {
drawable.setTexture(atlases ? (isText ? atlases->glyph : atlases->icon) : nullptr, *samplerLocation); drawable.setTexture(atlases ? (isText ? atlases->glyph : atlases->icon) : nullptr, *glyphTextureId);
} }
} }
} }

View File

@@ -102,8 +102,18 @@ void DrawableBuilder::resetDrawPriority(DrawPriority value) {
} }
} }
void DrawableBuilder::setTexture(const std::shared_ptr<gfx::Texture2D>& texture, int32_t location) { static const gfx::Texture2DPtr noTexture;
textures.insert(std::make_pair(location, gfx::Texture2DPtr{})).first->second = std::move(texture);
const gfx::Texture2DPtr& DrawableBuilder::getTexture(size_t id) const {
return (id < textures.size()) ? textures[id] : noTexture;
}
void DrawableBuilder::setTexture(const std::shared_ptr<gfx::Texture2D>& texture, size_t id) {
assert(id < textures.size());
if (id >= textures.size()) {
return;
}
textures[id] = std::move(texture);
} }
void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) { void DrawableBuilder::addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {

View File

@@ -21,8 +21,7 @@ UniformBlockArray& UniformBlockArray::operator=(const UniformBlockArray& other)
} }
const std::unique_ptr<UniformBlock>& UniformBlockArray::get(const size_t id) const { const std::unique_ptr<UniformBlock>& UniformBlockArray::get(const size_t id) const {
const auto& result = (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref; return (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref;
return (result != nullptr) ? result : nullref;
} }
const std::unique_ptr<UniformBlock>& UniformBlockArray::set(const size_t id, const size_t index, std::size_t size) { const std::unique_ptr<UniformBlock>& UniformBlockArray::set(const size_t id, const size_t index, std::size_t size) {

View File

@@ -23,8 +23,7 @@ UniformBufferArray& UniformBufferArray::operator=(const UniformBufferArray& othe
} }
const std::shared_ptr<UniformBuffer>& UniformBufferArray::get(const size_t id) const { const std::shared_ptr<UniformBuffer>& UniformBufferArray::get(const size_t id) const {
const auto& result = (id < uniformBufferVector.size()) ? uniformBufferVector[id] : nullref; return (id < uniformBufferVector.size()) ? uniformBufferVector[id] : nullref;
return (result != nullptr) ? result : nullref;
} }
const std::shared_ptr<UniformBuffer>& UniformBufferArray::set(const size_t id, const std::shared_ptr<UniformBuffer>& UniformBufferArray::set(const size_t id,

View File

@@ -223,7 +223,7 @@ void DrawableGL::upload(gfx::UploadPass& uploadPass) {
} }
const bool texturesNeedUpload = std::any_of( const bool texturesNeedUpload = std::any_of(
textures.begin(), textures.end(), [](const auto& pair) { return pair.second && pair.second->needsUpload(); }); textures.begin(), textures.end(), [](const auto& texture) { return texture && texture->needsUpload(); });
if (texturesNeedUpload) { if (texturesNeedUpload) {
uploadTextures(); uploadTextures();
@@ -245,27 +245,28 @@ gfx::StencilMode DrawableGL::makeStencilMode(PaintParameters& parameters) const
} }
void DrawableGL::uploadTextures() const { void DrawableGL::uploadTextures() const {
for (const auto& pair : textures) { for (const auto& texture : textures) {
if (const auto& tex = pair.second) { if (texture) {
std::static_pointer_cast<gl::Texture2D>(tex)->upload(); texture->upload();
} }
} }
} }
void DrawableGL::bindTextures() const { void DrawableGL::bindTextures() const {
int32_t unit = 0; int32_t unit = 0;
for (const auto& pair : textures) { for (size_t id = 0; id < textures.size(); id++) {
if (const auto& tex = pair.second) { if (const auto& texture = textures[id]) {
const auto& location = pair.first; if (const auto& location = shader->getSamplerLocation(id)) {
std::static_pointer_cast<gl::Texture2D>(tex)->bind(location, unit++); static_cast<gl::Texture2D&>(*texture).bind(static_cast<int32_t>(*location), unit++);
}
} }
} }
} }
void DrawableGL::unbindTextures() const { void DrawableGL::unbindTextures() const {
for (const auto& pair : textures) { for (const auto& texture : textures) {
if (const auto& tex = pair.second) { if (texture) {
std::static_pointer_cast<gl::Texture2D>(tex)->unbind(); static_cast<gl::Texture2D&>(*texture).unbind();
} }
} }
} }

View File

@@ -43,7 +43,7 @@ void DrawableGLBuilder::init() {
drawableGL.setIndexData(std::move(impl->sharedIndexes), std::move(impl->segments)); drawableGL.setIndexData(std::move(impl->sharedIndexes), std::move(impl->segments));
impl->clear(); impl->clear();
textures.clear(); textures.fill(nullptr);
} }
} // namespace gl } // namespace gl

View File

@@ -386,27 +386,29 @@ void Drawable::bindUniformBuffers(RenderPass& renderPass) const noexcept {
} }
void Drawable::bindTextures(RenderPass& renderPass) const noexcept { void Drawable::bindTextures(RenderPass& renderPass) const noexcept {
for (const auto& pair : textures) { for (size_t id = 0; id < textures.size(); id++) {
if (const auto& tex = pair.second) { if (const auto& texture = textures[id]) {
const auto& location = pair.first; if (const auto& location = shader->getSamplerLocation(id)) {
static_cast<mtl::Texture2D&>(*tex).bind(renderPass, location); static_cast<mtl::Texture2D&>(*texture).bind(renderPass, static_cast<int32_t>(*location));
}
} }
} }
} }
void Drawable::unbindTextures(RenderPass& renderPass) const noexcept { void Drawable::unbindTextures(RenderPass& renderPass) const noexcept {
for (const auto& pair : textures) { for (size_t id = 0; id < textures.size(); id++) {
if (const auto& tex = pair.second) { if (const auto& texture = textures[id]) {
const auto& location = pair.first; if (const auto& location = shader->getSamplerLocation(id)) {
static_cast<mtl::Texture2D&>(*tex).unbind(renderPass, location); static_cast<mtl::Texture2D&>(*texture).unbind(renderPass, static_cast<int32_t>(*location));
}
} }
} }
} }
void Drawable::uploadTextures(UploadPass&) const noexcept { void Drawable::uploadTextures(UploadPass&) const noexcept {
for (const auto& pair : textures) { for (const auto& texture : textures) {
if (const auto& tex = pair.second) { if (texture) {
static_cast<mtl::Texture2D&>(*tex).upload(); texture->upload();
} }
} }
} }
@@ -584,7 +586,7 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
} }
const bool texturesNeedUpload = std::any_of( const bool texturesNeedUpload = std::any_of(
textures.begin(), textures.end(), [](const auto& pair) { return pair.second && pair.second->needsUpload(); }); textures.begin(), textures.end(), [](const auto& texture) { return texture && texture->needsUpload(); });
if (texturesNeedUpload) { if (texturesNeedUpload) {
uploadTextures(uploadPass); uploadTextures(uploadPass);

View File

@@ -42,7 +42,7 @@ void DrawableBuilder::init() {
drawable.setIndexData(std::move(impl->sharedIndexes), std::move(impl->segments)); drawable.setIndexData(std::move(impl->sharedIndexes), std::move(impl->segments));
impl->clear(); impl->clear();
textures.clear(); textures.fill(nullptr);
} }
} // namespace mtl } // namespace mtl

View File

@@ -9,7 +9,6 @@
#include <mbgl/shaders/shader_program_base.hpp> #include <mbgl/shaders/shader_program_base.hpp>
#include <mbgl/style/layers/background_layer_properties.hpp> #include <mbgl/style/layers/background_layer_properties.hpp>
#include <mbgl/util/convert.hpp> #include <mbgl/util/convert.hpp>
#include <mbgl/util/string_indexer.hpp>
namespace mbgl { namespace mbgl {
@@ -20,8 +19,6 @@ using namespace shaders;
constexpr auto BackgroundPatternShaderName = "BackgroundPatternShader"; constexpr auto BackgroundPatternShaderName = "BackgroundPatternShader";
#endif #endif
static const StringIdentity idTexUniformName = stringIndexer().get("u_image");
void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
const auto& state = parameters.state; const auto& state = parameters.state;
auto& context = parameters.context; auto& context = parameters.context;
@@ -53,7 +50,6 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara
// properties are re-evaluated every time // properties are re-evaluated every time
propertiesUpdated = false; propertiesUpdated = false;
std::optional<uint32_t> samplerLocation{};
visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) {
assert(drawable.getTileID()); assert(drawable.getTileID());
if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) {
@@ -61,9 +57,8 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara
} }
// We assume that drawables don't change between pattern and non-pattern. // We assume that drawables don't change between pattern and non-pattern.
const auto& shader = drawable.getShader(); assert(hasPattern == (drawable.getShader() ==
assert(hasPattern == context.getGenericShader(parameters.shaders, std::string(BackgroundPatternShaderName))));
(shader == context.getGenericShader(parameters.shaders, std::string(BackgroundPatternShaderName))));
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();
const auto matrix = getTileMatrix( const auto matrix = getTileMatrix(
@@ -75,17 +70,10 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara
uniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); uniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context);
if (hasPattern) { if (hasPattern) {
if (!samplerLocation.has_value()) { if (const auto& tex = parameters.patternAtlas.texture()) {
samplerLocation = shader->getSamplerLocation(idTexUniformName); tex->setSamplerConfiguration(
if (const auto& tex = parameters.patternAtlas.texture()) { {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
tex->setSamplerConfiguration( drawable.setTexture(tex, idBackgroundImageTexture);
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
}
}
if (samplerLocation.has_value()) {
if (const auto& tex = parameters.patternAtlas.texture()) {
drawable.setTexture(tex, samplerLocation.value());
}
} }
// from BackgroundPatternProgram::layoutUniformValues // from BackgroundPatternProgram::layoutUniformValues

View File

@@ -14,7 +14,6 @@
#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp> #include <mbgl/style/layers/fill_extrusion_layer_properties.hpp>
#include <mbgl/util/convert.hpp> #include <mbgl/util/convert.hpp>
#include <mbgl/util/std.hpp> #include <mbgl/util/std.hpp>
#include <mbgl/util/string_indexer.hpp>
#if MLN_RENDER_BACKEND_METAL #if MLN_RENDER_BACKEND_METAL
#include <mbgl/shaders/mtl/fill_extrusion.hpp> #include <mbgl/shaders/mtl/fill_extrusion.hpp>
@@ -26,11 +25,6 @@ namespace mbgl {
using namespace shaders; using namespace shaders;
using namespace style; using namespace style;
namespace {
const StringIdentity idTexImageName = stringIndexer().get("u_image");
} // namespace
void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context; auto& context = parameters.context;
const auto& props = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties); const auto& props = static_cast<const FillExtrusionLayerProperties&>(*evaluatedProperties);
@@ -95,12 +89,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP
const auto heightFactor = static_cast<float>(-numTiles / util::tileSize_D / 8.0); const auto heightFactor = static_cast<float>(-numTiles / util::tileSize_D / 8.0);
Size textureSize = {0, 0}; Size textureSize = {0, 0};
if (const auto shader = drawable.getShader()) { if (const auto& tex = drawable.getTexture(idFillExtrusionImageTexture)) {
if (const auto index = shader->getSamplerLocation(idTexImageName)) { textureSize = tex->getSize();
if (const auto& tex = drawable.getTexture(*index)) {
textureSize = tex->getSize();
}
}
} }
const FillExtrusionDrawableUBO drawableUBO = { const FillExtrusionDrawableUBO drawableUBO = {

View File

@@ -15,7 +15,6 @@
#include <mbgl/style/layers/fill_layer_properties.hpp> #include <mbgl/style/layers/fill_layer_properties.hpp>
#include <mbgl/util/convert.hpp> #include <mbgl/util/convert.hpp>
#include <mbgl/util/std.hpp> #include <mbgl/util/std.hpp>
#include <mbgl/util/string_indexer.hpp>
#if MLN_RENDER_BACKEND_METAL #if MLN_RENDER_BACKEND_METAL
#include <mbgl/shaders/mtl/fill.hpp> #include <mbgl/shaders/mtl/fill.hpp>
@@ -24,8 +23,6 @@
namespace mbgl { namespace mbgl {
using namespace style; using namespace style;
static const StringIdentity idTexImageName = stringIndexer().get("u_image");
using namespace shaders; using namespace shaders;
void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
@@ -135,12 +132,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
const int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; const int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y;
Size textureSize = {0, 0}; Size textureSize = {0, 0};
if (const auto shader = drawable.getShader()) { if (const auto& tex = drawable.getTexture(idFillImageTexture)) {
if (const auto index = shader->getSamplerLocation(idTexImageName)) { textureSize = tex->getSize();
if (const auto& tex = drawable.getTexture(*index)) {
textureSize = tex->getSize();
}
}
} }
auto& uniforms = drawable.mutableUniformBuffers(); auto& uniforms = drawable.mutableUniformBuffers();

View File

@@ -3,7 +3,6 @@
#include <mbgl/gfx/context.hpp> #include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/drawable.hpp> #include <mbgl/gfx/drawable.hpp>
#include <mbgl/gfx/line_drawable_data.hpp> #include <mbgl/gfx/line_drawable_data.hpp>
#include <mbgl/util/string_indexer.hpp>
#include <mbgl/geometry/line_atlas.hpp> #include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/renderer/image_atlas.hpp> #include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/renderer/layer_group.hpp> #include <mbgl/renderer/layer_group.hpp>
@@ -25,8 +24,6 @@ namespace mbgl {
using namespace style; using namespace style;
using namespace shaders; using namespace shaders;
static const StringIdentity idTexImageName = stringIndexer().get("u_image");
void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context; auto& context = parameters.context;
const auto zoom = parameters.state.getZoom(); const auto zoom = parameters.state.getZoom();
@@ -164,10 +161,8 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
case LineType::Pattern: { case LineType::Pattern: {
Size textureSize{0, 0}; Size textureSize{0, 0};
if (const auto index = shader->getSamplerLocation(idTexImageName)) { if (const auto& texture = drawable.getTexture(idLineImageTexture)) {
if (const auto& texture = drawable.getTexture(index.value())) { textureSize = texture->getSize();
textureSize = texture->getSize();
}
} }
const LinePatternUBO linePatternUBO{ const LinePatternUBO linePatternUBO{
/*matrix =*/util::cast<float>(matrix), /*matrix =*/util::cast<float>(matrix),
@@ -198,13 +193,11 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters
lineData.linePatternCap); lineData.linePatternCap);
// texture // texture
if (const auto index = shader->getSamplerLocation(idTexImageName)) { if (!drawable.getTexture(idLineImageTexture)) {
if (!drawable.getTexture(index.value())) { const auto& texture = dashPatternTexture.getTexture();
const auto& texture = dashPatternTexture.getTexture(); drawable.setEnabled(!!texture);
drawable.setEnabled(!!texture); if (texture) {
if (texture) { drawable.setTexture(texture, idLineImageTexture);
drawable.setTexture(texture, index.value());
}
} }
} }

View File

@@ -42,8 +42,6 @@ namespace {
const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); const StringIdentity idPosAttribName = stringIndexer().get("a_pos");
const StringIdentity idNormAttribName = stringIndexer().get("a_normal_ed"); const StringIdentity idNormAttribName = stringIndexer().get("a_normal_ed");
const StringIdentity idIconTextureName = stringIndexer().get("u_image");
#endif // MLN_DRAWABLE_RENDERER #endif // MLN_DRAWABLE_RENDERER
inline const FillExtrusionLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) { inline const FillExtrusionLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
@@ -460,7 +458,7 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders,
if (const auto& atlases = tile.getAtlasTextures()) { if (const auto& atlases = tile.getAtlasTextures()) {
tweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases, tweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
std::nullopt, std::nullopt,
idIconTextureName, idFillExtrusionImageTexture,
/*isText=*/false, /*isText=*/false,
false, false,
style::AlignmentType::Auto, style::AlignmentType::Auto,

View File

@@ -51,7 +51,6 @@ constexpr auto FillPatternShaderName = "FillPatternShader";
constexpr auto FillOutlinePatternShaderName = "FillOutlinePatternShader"; constexpr auto FillOutlinePatternShaderName = "FillOutlinePatternShader";
const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); const StringIdentity idPosAttribName = stringIndexer().get("a_pos");
const StringIdentity idIconTextureName = stringIndexer().get("u_image");
#endif // MLN_DRAWABLE_RENDERER #endif // MLN_DRAWABLE_RENDERER
inline const FillLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) { inline const FillLayer::Impl& impl_cast(const Immutable<style::Layer::Impl>& impl) {
@@ -598,7 +597,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
atlasTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>( atlasTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(
atlases, atlases,
std::nullopt, std::nullopt,
idIconTextureName, idFillImageTexture,
/*isText*/ false, /*isText*/ false,
/*sdfIcons*/ true, // to force linear filter /*sdfIcons*/ true, // to force linear filter
/*rotationAlignment_*/ AlignmentType::Auto, /*rotationAlignment_*/ AlignmentType::Auto,

View File

@@ -279,8 +279,6 @@ constexpr auto HeatmapShaderGroupName = "HeatmapShader";
constexpr auto HeatmapTextureShaderGroupName = "HeatmapTextureShader"; constexpr auto HeatmapTextureShaderGroupName = "HeatmapTextureShader";
const StringIdentity idVertexAttribName = stringIndexer().get("a_pos"); const StringIdentity idVertexAttribName = stringIndexer().get("a_pos");
const StringIdentity idTexImageName = stringIndexer().get("u_image");
const StringIdentity idTexColorRampName = stringIndexer().get("u_color_ramp");
} // namespace } // namespace
@@ -529,18 +527,13 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
heatmapTextureBuilder->setSegments( heatmapTextureBuilder->setSegments(
gfx::Triangles(), RenderStaticData::quadTriangleIndices().vector(), segments.data(), segments.size()); gfx::Triangles(), RenderStaticData::quadTriangleIndices().vector(), segments.data(), segments.size());
auto imageLocation = heatmapTextureShader->getSamplerLocation(idTexImageName); heatmapTextureBuilder->setTexture(renderTarget->getTexture(), idHeatmapImageTexture);
if (imageLocation.has_value()) {
heatmapTextureBuilder->setTexture(renderTarget->getTexture(), imageLocation.value()); std::shared_ptr<gfx::Texture2D> texture = context.createTexture2D();
} texture->setImage(colorRamp);
auto colorRampLocation = heatmapTextureShader->getSamplerLocation(idTexColorRampName); texture->setSamplerConfiguration(
if (colorRampLocation.has_value()) { {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
std::shared_ptr<gfx::Texture2D> texture = context.createTexture2D(); heatmapTextureBuilder->setTexture(std::move(texture), idHeatmapColorRampTexture);
texture->setImage(colorRamp);
texture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
heatmapTextureBuilder->setTexture(std::move(texture), colorRampLocation.value());
}
heatmapTextureBuilder->flush(context); heatmapTextureBuilder->flush(context);

View File

@@ -30,6 +30,7 @@
namespace mbgl { namespace mbgl {
using namespace style; using namespace style;
using namespace shaders;
namespace { namespace {
@@ -296,7 +297,6 @@ static const std::string HillshadeShaderGroupName = "HillshadeShader";
static const StringIdentity idPosAttribName = stringIndexer().get("a_pos"); static const StringIdentity idPosAttribName = stringIndexer().get("a_pos");
static const StringIdentity idTexturePosAttribName = stringIndexer().get("a_texture_pos"); static const StringIdentity idTexturePosAttribName = stringIndexer().get("a_texture_pos");
static const StringIdentity idTexImageName = stringIndexer().get("u_image");
void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders, void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context, gfx::Context& context,
@@ -336,10 +336,6 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
return; return;
} }
if (!hillshadeImageLocation) {
hillshadeImageLocation = hillshadeShader->getSamplerLocation(idTexImageName);
}
auto renderPass = RenderPass::Translucent; auto renderPass = RenderPass::Translucent;
if (!(mbgl::underlying_type(renderPass) & evaluatedProperties->renderPasses)) { if (!(mbgl::underlying_type(renderPass) & evaluatedProperties->renderPasses)) {
return; return;
@@ -433,14 +429,11 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
hillshadePrepareBuilder->setSegments( hillshadePrepareBuilder->setSegments(
gfx::Triangles(), staticDataIndices.vector(), staticDataSegments.data(), staticDataSegments.size()); gfx::Triangles(), staticDataIndices.vector(), staticDataSegments.data(), staticDataSegments.size());
auto imageLocation = hillshadePrepareShader->getSamplerLocation(idTexImageName); std::shared_ptr<gfx::Texture2D> texture = context.createTexture2D();
if (imageLocation.has_value()) { texture->setImage(bucket.getDEMData().getImagePtr());
std::shared_ptr<gfx::Texture2D> texture = context.createTexture2D(); texture->setSamplerConfiguration(
texture->setImage(bucket.getDEMData().getImagePtr()); {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
texture->setSamplerConfiguration( hillshadePrepareBuilder->setTexture(texture, idHillshadeImageTexture);
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
hillshadePrepareBuilder->setTexture(texture, imageLocation.value());
}
hillshadePrepareBuilder->flush(context); hillshadePrepareBuilder->flush(context);
@@ -515,10 +508,7 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
drawSegments.emplace_back(hillshadeBuilder->createSegment(gfx::Triangles(), std::move(segCopy))); drawSegments.emplace_back(hillshadeBuilder->createSegment(gfx::Triangles(), std::move(segCopy)));
} }
drawable.setIndexData(indices->vector(), std::move(drawSegments)); drawable.setIndexData(indices->vector(), std::move(drawSegments));
drawable.setTexture(bucket.renderTarget->getTexture(), idHillshadeImageTexture);
if (hillshadeImageLocation) {
drawable.setTexture(bucket.renderTarget->getTexture(), *hillshadeImageLocation);
}
return true; return true;
}; };
if (updateTile(renderPass, tileID, std::move(updateExisting))) { if (updateTile(renderPass, tileID, std::move(updateExisting))) {
@@ -533,10 +523,7 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
hillshadeBuilder->setVertexAttributes(buildVertexAttributes()); hillshadeBuilder->setVertexAttributes(buildVertexAttributes());
hillshadeBuilder->setRawVertices({}, vertices->elements(), gfx::AttributeDataType::Short2); hillshadeBuilder->setRawVertices({}, vertices->elements(), gfx::AttributeDataType::Short2);
hillshadeBuilder->setSegments(gfx::Triangles(), indices->vector(), segments->data(), segments->size()); hillshadeBuilder->setSegments(gfx::Triangles(), indices->vector(), segments->data(), segments->size());
hillshadeBuilder->setTexture(bucket.renderTarget->getTexture(), idHillshadeImageTexture);
if (hillshadeImageLocation) {
hillshadeBuilder->setTexture(bucket.renderTarget->getTexture(), *hillshadeImageLocation);
}
hillshadeBuilder->flush(context); hillshadeBuilder->flush(context);

View File

@@ -75,7 +75,6 @@ private:
#if MLN_DRAWABLE_RENDERER #if MLN_DRAWABLE_RENDERER
gfx::ShaderProgramBasePtr hillshadePrepareShader; gfx::ShaderProgramBasePtr hillshadePrepareShader;
gfx::ShaderProgramBasePtr hillshadeShader; gfx::ShaderProgramBasePtr hillshadeShader;
std::optional<int> hillshadeImageLocation;
std::vector<RenderTargetPtr> activatedRenderTargets; std::vector<RenderTargetPtr> activatedRenderTargets;
using HillshadeVertexVector = gfx::VertexVector<HillshadeLayoutVertex>; using HillshadeVertexVector = gfx::VertexVector<HillshadeLayoutVertex>;

View File

@@ -345,8 +345,6 @@ float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature,
} }
#if MLN_DRAWABLE_RENDERER #if MLN_DRAWABLE_RENDERER
static const StringIdentity idLineImageUniformName = stringIndexer().get("u_image");
void RenderLineLayer::update(gfx::ShaderRegistry& shaders, void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context, gfx::Context& context,
const TransformState& state, const TransformState& state,
@@ -679,7 +677,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>( iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(
atlases, atlases,
std::nullopt, std::nullopt,
idLineImageUniformName, idLineImageTexture,
/*isText*/ false, /*isText*/ false,
/*sdfIcons*/ true, // to force linear filter /*sdfIcons*/ true, // to force linear filter
/*rotationAlignment_*/ AlignmentType::Auto, /*rotationAlignment_*/ AlignmentType::Auto,
@@ -727,33 +725,31 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
addAttributes(*builder, bucket, std::move(vertexAttrs)); addAttributes(*builder, bucket, std::move(vertexAttrs));
// texture // texture
if (const auto samplerLocation = builder->getShader()->getSamplerLocation(idLineImageUniformName)) { if (!colorRampTexture2D && colorRamp->valid()) {
if (!colorRampTexture2D && colorRamp->valid()) { // create texture. to be reused for all the tiles of the layer
// create texture. to be reused for all the tiles of the layer colorRampTexture2D = context.createTexture2D();
colorRampTexture2D = context.createTexture2D(); colorRampTexture2D->setImage(colorRamp);
colorRampTexture2D->setImage(colorRamp); colorRampTexture2D->setSamplerConfiguration(
colorRampTexture2D->setSamplerConfiguration( {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp}); }
}
if (colorRampTexture2D) { if (colorRampTexture2D) {
builder->setTexture(colorRampTexture2D, samplerLocation.value()); builder->setTexture(colorRampTexture2D, idLineImageTexture);
// segments // segments
setSegments(builder, bucket); setSegments(builder, bucket);
// finish // finish
builder->flush(context); builder->flush(context);
for (auto& drawable : builder->clearDrawables()) { for (auto& drawable : builder->clearDrawables()) {
drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::Gradient)); drawable->setType(mbgl::underlying_type(LineLayerTweaker::LineType::Gradient));
drawable->setTileID(tileID); drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker); drawable->setLayerTweaker(layerTweaker);
drawable->mutableUniformBuffers().createOrUpdate( drawable->mutableUniformBuffers().createOrUpdate(
idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context); idLineGradientInterpolationUBO, &getLineGradientInterpolationUBO(), context);
tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
++stats.drawablesAdded; ++stats.drawablesAdded;
}
} }
} }
} else { } else {

View File

@@ -26,6 +26,7 @@
namespace mbgl { namespace mbgl {
using namespace style; using namespace style;
using namespace shaders;
namespace { namespace {
@@ -273,8 +274,6 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
if (!rasterShader) { if (!rasterShader) {
return; return;
} }
rasterSampler0 = rasterShader->getSamplerLocation(idTexImage0Name);
rasterSampler1 = rasterShader->getSamplerLocation(idTexImage1Name);
} }
if (!layerTweaker) { if (!layerTweaker) {
@@ -311,7 +310,7 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
}; };
const auto setTextures = [&](gfx::UniqueDrawableBuilder& builder, RasterBucket& bucket) { const auto setTextures = [&](gfx::UniqueDrawableBuilder& builder, RasterBucket& bucket) {
if (bucket.image && (rasterSampler0 || rasterSampler1)) { if (bucket.image) {
if (!bucket.texture2d) { if (!bucket.texture2d) {
if (auto tex = context.createTexture2D()) { if (auto tex = context.createTexture2D()) {
tex->setImage(bucket.image); tex->setImage(bucket.image);
@@ -327,12 +326,8 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
bucket.texture2d->setSamplerConfiguration( bucket.texture2d->setSamplerConfiguration(
{filter, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp}); {filter, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
if (rasterSampler0) { builder->setTexture(bucket.texture2d, idRasterImage0Texture);
builder->setTexture(bucket.texture2d, *rasterSampler0); builder->setTexture(bucket.texture2d, idRasterImage1Texture);
}
if (rasterSampler1) {
builder->setTexture(bucket.texture2d, *rasterSampler1);
}
} }
} }
}; };
@@ -498,7 +493,8 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
builder = createBuilder(); builder = createBuilder();
} }
if (bucket.image && builder->getTextures().size() == 0) { if (bucket.image && !builder->getTexture(idRasterImage0Texture) &&
!builder->getTexture(idRasterImage1Texture)) {
setTextures(builder, bucket); setTextures(builder, bucket);
}; };

View File

@@ -66,8 +66,6 @@ private:
#if MLN_DRAWABLE_RENDERER #if MLN_DRAWABLE_RENDERER
gfx::ShaderProgramBasePtr rasterShader; gfx::ShaderProgramBasePtr rasterShader;
std::optional<uint32_t> rasterSampler0;
std::optional<uint32_t> rasterSampler1;
LayerGroupPtr imageLayerGroup; LayerGroupPtr imageLayerGroup;
using RasterVertexVector = gfx::VertexVector<RasterLayoutVertex>; using RasterVertexVector = gfx::VertexVector<RasterLayoutVertex>;

View File

@@ -766,8 +766,6 @@ const auto idPosOffsetAttribName = stringIndexer().get(posOffsetAttribName);
const auto idPixOffsetAttribName = stringIndexer().get("a_pixeloffset"); const auto idPixOffsetAttribName = stringIndexer().get("a_pixeloffset");
const auto idProjPosAttribName = stringIndexer().get("a_projected_pos"); const auto idProjPosAttribName = stringIndexer().get("a_projected_pos");
const auto idFadeOpacityAttribName = stringIndexer().get("a_fade_opacity"); const auto idFadeOpacityAttribName = stringIndexer().get("a_fade_opacity");
const auto idTexUniformName = stringIndexer().get("u_texture");
const auto idTexIconUniformName = stringIndexer().get("u_texture_icon");
void updateTileAttributes(const SymbolBucket::Buffer& buffer, void updateTileAttributes(const SymbolBucket::Buffer& buffer,
const bool isText, const bool isText,
@@ -1293,8 +1291,8 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
const bool textSizeIsZoomConstant = const bool textSizeIsZoomConstant =
bucket.textSizeBinder->evaluateForZoom(static_cast<float>(state.getZoom())).isZoomConstant; bucket.textSizeBinder->evaluateForZoom(static_cast<float>(state.getZoom())).isZoomConstant;
tileInfo.textTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases, tileInfo.textTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
idTexIconUniformName, idSymbolImageIconTexture,
idTexUniformName, idSymbolImageTexture,
isText, isText,
false, false,
values.rotationAlignment, values.rotationAlignment,
@@ -1304,8 +1302,8 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
if (!isText && !tileInfo.iconTweaker) { if (!isText && !tileInfo.iconTweaker) {
const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear; const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear;
tileInfo.iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases, tileInfo.iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
idTexIconUniformName, idSymbolImageIconTexture,
idTexUniformName, idSymbolImageTexture,
isText, isText,
sdfIcons, sdfIcons,
values.rotationAlignment, values.rotationAlignment,

View File

@@ -29,13 +29,9 @@ using namespace shaders;
namespace { namespace {
Size getTexSize(const gfx::Drawable& drawable, const StringIdentity nameId) { Size getTexSize(const gfx::Drawable& drawable, const size_t texId) {
if (const auto& shader = drawable.getShader()) { if (const auto& tex = drawable.getTexture(texId)) {
if (const auto index = shader->getSamplerLocation(nameId)) { return tex->getSize();
if (const auto& tex = drawable.getTexture(*index)) {
return tex->getSize();
}
}
} }
return {0, 0}; return {0, 0};
} }
@@ -44,9 +40,6 @@ std::array<float, 2> toArray(const Size& s) {
return util::cast<float>(std::array<uint32_t, 2>{s.width, s.height}); return util::cast<float>(std::array<uint32_t, 2>{s.width, s.height});
} }
const StringIdentity idTexUniformName = stringIndexer().get("u_texture");
const StringIdentity idTexIconUniformName = stringIndexer().get("u_texture_icon");
SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::PossiblyEvaluated& evaluated) { SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::PossiblyEvaluated& evaluated) {
return { return {
/*.fill_color=*/isText ? constOrDefault<TextColor>(evaluated) : constOrDefault<IconColor>(evaluated), /*.fill_color=*/isText ? constOrDefault<TextColor>(evaluated) : constOrDefault<IconColor>(evaluated),
@@ -152,8 +145,8 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
/*.label_plane_matrix=*/util::cast<float>(labelPlaneMatrix), /*.label_plane_matrix=*/util::cast<float>(labelPlaneMatrix),
/*.coord_matrix=*/util::cast<float>(glCoordMatrix), /*.coord_matrix=*/util::cast<float>(glCoordMatrix),
/*.texsize=*/toArray(getTexSize(drawable, idTexUniformName)), /*.texsize=*/toArray(getTexSize(drawable, idSymbolImageTexture)),
/*.texsize_icon=*/toArray(getTexSize(drawable, idTexIconUniformName)), /*.texsize_icon=*/toArray(getTexSize(drawable, idSymbolImageIconTexture)),
/*.gamma_scale=*/gammaScale, /*.gamma_scale=*/gammaScale,
/*.rotate_symbol=*/rotateInShader, /*.rotate_symbol=*/rotateInShader,

View File

@@ -131,18 +131,13 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr
// create texture. to be reused for all the tiles of the debug layers // create texture. to be reused for all the tiles of the debug layers
auto texture = context.createTexture2D(); auto texture = context.createTexture2D();
std::optional<uint32_t> samplerLocation;
{ {
std::array<uint8_t, 4> data{{0, 0, 0, 0}}; std::array<uint8_t, 4> data{{0, 0, 0, 0}};
auto emptyImage = std::make_shared<PremultipliedImage>(Size(1, 1), data.data(), data.size()); auto emptyImage = std::make_shared<PremultipliedImage>(Size(1, 1), data.data(), data.size());
texture->setImage(emptyImage); texture->setImage(emptyImage);
texture->setSamplerConfiguration( texture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp}); {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp});
static const StringIdentity idDebugOverlayUniformName = stringIndexer().get("u_overlay");
samplerLocation = debugShader->getSamplerLocation(idDebugOverlayUniformName);
} }
assert(samplerLocation.has_value());
if (!samplerLocation.has_value()) return;
// function to update existing tile drawables with UBO value. return number of updated drawables // function to update existing tile drawables with UBO value. return number of updated drawables
const auto updateDrawables = const auto updateDrawables =
@@ -172,7 +167,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr
debugBuilder->addVertices(verts, 0, verts.size()); debugBuilder->addVertices(verts, 0, verts.size());
debugBuilder->setSegments(mode, indexes, segments.data(), segments.size()); debugBuilder->setSegments(mode, indexes, segments.data(), segments.size());
// texture // texture
debugBuilder->setTexture(texture, samplerLocation.value()); debugBuilder->setTexture(texture, idDebugOverlayTexture);
// finish // finish
debugBuilder->flush(context); debugBuilder->flush(context);

View File

@@ -1,6 +1,6 @@
#include <mbgl/shaders/gl/shader_info.hpp> #include <mbgl/shaders/gl/shader_info.hpp>
#include <mbgl/shaders/ubo_max_count.hpp> #include <mbgl/shaders/shader_defines.hpp>
namespace mbgl { namespace mbgl {
namespace shaders { namespace shaders {
@@ -10,51 +10,76 @@ UniformBlockInfo::UniformBlockInfo(std::string_view name_, std::size_t id_)
id(id_), id(id_),
binding(id_) {} binding(id_) {}
TextureInfo::TextureInfo(std::string_view name_, std::size_t id_)
: name(name_),
id(id_) {}
// Background
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO},
UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL>::textures = {};
// Background Pattern
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO},
UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idBackgroundImageTexture},
};
// Circle
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO},
UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO}, UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO},
UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO},
UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL>::textures = {};
// Collision Box
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL>::uniformBlocks = const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL>::uniformBlocks =
{ {
UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO}, UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL>::textures = {};
// Collision Circle
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO}, UniformBlockInfo{"CollisionCircleUBO", idCollisionUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL>::textures = {};
// Debug
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"DebugUBO", idDebugUBO}, UniformBlockInfo{"DebugUBO", idDebugUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_overlay", idDebugOverlayTexture},
};
// Fill
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO},
UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO},
UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO}, UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL>::textures = {};
// Fill Outline
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL>::uniformBlocks = const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL>::uniformBlocks =
{ {
UniformBlockInfo{"FillOutlineDrawableUBO", idFillOutlineDrawableUBO}, UniformBlockInfo{"FillOutlineDrawableUBO", idFillOutlineDrawableUBO},
UniformBlockInfo{"FillOutlineEvaluatedPropsUBO", idFillOutlineEvaluatedPropsUBO}, UniformBlockInfo{"FillOutlineEvaluatedPropsUBO", idFillOutlineEvaluatedPropsUBO},
UniformBlockInfo{"FillOutlineInterpolateUBO", idFillOutlineInterpolateUBO}, UniformBlockInfo{"FillOutlineInterpolateUBO", idFillOutlineInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL>::textures = {};
// Fill Pattern
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks =
{ {
UniformBlockInfo{"FillPatternDrawableUBO", idFillPatternDrawableUBO}, UniformBlockInfo{"FillPatternDrawableUBO", idFillPatternDrawableUBO},
@@ -62,7 +87,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillPatternShader, gfx::
UniformBlockInfo{"FillPatternEvaluatedPropsUBO", idFillPatternEvaluatedPropsUBO}, UniformBlockInfo{"FillPatternEvaluatedPropsUBO", idFillPatternEvaluatedPropsUBO},
UniformBlockInfo{"FillPatternInterpolateUBO", idFillPatternInterpolateUBO}, UniformBlockInfo{"FillPatternInterpolateUBO", idFillPatternInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idFillImageTexture},
};
// Fill Outline Pattern
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillOutlinePatternDrawableUBO}, UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillOutlinePatternDrawableUBO},
@@ -70,7 +99,11 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillOutlinePatternEvaluatedPropsUBO", idFillOutlinePatternEvaluatedPropsUBO}, UniformBlockInfo{"FillOutlinePatternEvaluatedPropsUBO", idFillOutlinePatternEvaluatedPropsUBO},
UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillOutlinePatternInterpolateUBO}, UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillOutlinePatternInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idFillImageTexture},
};
// Fill Extrusion
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO},
@@ -78,7 +111,9 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO},
UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL>::textures = {};
// Fill Extrusion Pattern
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO},
@@ -86,28 +121,47 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO}, UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO},
UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idFillExtrusionImageTexture},
};
// Heatmap
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO}, UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO},
UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO}, UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO},
UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO}, UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL>::textures = {};
// Heatmap Texture
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"HeatmapTextureDrawableUBO", idHeatmapTextureDrawableUBO}, UniformBlockInfo{"HeatmapTextureDrawableUBO", idHeatmapTextureDrawableUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idHeatmapImageTexture},
TextureInfo{"u_color_ramp", idHeatmapColorRampTexture},
};
// Hillshade Prepare
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idHillshadeImageTexture},
};
// Hillshade
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO}, UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO},
UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO}, UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idHillshadeImageTexture},
};
// Line Gradient
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL>::uniformBlocks = const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL>::uniformBlocks =
{ {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
@@ -115,7 +169,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineGradientShader, gfx:
UniformBlockInfo{"LineGradientPropertiesUBO", idLineGradientPropertiesUBO}, UniformBlockInfo{"LineGradientPropertiesUBO", idLineGradientPropertiesUBO},
UniformBlockInfo{"LineGradientInterpolationUBO", idLineGradientInterpolationUBO}, UniformBlockInfo{"LineGradientInterpolationUBO", idLineGradientInterpolationUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::LineGradientShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idLineImageTexture},
};
// Line Pattern
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks =
{ {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
@@ -124,30 +182,47 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LinePatternShader, gfx::
UniformBlockInfo{"LinePatternInterpolationUBO", idLinePatternInterpolationUBO}, UniformBlockInfo{"LinePatternInterpolationUBO", idLinePatternInterpolationUBO},
UniformBlockInfo{"LinePatternTilePropertiesUBO", idLinePatternTilePropertiesUBO}, UniformBlockInfo{"LinePatternTilePropertiesUBO", idLinePatternTilePropertiesUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::LinePatternShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idLineImageTexture},
};
// Line SDF
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
UniformBlockInfo{"LineSDFUBO", idLineSDFUBO}, UniformBlockInfo{"LineSDFUBO", idLineSDFUBO},
UniformBlockInfo{"LineSDFPropertiesUBO", idLineSDFPropertiesUBO}, UniformBlockInfo{"LineSDFPropertiesUBO", idLineSDFPropertiesUBO},
UniformBlockInfo{"LineSDFInterpolationUBO", idLineSDFInterpolationUBO}, UniformBlockInfo{"LineSDFInterpolationUBO", idLineSDFInterpolationUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::LineSDFShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image", idLineImageTexture},
};
// Line
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO}, UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
UniformBlockInfo{"LineUBO", idLineUBO}, UniformBlockInfo{"LineUBO", idLineUBO},
UniformBlockInfo{"LinePropertiesUBO", idLinePropertiesUBO}, UniformBlockInfo{"LinePropertiesUBO", idLinePropertiesUBO},
UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::LineShader, gfx::Backend::Type::OpenGL>::textures = {};
// Line Basic
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineBasicShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineBasicShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"LineBasicUBO", idLineBasicUBO}, UniformBlockInfo{"LineBasicUBO", idLineBasicUBO},
UniformBlockInfo{"LineBasicPropertiesUBO", idLineBasicPropertiesUBO}, UniformBlockInfo{"LineBasicPropertiesUBO", idLineBasicPropertiesUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::LineBasicShader, gfx::Backend::Type::OpenGL>::textures = {};
// Raster
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO}, UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_image0", idRasterImage0Texture},
TextureInfo{"u_image1", idRasterImage0Texture},
};
// Symbol Icon
const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO}, UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO},
@@ -155,7 +230,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::SymbolIconShader, gfx::B
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_texture", idSymbolImageTexture},
};
// Symbol SDF
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
@@ -164,7 +243,11 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_texture", idSymbolImageTexture},
};
// Symbol Text & Icon
const std::vector<UniformBlockInfo> const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = { ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
@@ -173,6 +256,10 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO}, UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO}, UniformBlockInfo{"SymbolDrawableInterpolateUBO", idSymbolDrawableInterpolateUBO},
}; };
const std::vector<TextureInfo> ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL>::textures = {
TextureInfo{"u_texture", idSymbolImageTexture},
TextureInfo{"u_texture_icon", idSymbolImageIconTexture},
};
} // namespace shaders } // namespace shaders
} // namespace mbgl } // namespace mbgl

View File

@@ -91,7 +91,7 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_)
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program, ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
UniformBlockArrayGL&& uniformBlocks_, UniformBlockArrayGL&& uniformBlocks_,
VertexAttributeArrayGL&& attributes_, VertexAttributeArrayGL&& attributes_,
SamplerLocationMap&& samplerLocations_) SamplerLocationArray&& samplerLocations_)
: ShaderProgramBase(), : ShaderProgramBase(),
glProgram(std::move(program)), glProgram(std::move(program)),
uniformBlocks(std::move(uniformBlocks_)), uniformBlocks(std::move(uniformBlocks_)),
@@ -105,20 +105,16 @@ ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other)
vertexAttributes(std::move(other.vertexAttributes)), vertexAttributes(std::move(other.vertexAttributes)),
samplerLocations(std::move(other.samplerLocations)) {} samplerLocations(std::move(other.samplerLocations)) {}
std::optional<uint32_t> ShaderProgramGL::getSamplerLocation(const StringIdentity id) const { std::optional<size_t> ShaderProgramGL::getSamplerLocation(const size_t id) const {
std::optional<uint32_t> result{}; return (id < samplerLocations.size()) ? samplerLocations[id] : std::nullopt;
if (auto it = samplerLocations.find(id); it != samplerLocations.end()) {
result = it->second;
}
return result;
} }
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create( std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
Context& context, Context& context,
const ProgramParameters& programParameters, const ProgramParameters& programParameters,
const std::string& /*name*/,
const std::string_view firstAttribName, const std::string_view firstAttribName,
const std::vector<shaders::UniformBlockInfo>& uniformBlocksInfo, const std::vector<shaders::UniformBlockInfo>& uniformBlocksInfo,
const std::vector<shaders::TextureInfo>& texturesInfo,
const std::string& vertexSource, const std::string& vertexSource,
const std::string& fragmentSource, const std::string& fragmentSource,
const std::string& additionalDefines) noexcept(false) { const std::string& additionalDefines) noexcept(false) {
@@ -140,17 +136,7 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
fragmentSource.c_str()}); fragmentSource.c_str()});
auto program = context.createProgram(vertProg, fragProg, firstAttribName.data()); auto program = context.createProgram(vertProg, fragProg, firstAttribName.data());
// GLES3.1
// GLint numAttribs;
// glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
UniformBlockArrayGL uniformBlocks; UniformBlockArrayGL uniformBlocks;
GLint count = 0;
GLint maxLength = 0;
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &count));
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &maxLength));
for (const auto& blockInfo : uniformBlocksInfo) { for (const auto& blockInfo : uniformBlocksInfo) {
GLint index = MBGL_CHECK_ERROR(glGetUniformBlockIndex(program, blockInfo.name.data())); GLint index = MBGL_CHECK_ERROR(glGetUniformBlockIndex(program, blockInfo.name.data()));
GLint size = 0; GLint size = 0;
@@ -161,34 +147,21 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
uniformBlocks.set(blockInfo.id, binding, size); uniformBlocks.set(blockInfo.id, binding, size);
} }
SamplerLocationMap samplerLocations; SamplerLocationArray samplerLocations;
GLint numActiveUniforms = 0; for (const auto& textureInfo : texturesInfo) {
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numActiveUniforms)); GLint location = MBGL_CHECK_ERROR(glGetUniformLocation(program, textureInfo.name.data()));
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); assert(location != -1);
auto name = std::vector<GLchar>(maxLength); if (location != -1) {
for (GLint index = 0; index < numActiveUniforms; ++index) { samplerLocations[textureInfo.id] = location;
GLsizei actualLength = 0;
GLint size = 0;
GLenum type = GL_ZERO;
MBGL_CHECK_ERROR(glGetActiveUniform(program, index, maxLength, &actualLength, &size, &type, name.data()));
if (type == GL_SAMPLER_2D) {
// This uniform is a texture sampler
GLint location = MBGL_CHECK_ERROR(glGetUniformLocation(program, name.data()));
assert(location != -1);
if (location != -1) {
samplerLocations[stringIndexer().get(name.data())] = location;
}
} }
} }
VertexAttributeArrayGL attrs; VertexAttributeArrayGL attrs;
GLint count = 0;
count = 0; GLint maxLength = 0;
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count)); MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count));
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength)); MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength));
name.resize(maxLength); auto name = std::vector<GLchar>(maxLength);
for (GLint index = 0; index < count; ++index) { for (GLint index = 0; index < count; ++index) {
GLsizei length = 0; // "number of characters actually written in name (excluding the null terminator)" GLsizei length = 0; // "number of characters actually written in name (excluding the null terminator)"
GLint size = 0; // "size of the attribute variable, in units of the type returned in type" GLint size = 0; // "size of the attribute variable, in units of the type returned in type"

View File

@@ -14,7 +14,7 @@ const std::array<UniformBlockInfo, 2>
UniformBlockInfo{2, true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, UniformBlockInfo{2, true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}}; TextureInfo{0, idBackgroundImageTexture}};
} // namespace shaders } // namespace shaders
} // namespace mbgl } // namespace mbgl

View File

@@ -10,7 +10,7 @@ const std::array<UniformBlockInfo, 1> ShaderSource<BuiltIn::DebugShader, gfx::Ba
UniformBlockInfo{1, true, true, sizeof(DebugUBO), idDebugUBO}, UniformBlockInfo{1, true, true, sizeof(DebugUBO), idDebugUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_overlay"}, TextureInfo{0, idDebugOverlayTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -40,7 +40,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::FillPatternShader, g
UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), idFillPatternInterpolateUBO}, UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), idFillPatternInterpolateUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idFillImageTexture},
}; };
const std::array<AttributeInfo, 4> const std::array<AttributeInfo, 4>
@@ -59,7 +59,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::FillOutlinePatternSh
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal>::textures = const std::array<TextureInfo, 1> ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Metal>::textures =
{ {
TextureInfo{0, "u_image"}, TextureInfo{0, idFillImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -22,7 +22,7 @@ const std::array<UniformBlockInfo, 4>
}; };
const std::array<TextureInfo, 1> const std::array<TextureInfo, 1>
ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Metal>::textures = { ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idFillExtrusionImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -12,8 +12,8 @@ const std::array<UniformBlockInfo, 1> ShaderSource<BuiltIn::HeatmapTextureShader
UniformBlockInfo{1, true, true, sizeof(HeatmapTextureDrawableUBO), idHeatmapTextureDrawableUBO}, UniformBlockInfo{1, true, true, sizeof(HeatmapTextureDrawableUBO), idHeatmapTextureDrawableUBO},
}; };
const std::array<TextureInfo, 2> ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 2> ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idHeatmapImageTexture},
TextureInfo{1, "u_color_ramp"}, TextureInfo{1, idHeatmapColorRampTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -12,7 +12,7 @@ const std::array<UniformBlockInfo, 2> ShaderSource<BuiltIn::HillshadeShader, gfx
UniformBlockInfo{3, false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, UniformBlockInfo{3, false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idHillshadeImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -13,7 +13,7 @@ const std::array<UniformBlockInfo, 1>
UniformBlockInfo{2, true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, UniformBlockInfo{2, true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idHillshadeImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -40,7 +40,7 @@ const std::array<UniformBlockInfo, 5> ShaderSource<BuiltIn::LinePatternShader, g
UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), idLinePatternTilePropertiesUBO}, UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), idLinePatternTilePropertiesUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idLineImageTexture},
}; };
const std::array<AttributeInfo, 9> ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Metal>::attributes = { const std::array<AttributeInfo, 9> ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Metal>::attributes = {
@@ -61,7 +61,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::LineSDFShader, gfx::
UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), idLineSDFInterpolationUBO}, UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), idLineSDFInterpolationUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idLineImageTexture},
}; };
const std::array<AttributeInfo, 2> ShaderSource<BuiltIn::LineBasicShader, gfx::Backend::Type::Metal>::attributes = { const std::array<AttributeInfo, 2> ShaderSource<BuiltIn::LineBasicShader, gfx::Backend::Type::Metal>::attributes = {

View File

@@ -19,7 +19,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::LineGradientShader,
UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), idLineGradientInterpolationUBO}, UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), idLineGradientInterpolationUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image"}, TextureInfo{0, idLineImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -11,8 +11,8 @@ const std::array<UniformBlockInfo, 1> ShaderSource<BuiltIn::RasterShader, gfx::B
UniformBlockInfo{2, true, true, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, UniformBlockInfo{2, true, true, sizeof(RasterDrawableUBO), idRasterDrawableUBO},
}; };
const std::array<TextureInfo, 2> ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 2> ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_image0"}, TextureInfo{0, idRasterImage0Texture},
TextureInfo{1, "u_image1"}, TextureInfo{1, idRasterImage1Texture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -38,10 +38,9 @@ shaders::UniformBlockInfo::UniformBlockInfo(
size(size_), size(size_),
id(id_) {} id(id_) {}
shaders::TextureInfo::TextureInfo(std::size_t index_, std::string_view name_) shaders::TextureInfo::TextureInfo(std::size_t index_, std::size_t id_)
: index(index_), : index(index_),
name(name_), id(id_) {}
nameID(stringIndexer().get(name_)) {}
namespace mtl { namespace mtl {
namespace { namespace {
@@ -188,11 +187,8 @@ MTLRenderPipelineStatePtr ShaderProgram::getRenderPipelineState(const gfx::Rende
return rps; return rps;
} }
std::optional<uint32_t> ShaderProgram::getSamplerLocation(const StringIdentity id) const { std::optional<size_t> ShaderProgram::getSamplerLocation(const size_t id) const {
if (auto it = textureBindings.find(id); it != textureBindings.end()) { return (id < textureBindings.size()) ? textureBindings[id] : std::nullopt;
return it->second;
}
return std::nullopt;
} }
void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) {
@@ -222,7 +218,11 @@ void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) {
} }
void ShaderProgram::initTexture(const shaders::TextureInfo& info) { void ShaderProgram::initTexture(const shaders::TextureInfo& info) {
textureBindings[stringIndexer().get(info.name.data())] = info.index; assert(info.id < textureBindings.size());
if (info.id >= textureBindings.size()) {
return;
}
textureBindings[info.id] = info.index;
} }
} // namespace mtl } // namespace mtl

View File

@@ -22,7 +22,7 @@ const std::array<UniformBlockInfo, 5> ShaderSource<BuiltIn::SymbolIconShader, gf
UniformBlockInfo{10, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, UniformBlockInfo{10, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_texture"}, TextureInfo{0, idSymbolImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -28,7 +28,7 @@ const std::array<UniformBlockInfo, 5> ShaderSource<BuiltIn::SymbolSDFIconShader,
UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, UniformBlockInfo{14, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO},
}; };
const std::array<TextureInfo, 1> ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 1> ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_texture"}, TextureInfo{0, idSymbolImageTexture},
}; };
} // namespace shaders } // namespace shaders

View File

@@ -27,8 +27,8 @@ const std::array<UniformBlockInfo, 5>
UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO}, UniformBlockInfo{13, true, false, sizeof(SymbolDrawableInterpolateUBO), idSymbolDrawableInterpolateUBO},
}; };
const std::array<TextureInfo, 2> ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal>::textures = { const std::array<TextureInfo, 2> ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Metal>::textures = {
TextureInfo{0, "u_texture"}, TextureInfo{0, idSymbolImageTexture},
TextureInfo{1, "u_texture_icon"}, TextureInfo{1, idSymbolImageIconTexture},
}; };
} // namespace shaders } // namespace shaders