Use optional values in place of zero placeholders (#2089)

This commit is contained in:
Tim Sylvester
2024-02-06 07:13:13 -08:00
committed by GitHub
parent 14bfb5df72
commit f9c6c9c2be
5 changed files with 19 additions and 10 deletions

View File

@@ -8,9 +8,16 @@
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 = shader->getSamplerLocation(glyphNameId)) {
if (const auto samplerLocation = getSamplerLocation(shader, glyphNameId)) {
if (atlases) {
atlases->glyph->setSamplerConfiguration(
{TextureFilterType::Linear, TextureWrapType::Clamp, TextureWrapType::Clamp});
@@ -19,7 +26,7 @@ void DrawableAtlasesTweaker::setupTextures(gfx::Drawable& drawable, const bool l
TextureWrapType::Clamp,
TextureWrapType::Clamp});
}
if (const auto iconSamplerLocation = shader->getSamplerLocation(iconNameId)) {
if (const auto iconSamplerLocation = getSamplerLocation(shader, iconNameId)) {
assert(*samplerLocation != *iconSamplerLocation);
drawable.setTexture(atlases ? atlases->glyph : nullptr, *samplerLocation);
drawable.setTexture(atlases ? atlases->icon : nullptr, *iconSamplerLocation);

View File

@@ -459,7 +459,7 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders,
if (hasPattern && !tweaker) {
if (const auto& atlases = tile.getAtlasTextures()) {
tweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(atlases,
0,
std::nullopt,
idIconTextureName,
/*isText=*/false,
false,

View File

@@ -599,7 +599,7 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
if (const auto& atlases = tile.getAtlasTextures(); atlases && atlases->icon) {
atlasTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(
atlases,
0,
std::nullopt,
idIconTextureName,
/*isText*/ false,
/*sdfIcons*/ true, // to force linear filter

View File

@@ -680,7 +680,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
if (!iconTweaker) {
iconTweaker = std::make_shared<gfx::DrawableAtlasesTweaker>(
atlases,
0,
std::nullopt,
idLineImageUniformName,
/*isText*/ false,
/*sdfIcons*/ true, // to force linear filter