void TextureLoader::doLoad(ResourceKey key) { auto found = names.find(key); if(found == names.end()) return setNotFound(key); Utility::Resource rs("textures"); if(!tgaImporter->openData(rs.getRaw(found->second + ".tga"))) { Error() << "TextureLoader: cannot open" << found->second; return setNotFound(key); } auto image = tgaImporter->image2D(0); if(!image) { Error() << "TextureLoader: cannot load" << found->second; return setNotFound(key); } /* TODO: fix when glPixelStorei is implemented */ if(image->size().x() % 4) { Error() << "TextureLoader: with of image" << found->second << "is not divisible by 4"; return setNotFound(key); } if(image->size().y() % 2) { Error() << "TextureLoader: height of image" << found->second << "is not even"; return setNotFound(key); } #ifndef MAGNUM_TARGET_GLES if(image->format() != ColorFormat::Red || image->type() != ColorType::UnsignedByte) #else if(image->format() != ColorFormat::Luminance || image->type() != ColorType::UnsignedByte) #endif { Error() << "TextureLoader: image" << found->second << "isn't in greyscale format"; return setNotFound(key); } auto texture = new Texture2D; texture->setMinificationFilter(Sampler::Filter::Nearest) .setMagnificationFilter(Sampler::Filter::Nearest) .setWrapping(Sampler::Wrapping::ClampToEdge); #ifndef MAGNUM_TARGET_GLES texture->setImage(0, TextureFormat::Red, *image); #else texture->setImage(0, TextureFormat::Luminance, *image); #endif set(key, texture); }
void load() { set("hello", 773, ResourceDataState::Final, ResourcePolicy::Resident); setNotFound("world"); }