diff --git a/src/sharedstate.cpp b/src/sharedstate.cpp index d85dd1f..c79ed3a 100644 --- a/src/sharedstate.cpp +++ b/src/sharedstate.cpp @@ -92,6 +92,8 @@ struct SharedStatePrivate TEXFBO gpTexFBO; + TEXFBO atlasTex; + Quad gpQuad; unsigned int stampCounter; @@ -143,6 +145,7 @@ struct SharedStatePrivate { TEX::del(globalTex); TEXFBO::fini(gpTexFBO); + TEXFBO::fini(atlasTex); } }; @@ -266,6 +269,36 @@ TEXFBO &SharedState::gpTexFBO(int minW, int minH) 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() { if (!p->rtData.rqTerm) diff --git a/src/sharedstate.h b/src/sharedstate.h index b98c8f0..ecd2ee3 100644 --- a/src/sharedstate.h +++ b/src/sharedstate.h @@ -123,6 +123,11 @@ struct SharedState 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, * requests the binding to terminate. In this case, this * function will most likely not return */ diff --git a/src/tilemap.cpp b/src/tilemap.cpp index c9a5d83..f97a5e9 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -440,7 +440,7 @@ struct TilemapPrivate { destroyElements(); - shState->texPool().release(atlas.gl); + shState->releaseAtlasTex(atlas.gl); VAO::del(tiles.vao); VBO::del(tiles.vbo); @@ -607,8 +607,8 @@ struct TilemapPrivate updateAtlasInfo(); /* Aquire atlas tex */ - shState->texPool().release(atlas.gl); - atlas.gl = shState->texPool().request(atlas.size.x, atlas.size.y); + shState->releaseAtlasTex(atlas.gl); + shState->requestAtlasTex(atlas.size.x, atlas.size.y, atlas.gl); atlasDirty = true; }