Tilemap: Use simple "TexPool" replacement for atlas allocation

Releasing a Tilemap atlas into the pool on every map switch
will blow out tons of smaller textures for very little gain,
as atlas textures are already pretty much impossible to
recycle anywhere but in new Tilemaps.
This commit is contained in:
Jonas Kulla 2013-10-22 06:36:13 +02:00
parent 10b3e04dee
commit 765fd55bce
3 changed files with 41 additions and 3 deletions

View File

@ -92,6 +92,8 @@ struct SharedStatePrivate
TEXFBO gpTexFBO; TEXFBO gpTexFBO;
TEXFBO atlasTex;
Quad gpQuad; Quad gpQuad;
unsigned int stampCounter; unsigned int stampCounter;
@ -143,6 +145,7 @@ struct SharedStatePrivate
{ {
TEX::del(globalTex); TEX::del(globalTex);
TEXFBO::fini(gpTexFBO); TEXFBO::fini(gpTexFBO);
TEXFBO::fini(atlasTex);
} }
}; };
@ -266,6 +269,36 @@ TEXFBO &SharedState::gpTexFBO(int minW, int minH)
return p->gpTexFBO; return p->gpTexFBO;
} }
void SharedState::requestAtlasTex(int w, int h, TEXFBO &out)
{
TEXFBO tex;
if (w == p->atlasTex.width && h == p->atlasTex.height)
{
tex = p->atlasTex;
p->atlasTex = TEXFBO();
}
else
{
TEXFBO::init(tex);
TEXFBO::allocEmpty(tex, w, h);
TEXFBO::linkFBO(tex);
}
out = tex;
}
void SharedState::releaseAtlasTex(TEXFBO &tex)
{
/* No point in caching an invalid object */
if (tex.tex == TEX::ID(0))
return;
TEXFBO::fini(p->atlasTex);
p->atlasTex = tex;
}
void SharedState::checkShutdown() void SharedState::checkShutdown()
{ {
if (!p->rtData.rqTerm) if (!p->rtData.rqTerm)

View File

@ -123,6 +123,11 @@ struct SharedState
Quad &gpQuad(); Quad &gpQuad();
/* Basically just a simple "TexPool"
* replacement for Tilemap atlas use */
void requestAtlasTex(int w, int h, TEXFBO &out);
void releaseAtlasTex(TEXFBO &tex);
/* Checks EventThread's shutdown request flag and if set, /* Checks EventThread's shutdown request flag and if set,
* requests the binding to terminate. In this case, this * requests the binding to terminate. In this case, this
* function will most likely not return */ * function will most likely not return */

View File

@ -440,7 +440,7 @@ struct TilemapPrivate
{ {
destroyElements(); destroyElements();
shState->texPool().release(atlas.gl); shState->releaseAtlasTex(atlas.gl);
VAO::del(tiles.vao); VAO::del(tiles.vao);
VBO::del(tiles.vbo); VBO::del(tiles.vbo);
@ -607,8 +607,8 @@ struct TilemapPrivate
updateAtlasInfo(); updateAtlasInfo();
/* Aquire atlas tex */ /* Aquire atlas tex */
shState->texPool().release(atlas.gl); shState->releaseAtlasTex(atlas.gl);
atlas.gl = shState->texPool().request(atlas.size.x, atlas.size.y); shState->requestAtlasTex(atlas.size.x, atlas.size.y, atlas.gl);
atlasDirty = true; atlasDirty = true;
} }