Skip to content

Commit

Permalink
Use optional values in place of zero placeholders (#2089)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester authored Feb 6, 2024
1 parent 14bfb5d commit f9c6c9c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
12 changes: 7 additions & 5 deletions include/mbgl/gfx/drawable_atlases_tweaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Drawable;
class DrawableAtlasesTweaker : public gfx::DrawableTweaker {
public:
DrawableAtlasesTweaker(TileAtlasTexturesPtr atlases_,
const StringIdentity iconNameId_,
const StringIdentity glyphNameId_,
const std::optional<StringIdentity> iconNameId_,
const std::optional<StringIdentity> glyphNameId_,
bool isText_,
const bool sdfIcons_,
const style::AlignmentType rotationAlignment_,
Expand All @@ -37,7 +37,9 @@ class DrawableAtlasesTweaker : public gfx::DrawableTweaker {
sdfIcons(sdfIcons_),
rotationAlignment(rotationAlignment_),
iconScaled(iconScaled_),
textSizeIsZoomConstant(textSizeIsZoomConstant_) {}
textSizeIsZoomConstant(textSizeIsZoomConstant_) {
assert(iconNameId_ != glyphNameId_);
}
~DrawableAtlasesTweaker() override = default;

void init(Drawable&) override;
Expand All @@ -48,8 +50,8 @@ class DrawableAtlasesTweaker : public gfx::DrawableTweaker {
void setupTextures(Drawable&, const bool);

TileAtlasTexturesPtr atlases;
StringIdentity iconNameId;
StringIdentity glyphNameId;
std::optional<StringIdentity> iconNameId;
std::optional<StringIdentity> glyphNameId;
bool isText;

const bool sdfIcons;
Expand Down
11 changes: 9 additions & 2 deletions src/mbgl/gfx/drawable_atlases_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_fill_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layers/render_line_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9c6c9c

Please sign in to comment.