MCPcopy Create free account
hub / github.com/Tom94/tev / texture

Method texture

src/Image.cpp:826–970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

824}
825
826Texture* Image::texture(span<const string> channelNames, EInterpolationMode minFilter, EInterpolationMode magFilter) & {
827 if (size().x() > maxTextureSize() || size().y() > maxTextureSize()) {
828 tlog::error("{} is too large for Texturing. ({}x{})", mName, size().x(), size().y());
829 return nullptr;
830 }
831
832 const string lookup = fmt::format("{}-{}-{}", join(channelNames, ","), tev::toString(minFilter), tev::toString(magFilter));
833 if (const auto it = mTextures.find(lookup); it != end(mTextures)) {
834 auto& texture = it->second;
835 if (texture.mipmapDirty && minFilter == EInterpolationMode::Trilinear) {
836 texture.nanoguiTexture->generate_mipmap();
837 texture.mipmapDirty = false;
838 }
839
840 return texture.nanoguiTexture.get();
841 }
842
843 static constexpr auto toNanogui = [](EInterpolationMode mode) {
844 switch (mode) {
845 case EInterpolationMode::Nearest: return Texture::InterpolationMode::Nearest;
846 case EInterpolationMode::Bilinear: return Texture::InterpolationMode::Bilinear;
847 case EInterpolationMode::Trilinear: return Texture::InterpolationMode::Trilinear;
848 default: throw runtime_error{"Unknown interpolation mode."};
849 }
850 };
851
852 Texture::PixelFormat pixelFormat;
853 switch (channelNames.size()) {
854 case 1: pixelFormat = Texture::PixelFormat::R; break;
855 case 2: pixelFormat = Texture::PixelFormat::RA; break;
856 case 3: pixelFormat = Texture::PixelFormat::RGB; break;
857 case 4: pixelFormat = Texture::PixelFormat::RGBA; break;
858 default: throw runtime_error{"Unsupported number of channels for texture."};
859 }
860
861 const Texture::ComponentFormat componentFormat = ranges::any_of(
862 channelNames | views::transform([this](const auto& c) { return channel(c); }),
863 [](const auto& c) { return c && c->desiredPixelFormat() == EPixelFormat::F32; }
864 ) ?
865 Texture::ComponentFormat::Float32 :
866 Texture::ComponentFormat::Float16;
867
868 mTextures.emplace(
869 piecewise_construct,
870 tuple{
871 lookup
872 },
873 tuple{
874 new Texture{
875 pixelFormat,
876 componentFormat,
877 {size().x(), size().y()},
878 toNanogui(minFilter),
879 toNanogui(magFilter),
880 Texture::WrapMode::ClampToEdge,
881 1,
882 Texture::TextureFlags::ShaderRead,
883 true,

Callers 1

drawMethod · 0.80

Calls 14

numPixelsMethod · 0.95
sizeMethod · 0.95
maxTextureSizeFunction · 0.85
joinFunction · 0.85
nChannelsInPixelFormatFunction · 0.85
prepareTextureChannelFunction · 0.85
waitAllFunction · 0.85
dataBytesMethod · 0.80
toStringFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected