summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2013-04-10 15:27:42 -0500
committerMichael Brasser <michael.brasser@live.com>2013-04-11 16:46:56 +0200
commit6baa3e1d65047cb94adf0d2b640fda1c52cc15e7 (patch)
tree6f9b81ae7dfb31c441f6f0c17a5df69ae5f2dbad
parentd7b3949b1598f5525c8fc4cc0ec3b1c8bddb458c (diff)
AtlasTexture improvements
Rename small/large atlas to primary/secondary atlas. This makes it more intuitive in the case of the primary atlas being the same size or larger than the secondary one. Allow the primary atlas to be preloaded. Change-Id: I6acb466c9c351558b7ecc49cdbc76af36802ad69 Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
-rw-r--r--customcontext/context.cpp5
-rw-r--r--customcontext/texture/atlastexture.cpp48
-rw-r--r--customcontext/texture/atlastexture.h9
3 files changed, 34 insertions, 28 deletions
diff --git a/customcontext/context.cpp b/customcontext/context.cpp
index 27a6a81..ba03e06 100644
--- a/customcontext/context.cpp
+++ b/customcontext/context.cpp
@@ -223,6 +223,11 @@ void Context::initialize(QOpenGLContext *context)
QSGDistanceFieldTextMaterial m;
prepareMaterial(&m);
}
+#ifdef CUSTOMCONTEXT_ATLASTEXTURE
+ if (m_atlasTexture) {
+ m_atlasManager.preload();
+ }
+#endif
}
#endif
diff --git a/customcontext/texture/atlastexture.cpp b/customcontext/texture/atlastexture.cpp
index 85a4ec6..742171e 100644
--- a/customcontext/texture/atlastexture.cpp
+++ b/customcontext/texture/atlastexture.cpp
@@ -48,11 +48,6 @@
#include <private/qsgtexture_p.h>
-// "small" is defined as "char" on Windows.
-#ifdef small
-#undef small
-#endif
-
#ifndef GL_BGRA
#define GL_BGRA 0x80E1
#endif
@@ -75,15 +70,15 @@ int get_env_int(const char *name, int defaultValue)
}
TextureAtlasManager::TextureAtlasManager()
- : m_small_atlas(0)
- , m_large_atlas(0)
+ : m_primary_atlas(0)
+ , m_secondary_atlas(0)
{
- int small = get_env_int("CustomContext_SMALL_ATLAS_SIZE", 1024);
- int large = get_env_int("CustomContext_LARGE_ATLAS_SIZE", 2048);
+ int primary = get_env_int("CustomContext_PRIMARY_ATLAS_SIZE", 1024);
+ int secondary = get_env_int("CustomContext_SECONDARY_ATLAS_SIZE", 2048);
m_atlas_size_limit = get_env_int("CustomContext_ATLAS_SIZE_LIMIT", 256);
- m_small_atlas_size = QSize(small, small);
- m_large_atlas_size = QSize(large, large);
+ m_primary_atlas_size = QSize(primary, primary);
+ m_secondary_atlas_size = QSize(secondary, secondary);
}
@@ -94,35 +89,40 @@ TextureAtlasManager::~TextureAtlasManager()
void TextureAtlasManager::invalidate()
{
- delete m_small_atlas;
- m_small_atlas = 0;
- delete m_large_atlas;
- m_large_atlas = 0;
+ delete m_primary_atlas;
+ m_primary_atlas = 0;
+ delete m_secondary_atlas;
+ m_secondary_atlas = 0;
}
+void TextureAtlasManager::preload()
+{
+ m_primary_atlas = new TextureAtlas(m_primary_atlas_size);
+ m_primary_atlas->bind();
+}
QSGTexture *TextureAtlasManager::create(const QImage &image)
{
QSGTexture *t = 0;
if (image.width() < m_atlas_size_limit && image.height() < m_atlas_size_limit) {
- // If we have a larger atlas, try to allocate in that one, so we get as many
+ // If the secondary atlas is larger, try to allocate in that one, so we get as many
// images as possible batched together.
- if (m_large_atlas) {
- t = m_large_atlas->create(image);
+ if (m_secondary_atlas && m_secondary_atlas_size.width() > m_primary_atlas_size.width()) {
+ t = m_secondary_atlas->create(image);
if (t)
return t;
}
- if (!m_small_atlas)
- m_small_atlas = new TextureAtlas(m_small_atlas_size);
- t = m_small_atlas->create(image);
+ if (!m_primary_atlas)
+ m_primary_atlas = new TextureAtlas(m_primary_atlas_size);
+ t = m_primary_atlas->create(image);
if (t)
return t;
- if (!m_large_atlas)
- m_large_atlas = new TextureAtlas(m_large_atlas_size);
- t = m_large_atlas->create(image);
+ if (!m_secondary_atlas)
+ m_secondary_atlas = new TextureAtlas(m_secondary_atlas_size);
+ t = m_secondary_atlas->create(image);
if (t)
return t;
}
diff --git a/customcontext/texture/atlastexture.h b/customcontext/texture/atlastexture.h
index 9984c76..4de247c 100644
--- a/customcontext/texture/atlastexture.h
+++ b/customcontext/texture/atlastexture.h
@@ -64,13 +64,14 @@ public:
QSGTexture *create(const QImage &image);
void invalidate();
+ void preload();
private:
- TextureAtlas *m_small_atlas;
- TextureAtlas *m_large_atlas;
+ TextureAtlas *m_primary_atlas;
+ TextureAtlas *m_secondary_atlas;
- QSize m_small_atlas_size;
- QSize m_large_atlas_size;
+ QSize m_primary_atlas_size;
+ QSize m_secondary_atlas_size;
int m_atlas_size_limit;
};