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/line_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/ubo_max_count.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_builder.hpp

View File

@@ -990,9 +990,9 @@ MLN_DRAWABLES_HEADERS = [
"include/mbgl/shaders/layer_ubo.hpp",
"include/mbgl/shaders/line_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/symbol_layer_ubo.hpp",
"include/mbgl/shaders/ubo_max_count.hpp",
"include/mbgl/util/identity.hpp",
"include/mbgl/util/suppress_copies.hpp",
"include/mbgl/style/layers/custom_drawable_layer.hpp",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,132 +15,163 @@ struct UniformBlockInfo {
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>
struct ShaderInfo;
template <>
struct ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::CircleShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::DebugShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillOutlineShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
};
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;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::HillshadeShader, gfx::Backend::Type::OpenGL> {
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 <>
struct ShaderInfo<BuiltIn::RasterShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::SymbolIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
template <>
struct ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL> {
static const std::vector<UniformBlockInfo> uniformBlocks;
static const std::vector<TextureInfo> textures;
};
} // namespace shaders

View File

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

View File

@@ -29,10 +29,9 @@ struct UniformBlockInfo {
std::size_t id;
};
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::string_view name;
StringIdentity nameID;
std::size_t id;
};
} // namespace shaders
namespace mtl {
@@ -56,7 +55,7 @@ public:
const MTLVertexDescriptorPtr&,
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; }
@@ -74,7 +73,7 @@ protected:
MTLFunctionPtr fragmentFunction;
UniformBlockArray uniformBlocks;
VertexAttributeArray vertexAttributes;
std::unordered_map<StringIdentity, std::size_t> textureBindings;
std::array<std::optional<size_t>, shaders::maxTextureCountPerShader> textureBindings;
};
} // 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>(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 mbgl

View File

@@ -33,7 +33,7 @@ public:
/// @brief Gets the sampler location
/// @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
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;
const gfx::Texture2DPtr& Drawable::getTexture(int32_t location) const {
const auto hit = textures.find(location);
return (hit != textures.end()) ? hit->second : noTexture;
const gfx::Texture2DPtr& Drawable::getTexture(size_t id) const {
return (id < textures.size()) ? textures[id] : noTexture;
}
void Drawable::setTexture(std::shared_ptr<gfx::Texture2D> texture, int32_t location) {
textures.insert(std::make_pair(location, gfx::Texture2DPtr{})).first->second = std::move(texture);
}
void Drawable::removeTexture(int32_t location) {
textures.erase(location);
void Drawable::setTexture(std::shared_ptr<gfx::Texture2D> texture, size_t id) {
assert(id < textures.size());
if (id >= textures.size()) {
return;
}
textures[id] = std::move(texture);
}
} // namespace gfx

View File

@@ -8,16 +8,9 @@
namespace mbgl {
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) {
if (const auto& shader = drawable.getShader()) {
if (const auto samplerLocation = getSamplerLocation(shader, glyphNameId)) {
if (glyphTextureId) {
if (atlases) {
atlases->glyph->setSamplerConfiguration(
{TextureFilterType::Linear, TextureWrapType::Clamp, TextureWrapType::Clamp});
@@ -26,12 +19,12 @@ void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable, const bool l
TextureWrapType::Clamp,
TextureWrapType::Clamp});
}
if (const auto iconSamplerLocation = getSamplerLocation(shader, iconNameId)) {
assert(*samplerLocation != *iconSamplerLocation);
drawable.setTexture(atlases ? atlases->glyph : nullptr, *samplerLocation);
drawable.setTexture(atlases ? atlases->icon : nullptr, *iconSamplerLocation);
if (iconTextureId && shader->getSamplerLocation(*iconTextureId)) {
assert(*glyphTextureId != *iconTextureId);
drawable.setTexture(atlases ? atlases->glyph : nullptr, *glyphTextureId);
drawable.setTexture(atlases ? atlases->icon : nullptr, *iconTextureId);
} 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) {
textures.insert(std::make_pair(location, gfx::Texture2DPtr{})).first->second = std::move(texture);
static const gfx::Texture2DPtr noTexture;
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) {

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 auto& result = (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref;
return (result != nullptr) ? result : nullref;
return (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref;
}
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 auto& result = (id < uniformBufferVector.size()) ? uniformBufferVector[id] : nullref;
return (result != nullptr) ? result : nullref;
return (id < uniformBufferVector.size()) ? uniformBufferVector[id] : nullref;
}
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(
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) {
uploadTextures();
@@ -245,27 +245,28 @@ gfx::StencilMode DrawableGL::makeStencilMode(PaintParameters& parameters) const
}
void DrawableGL::uploadTextures() const {
for (const auto& pair : textures) {
if (const auto& tex = pair.second) {
std::static_pointer_cast<gl::Texture2D>(tex)->upload();
for (const auto& texture : textures) {
if (texture) {
texture->upload();
}
}
}
void DrawableGL::bindTextures() const {
int32_t unit = 0;
for (const auto& pair : textures) {
if (const auto& tex = pair.second) {
const auto& location = pair.first;
std::static_pointer_cast<gl::Texture2D>(tex)->bind(location, unit++);
for (size_t id = 0; id < textures.size(); id++) {
if (const auto& texture = textures[id]) {
if (const auto& location = shader->getSamplerLocation(id)) {
static_cast<gl::Texture2D&>(*texture).bind(static_cast<int32_t>(*location), unit++);
}
}
}
}
void DrawableGL::unbindTextures() const {
for (const auto& pair : textures) {
if (const auto& tex = pair.second) {
std::static_pointer_cast<gl::Texture2D>(tex)->unbind();
for (const auto& texture : textures) {
if (texture) {
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));
impl->clear();
textures.clear();
textures.fill(nullptr);
}
} // namespace gl

View File

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

View File

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

View File

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

View File

@@ -14,7 +14,6 @@
#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp>
#include <mbgl/util/convert.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/string_indexer.hpp>
#if MLN_RENDER_BACKEND_METAL
#include <mbgl/shaders/mtl/fill_extrusion.hpp>
@@ -26,11 +25,6 @@ namespace mbgl {
using namespace shaders;
using namespace style;
namespace {
const StringIdentity idTexImageName = stringIndexer().get("u_image");
} // namespace
void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) {
auto& context = parameters.context;
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);
Size textureSize = {0, 0};
if (const auto shader = drawable.getShader()) {
if (const auto index = shader->getSamplerLocation(idTexImageName)) {
if (const auto& tex = drawable.getTexture(*index)) {
textureSize = tex->getSize();
}
}
if (const auto& tex = drawable.getTexture(idFillExtrusionImageTexture)) {
textureSize = tex->getSize();
}
const FillExtrusionDrawableUBO drawableUBO = {

View File

@@ -15,7 +15,6 @@
#include <mbgl/style/layers/fill_layer_properties.hpp>
#include <mbgl/util/convert.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/string_indexer.hpp>
#if MLN_RENDER_BACKEND_METAL
#include <mbgl/shaders/mtl/fill.hpp>
@@ -24,8 +23,6 @@
namespace mbgl {
using namespace style;
static const StringIdentity idTexImageName = stringIndexer().get("u_image");
using namespace shaders;
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;
Size textureSize = {0, 0};
if (const auto shader = drawable.getShader()) {
if (const auto index = shader->getSamplerLocation(idTexImageName)) {
if (const auto& tex = drawable.getTexture(*index)) {
textureSize = tex->getSize();
}
}
if (const auto& tex = drawable.getTexture(idFillImageTexture)) {
textureSize = tex->getSize();
}
auto& uniforms = drawable.mutableUniformBuffers();

View File

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

View File

@@ -42,8 +42,6 @@ namespace {
const StringIdentity idPosAttribName = stringIndexer().get("a_pos");
const StringIdentity idNormAttribName = stringIndexer().get("a_normal_ed");
const StringIdentity idIconTextureName = stringIndexer().get("u_image");
#endif // MLN_DRAWABLE_RENDERER
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()) {
tweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
std::nullopt,
idIconTextureName,
idFillExtrusionImageTexture,
/*isText=*/false,
false,
style::AlignmentType::Auto,

View File

@@ -51,7 +51,6 @@ constexpr auto FillPatternShaderName = "FillPatternShader";
constexpr auto FillOutlinePatternShaderName = "FillOutlinePatternShader";
const StringIdentity idPosAttribName = stringIndexer().get("a_pos");
const StringIdentity idIconTextureName = stringIndexer().get("u_image");
#endif // MLN_DRAWABLE_RENDERER
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>(
atlases,
std::nullopt,
idIconTextureName,
idFillImageTexture,
/*isText*/ false,
/*sdfIcons*/ true, // to force linear filter
/*rotationAlignment_*/ AlignmentType::Auto,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -66,8 +66,6 @@ private:
#if MLN_DRAWABLE_RENDERER
gfx::ShaderProgramBasePtr rasterShader;
std::optional<uint32_t> rasterSampler0;
std::optional<uint32_t> rasterSampler1;
LayerGroupPtr imageLayerGroup;
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 idProjPosAttribName = stringIndexer().get("a_projected_pos");
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,
const bool isText,
@@ -1293,8 +1291,8 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
const bool textSizeIsZoomConstant =
bucket.textSizeBinder->evaluateForZoom(static_cast<float>(state.getZoom())).isZoomConstant;
tileInfo.textTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
idTexIconUniformName,
idTexUniformName,
idSymbolImageIconTexture,
idSymbolImageTexture,
isText,
false,
values.rotationAlignment,
@@ -1304,8 +1302,8 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
if (!isText && !tileInfo.iconTweaker) {
const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear;
tileInfo.iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
idTexIconUniformName,
idTexUniformName,
idSymbolImageIconTexture,
idSymbolImageTexture,
isText,
sdfIcons,
values.rotationAlignment,

View File

@@ -29,13 +29,9 @@ using namespace shaders;
namespace {
Size getTexSize(const gfx::Drawable& drawable, const StringIdentity nameId) {
if (const auto& shader = drawable.getShader()) {
if (const auto index = shader->getSamplerLocation(nameId)) {
if (const auto& tex = drawable.getTexture(*index)) {
return tex->getSize();
}
}
Size getTexSize(const gfx::Drawable& drawable, const size_t texId) {
if (const auto& tex = drawable.getTexture(texId)) {
return tex->getSize();
}
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});
}
const StringIdentity idTexUniformName = stringIndexer().get("u_texture");
const StringIdentity idTexIconUniformName = stringIndexer().get("u_texture_icon");
SymbolDrawablePaintUBO buildPaintUBO(bool isText, const SymbolPaintProperties::PossiblyEvaluated& evaluated) {
return {
/*.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),
/*.coord_matrix=*/util::cast<float>(glCoordMatrix),
/*.texsize=*/toArray(getTexSize(drawable, idTexUniformName)),
/*.texsize_icon=*/toArray(getTexSize(drawable, idTexIconUniformName)),
/*.texsize=*/toArray(getTexSize(drawable, idSymbolImageTexture)),
/*.texsize_icon=*/toArray(getTexSize(drawable, idSymbolImageIconTexture)),
/*.gamma_scale=*/gammaScale,
/*.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
auto texture = context.createTexture2D();
std::optional<uint32_t> samplerLocation;
{
std::array<uint8_t, 4> data{{0, 0, 0, 0}};
auto emptyImage = std::make_shared<PremultipliedImage>(Size(1, 1), data.data(), data.size());
texture->setImage(emptyImage);
texture->setSamplerConfiguration(
{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
const auto updateDrawables =
@@ -172,7 +167,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr
debugBuilder->addVertices(verts, 0, verts.size());
debugBuilder->setSegments(mode, indexes, segments.data(), segments.size());
// texture
debugBuilder->setTexture(texture, samplerLocation.value());
debugBuilder->setTexture(texture, idDebugOverlayTexture);
// finish
debugBuilder->flush(context);

View File

@@ -1,6 +1,6 @@
#include <mbgl/shaders/gl/shader_info.hpp>
#include <mbgl/shaders/ubo_max_count.hpp>
#include <mbgl/shaders/shader_defines.hpp>
namespace mbgl {
namespace shaders {
@@ -10,51 +10,76 @@ UniformBlockInfo::UniformBlockInfo(std::string_view name_, std::size_t id_)
id(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 = {
UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO},
UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO},
};
const std::vector<TextureInfo> ShaderInfo<BuiltIn::BackgroundShader, gfx::Backend::Type::OpenGL>::textures = {};
// Background Pattern
const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO},
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 = {
UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO},
UniformBlockInfo{"CirclePaintParamsUBO", idCirclePaintParamsUBO},
UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO},
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 =
{
UniformBlockInfo{"CollisionBoxUBO", idCollisionUBO},
};
const std::vector<TextureInfo> ShaderInfo<BuiltIn::CollisionBoxShader, gfx::Backend::Type::OpenGL>::textures = {};
// Collision Circle
const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::CollisionCircleShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
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 = {
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 = {
UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO},
UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO},
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 =
{
UniformBlockInfo{"FillOutlineDrawableUBO", idFillOutlineDrawableUBO},
UniformBlockInfo{"FillOutlineEvaluatedPropsUBO", idFillOutlineEvaluatedPropsUBO},
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 =
{
UniformBlockInfo{"FillPatternDrawableUBO", idFillPatternDrawableUBO},
@@ -62,7 +87,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::FillPatternShader, gfx::
UniformBlockInfo{"FillPatternEvaluatedPropsUBO", idFillPatternEvaluatedPropsUBO},
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>
ShaderInfo<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillOutlinePatternDrawableUBO},
@@ -70,7 +99,11 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillOutlinePatternEvaluatedPropsUBO", idFillOutlinePatternEvaluatedPropsUBO},
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>
ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO},
@@ -78,7 +111,9 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO},
UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO},
};
const std::vector<TextureInfo> ShaderInfo<BuiltIn::FillExtrusionShader, gfx::Backend::Type::OpenGL>::textures = {};
// Fill Extrusion Pattern
const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO},
@@ -86,28 +121,47 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"FillExtrusionDrawableTilePropsUBO", idFillExtrusionDrawableTilePropsUBO},
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 = {
UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO},
UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO},
UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO},
};
const std::vector<TextureInfo> ShaderInfo<BuiltIn::HeatmapShader, gfx::Backend::Type::OpenGL>::textures = {};
// Heatmap Texture
const std::vector<UniformBlockInfo>
ShaderInfo<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
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>
ShaderInfo<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
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 = {
UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO},
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 =
{
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
@@ -115,7 +169,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LineGradientShader, gfx:
UniformBlockInfo{"LineGradientPropertiesUBO", idLineGradientPropertiesUBO},
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 =
{
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
@@ -124,30 +182,47 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::LinePatternShader, gfx::
UniformBlockInfo{"LinePatternInterpolationUBO", idLinePatternInterpolationUBO},
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 = {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
UniformBlockInfo{"LineSDFUBO", idLineSDFUBO},
UniformBlockInfo{"LineSDFPropertiesUBO", idLineSDFPropertiesUBO},
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 = {
UniformBlockInfo{"LineDynamicUBO", idLineDynamicUBO},
UniformBlockInfo{"LineUBO", idLineUBO},
UniformBlockInfo{"LinePropertiesUBO", idLinePropertiesUBO},
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 = {
UniformBlockInfo{"LineBasicUBO", idLineBasicUBO},
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 = {
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 = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
UniformBlockInfo{"SymbolDynamicUBO", idSymbolDynamicUBO},
@@ -155,7 +230,11 @@ const std::vector<UniformBlockInfo> ShaderInfo<BuiltIn::SymbolIconShader, gfx::B
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
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>
ShaderInfo<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
@@ -164,7 +243,11 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
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>
ShaderInfo<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::OpenGL>::uniformBlocks = {
UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO},
@@ -173,6 +256,10 @@ const std::vector<UniformBlockInfo>
UniformBlockInfo{"SymbolDrawableTilePropsUBO", idSymbolDrawableTilePropsUBO},
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 mbgl

View File

@@ -91,7 +91,7 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_)
ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program,
UniformBlockArrayGL&& uniformBlocks_,
VertexAttributeArrayGL&& attributes_,
SamplerLocationMap&& samplerLocations_)
SamplerLocationArray&& samplerLocations_)
: ShaderProgramBase(),
glProgram(std::move(program)),
uniformBlocks(std::move(uniformBlocks_)),
@@ -105,20 +105,16 @@ ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other)
vertexAttributes(std::move(other.vertexAttributes)),
samplerLocations(std::move(other.samplerLocations)) {}
std::optional<uint32_t> ShaderProgramGL::getSamplerLocation(const StringIdentity id) const {
std::optional<uint32_t> result{};
if (auto it = samplerLocations.find(id); it != samplerLocations.end()) {
result = it->second;
}
return result;
std::optional<size_t> ShaderProgramGL::getSamplerLocation(const size_t id) const {
return (id < samplerLocations.size()) ? samplerLocations[id] : std::nullopt;
}
std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
Context& context,
const ProgramParameters& programParameters,
const std::string& /*name*/,
const std::string_view firstAttribName,
const std::vector<shaders::UniformBlockInfo>& uniformBlocksInfo,
const std::vector<shaders::TextureInfo>& texturesInfo,
const std::string& vertexSource,
const std::string& fragmentSource,
const std::string& additionalDefines) noexcept(false) {
@@ -140,17 +136,7 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
fragmentSource.c_str()});
auto program = context.createProgram(vertProg, fragProg, firstAttribName.data());
// GLES3.1
// GLint numAttribs;
// glGetProgramInterfaceiv(program, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numAttribs);
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) {
GLint index = MBGL_CHECK_ERROR(glGetUniformBlockIndex(program, blockInfo.name.data()));
GLint size = 0;
@@ -161,34 +147,21 @@ std::shared_ptr<ShaderProgramGL> ShaderProgramGL::create(
uniformBlocks.set(blockInfo.id, binding, size);
}
SamplerLocationMap samplerLocations;
GLint numActiveUniforms = 0;
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numActiveUniforms));
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength));
auto name = std::vector<GLchar>(maxLength);
for (GLint index = 0; index < numActiveUniforms; ++index) {
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;
}
SamplerLocationArray samplerLocations;
for (const auto& textureInfo : texturesInfo) {
GLint location = MBGL_CHECK_ERROR(glGetUniformLocation(program, textureInfo.name.data()));
assert(location != -1);
if (location != -1) {
samplerLocations[textureInfo.id] = location;
}
}
VertexAttributeArrayGL attrs;
count = 0;
GLint count = 0;
GLint maxLength = 0;
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count));
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) {
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"

View File

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

View File

@@ -40,7 +40,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::FillPatternShader, g
UniformBlockInfo{7, true, false, sizeof(FillPatternInterpolateUBO), idFillPatternInterpolateUBO},
};
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>
@@ -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 =
{
TextureInfo{0, "u_image"},
TextureInfo{0, idFillImageTexture},
};
} // namespace shaders

View File

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

View File

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

View File

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

View File

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

View File

@@ -40,7 +40,7 @@ const std::array<UniformBlockInfo, 5> ShaderSource<BuiltIn::LinePatternShader, g
UniformBlockInfo{13, true, true, sizeof(LinePatternTilePropertiesUBO), idLinePatternTilePropertiesUBO},
};
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 = {
@@ -61,7 +61,7 @@ const std::array<UniformBlockInfo, 4> ShaderSource<BuiltIn::LineSDFShader, gfx::
UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), idLineSDFInterpolationUBO},
};
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 = {

View File

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

View File

@@ -38,10 +38,9 @@ shaders::UniformBlockInfo::UniformBlockInfo(
size(size_),
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_),
name(name_),
nameID(stringIndexer().get(name_)) {}
id(id_) {}
namespace mtl {
namespace {
@@ -188,11 +187,8 @@ MTLRenderPipelineStatePtr ShaderProgram::getRenderPipelineState(const gfx::Rende
return rps;
}
std::optional<uint32_t> ShaderProgram::getSamplerLocation(const StringIdentity id) const {
if (auto it = textureBindings.find(id); it != textureBindings.end()) {
return it->second;
}
return std::nullopt;
std::optional<size_t> ShaderProgram::getSamplerLocation(const size_t id) const {
return (id < textureBindings.size()) ? textureBindings[id] : std::nullopt;
}
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) {
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

View File

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

View File

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

View File

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