Skip to content

Commit 4f59f0d

Browse files
committed
chore: minor emplace() refactor
1 parent b315e77 commit 4f59f0d

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/BackgroundImagesLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void BackgroundImagesLoader::enqueue(const fs::path& path, string_view channelSe
4646
vector<fs::directory_entry> entries;
4747
forEachFileInDir(mRecursiveDirectories, canonicalPath, [&](const auto& entry) {
4848
if (!entry.is_directory()) {
49-
mFilesFoundInDirectories.emplace(PathAndChannelSelector{entry, string{channelSelector}});
49+
mFilesFoundInDirectories.emplace(entry, string{channelSelector});
5050
entries.emplace_back(entry);
5151
}
5252
});

src/Image.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -834,29 +834,33 @@ Texture* Image::texture(span<const string> channelNames, EInterpolationMode minF
834834
default: throw runtime_error{"Unsupported number of channels for texture."};
835835
}
836836

837-
Texture::ComponentFormat componentFormat = Texture::ComponentFormat::Float16;
838-
for (const auto& chanName : channelNames) {
839-
const Channel* chan = channel(chanName);
840-
if (chan && chan->desiredPixelFormat() == EPixelFormat::F32) {
841-
componentFormat = Texture::ComponentFormat::Float32;
842-
break; // No need to check further, we already have a channel that requires F32.
843-
}
844-
}
837+
const Texture::ComponentFormat componentFormat = ranges::any_of(
838+
channelNames | views::transform([this](const auto& c) { return channel(c); }),
839+
[](const auto& c) { return c && c->desiredPixelFormat() == EPixelFormat::F32; }
840+
) ?
841+
Texture::ComponentFormat::Float32 :
842+
Texture::ComponentFormat::Float16;
845843

846844
mTextures.emplace(
847-
lookup,
848-
ImageTexture{
845+
piecewise_construct,
846+
tuple{
847+
lookup
848+
},
849+
tuple{
849850
new Texture{
850-
pixelFormat, componentFormat,
851-
{size().x(), size().y()},
852-
toNanogui(minFilter),
853-
toNanogui(magFilter),
854-
Texture::WrapMode::ClampToEdge,
855-
1, Texture::TextureFlags::ShaderRead,
856-
true, },
857-
{channelNames.begin(), channelNames.end()},
851+
pixelFormat,
852+
componentFormat,
853+
{size().x(), size().y()},
854+
toNanogui(minFilter),
855+
toNanogui(magFilter),
856+
Texture::WrapMode::ClampToEdge,
857+
1,
858+
Texture::TextureFlags::ShaderRead,
859+
true,
860+
},
861+
channelNames | toVector,
858862
false,
859-
}
863+
}
860864
);
861865

862866
auto& texture = mTextures.at(lookup).nanoguiTexture;

src/ImageViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ void ImageViewer::openImageDialog() {
24032403
allImages.push_back(filter.first);
24042404
}
24052405

2406-
filters.emplace(filters.begin(), pair<string, string>{join(allImages, ","), "All images"});
2406+
filters.emplace(filters.begin(), pair{join(allImages, ","), "All images"});
24072407
const auto paths = file_dialog(this, FileDialogType::OpenMultiple, filters);
24082408

24092409
for (size_t i = 0; i < paths.size(); ++i) {

0 commit comments

Comments
 (0)