summaryrefslogtreecommitdiff
path: root/src/resources/atlas
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-26 00:44:51 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-26 02:01:27 +0300
commit63a18c31ee0ccc5f4ac967aaa2f674eb89f90528 (patch)
tree9fa32c6ad2b6998529c1bdabd8f29535b74ab5ab /src/resources/atlas
parent916dfcf76e6ffa46cd61656e2c0087be4624cf80 (diff)
downloadmanaverse-63a18c31ee0ccc5f4ac967aaa2f674eb89f90528.tar.gz
manaverse-63a18c31ee0ccc5f4ac967aaa2f674eb89f90528.tar.bz2
manaverse-63a18c31ee0ccc5f4ac967aaa2f674eb89f90528.tar.xz
manaverse-63a18c31ee0ccc5f4ac967aaa2f674eb89f90528.zip
Improve a bit creating empty atlas.
Diffstat (limited to 'src/resources/atlas')
-rw-r--r--src/resources/atlas/atlasmanager.cpp94
-rw-r--r--src/resources/atlas/atlasmanager.h6
2 files changed, 95 insertions, 5 deletions
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp
index f8251ba7d..7b7ab4536 100644
--- a/src/resources/atlas/atlasmanager.cpp
+++ b/src/resources/atlas/atlasmanager.cpp
@@ -98,10 +98,9 @@ AtlasResource *AtlasManager::loadEmptyAtlas(const std::string &name,
AtlasResource *resource = new AtlasResource;
loadEmptyImages(files, images);
- int maxSize = OpenGLImageHelper::getTextureSize();
// sorting images on atlases.
- simpleSort(name, atlases, images, maxSize);
+ emptySort(name, atlases, images);
FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases)
{
@@ -110,10 +109,10 @@ AtlasResource *AtlasManager::loadEmptyAtlas(const std::string &name,
continue;
atlas->atlasImage = new Image(0,
- 8192, 8192,
- 8192, 8192);
+ 1024, 1024,
+ 1024, 1024);
// convert SDL images to OpenGL
- convertAtlas(atlas);
+ convertEmptyAtlas(atlas);
resource->atlases.push_back(atlas);
}
@@ -269,6 +268,44 @@ void AtlasManager::simpleSort(const std::string &restrict name,
BLOCK_END("AtlasManager::simpleSort")
}
+void AtlasManager::emptySort(const std::string &restrict name,
+ std::vector<TextureAtlas*> &restrict atlases,
+ const std::vector<Image*> &restrict images)
+{
+ BLOCK_START("AtlasManager::simpleSort")
+ TextureAtlas *atlas = new TextureAtlas;
+ std::vector<Image*>::const_iterator it = images.begin();
+ const std::vector<Image*>::const_iterator it_end = images.end();
+ for (it = images.begin(); it != it_end; ++ it)
+ {
+ const Image *const img = *it;
+ if (img)
+ {
+ atlas->name = std::string("atlas_").append(name).append(
+ "_").append(img->mIdPath);
+ break;
+ }
+ }
+
+ for (it = images.begin(); it != it_end; ++ it)
+ {
+ Image *const img = *it;
+ if (img)
+ {
+ AtlasItem *const item = new AtlasItem(img);
+ item->name = img->mIdPath;
+ item->x = 0;
+ item->y = 0;
+ atlas->items.push_back(item);
+ }
+ }
+ if (!atlas->items.empty())
+ atlases.push_back(atlas);
+ else
+ delete atlas;
+ BLOCK_END("AtlasManager::simpleSort")
+}
+
void AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
{
BLOCK_START("AtlasManager::createSDLAtlas")
@@ -358,6 +395,53 @@ void AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
BLOCK_END("AtlasManager::createSDLAtlas")
}
+void AtlasManager::convertEmptyAtlas(TextureAtlas *const atlas)
+{
+ // no check for null pointer in atlas because it was in caller
+ // convert surface to OpemGL image
+ Image *const oldImage = atlas->atlasImage;
+
+ if (oldImage->mSDLSurface)
+ {
+ atlas->atlasImage = imageHelper->loadSurface(
+ atlas->atlasImage->mSDLSurface);
+ oldImage->decRef();
+ }
+
+ Image *const image = atlas->atlasImage;
+ if (!image)
+ return;
+
+ image->mIdPath = atlas->name;
+#ifdef DEBUG_IMAGES
+ logger->log("set name %p, %s", static_cast<void*>(image),
+ image->mIdPath.c_str());
+#endif // DEBUG_IMAGES
+
+ image->incRef();
+
+ FOR_EACH (std::vector<AtlasItem*>::iterator, it, atlas->items)
+ {
+ AtlasItem *const item = *it;
+ // delete SDL Image
+ delete item->image;
+ // store OpenGL image
+ item->image = image->getSubImage(item->x, item->y,
+ item->width, item->height);
+ Image *const image2 = item->image;
+ if (image2)
+ {
+ image2->mIdPath = item->name;
+#ifdef DEBUG_IMAGES
+ logger->log("set empty name %p, %s", static_cast<void*>(image2),
+ image2->mIdPath.c_str());
+#endif // DEBUG_IMAGES
+
+ image2->incRef();
+ }
+ }
+}
+
void AtlasManager::convertAtlas(TextureAtlas *const atlas)
{
// no check for null pointer in atlas because it was in caller
diff --git a/src/resources/atlas/atlasmanager.h b/src/resources/atlas/atlasmanager.h
index e619ce736..13db9717e 100644
--- a/src/resources/atlas/atlasmanager.h
+++ b/src/resources/atlas/atlasmanager.h
@@ -58,6 +58,10 @@ class AtlasManager final
static void loadEmptyImages(const StringVect &files,
std::vector<Image*> &images);
+ static void emptySort(const std::string &restrict name,
+ std::vector<TextureAtlas*> &restrict atlases,
+ const std::vector<Image*> &restrict images);
+
static void simpleSort(const std::string &restrict name,
std::vector<TextureAtlas*> &restrict atlases,
const std::vector<Image*> &restrict images,
@@ -66,6 +70,8 @@ class AtlasManager final
static void createSDLAtlas(TextureAtlas *const atlas) A_NONNULL(1);
static void convertAtlas(TextureAtlas *const atlas) A_NONNULL(1);
+
+ static void convertEmptyAtlas(TextureAtlas *const atlas) A_NONNULL(1);
};
#endif // USE_OPENGL