From 4c8e7ad74f2709125659deaf1b4ddd10623740dc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Jun 2016 23:35:09 +0300 Subject: Add support for load pseudo atlas, where atlas and each image in it will not use any images. --- src/resources/atlas/atlasmanager.cpp | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/resources/atlas/atlasmanager.cpp') diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp index 4e1b0e96c..353818d68 100644 --- a/src/resources/atlas/atlasmanager.cpp +++ b/src/resources/atlas/atlasmanager.cpp @@ -103,6 +103,38 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name, return resource; } +AtlasResource *AtlasManager::loadEmptyAtlas(const std::string &name, + const StringVect &files) +{ + std::vector atlases; + std::vector images; + AtlasResource *resource = new AtlasResource; + + loadEmptyImages(files, images); + int maxSize = OpenGLImageHelper::getTextureSize(); + + // sorting images on atlases. + simpleSort(name, atlases, images, maxSize); + + FOR_EACH (std::vector::iterator, it, atlases) + { + TextureAtlas *const atlas = *it; + if (!atlas) + continue; + + atlas->atlasImage = new Image(0, + 8192, 8192, + 8192, 8192); + // convert SDL images to OpenGL + convertAtlas(atlas); + + resource->atlases.push_back(atlas); + } + + BLOCK_END("AtlasManager::loadTextureAtlas") + return resource; +} + void AtlasManager::loadImages(const StringVect &files, std::vector &images) { @@ -151,6 +183,33 @@ void AtlasManager::loadImages(const StringVect &files, BLOCK_END("AtlasManager::loadImages") } +void AtlasManager::loadEmptyImages(const StringVect &files, + std::vector &images) +{ + BLOCK_START("AtlasManager::loadEmptyImages") + + FOR_EACH (StringVectCIter, it, files) + { + const std::string str = *it; + // check is image with same name already in cache + // and if yes, move it to deleted set + Resource *const res = resourceManager->getTempResource(str); + if (res) + { + // increase counter because in moveToDeleted it will be decreased. + res->incRef(); + resourceManager->moveToDeleted(res); + } + + Image *const image = new Image(0, + 2048, 2048, + 2048, 2048); + image->mIdPath = str; + images.push_back(image); + } + BLOCK_END("AtlasManager::loadEmptyImages") +} + void AtlasManager::simpleSort(const std::string &restrict name, std::vector &restrict atlases, const std::vector &restrict images, -- cgit v1.2.3-70-g09d2