@@ -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 ;
0 commit comments