From 4823b6d4e989943c31e20027564ab4eca43f6f8d Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 11 Sep 2015 12:27:45 +0200 Subject: opengl: optimize search for a free slot in texture atlas Change-Id: Ic853457871b914f9c1beb2f648bf7d9d18dce957 --- vcl/opengl/FixedTextureAtlas.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'vcl') diff --git a/vcl/opengl/FixedTextureAtlas.cxx b/vcl/opengl/FixedTextureAtlas.cxx index f6e400597342..8a3e927b4698 100644 --- a/vcl/opengl/FixedTextureAtlas.cxx +++ b/vcl/opengl/FixedTextureAtlas.cxx @@ -36,15 +36,18 @@ OpenGLTexture FixedTextureAtlasManager::InsertBuffer(int nWidth, int nHeight, in { ImplOpenGLTexture* pTexture = nullptr; - for (size_t i = 0; i < mpTextures.size(); i++) + auto funFreeSlot = [] (std::unique_ptr& mpTexture) { - if (mpTextures[i]->mnFreeSlots > 0) - { - pTexture = mpTextures[i].get(); - } - } + return mpTexture->mnFreeSlots > 0; + }; + + auto aIterator = std::find_if(mpTextures.begin(), mpTextures.end(), funFreeSlot); - if (!pTexture) + if (aIterator != mpTextures.end()) + { + pTexture = (*aIterator).get(); + } + else { CreateNewTexture(); pTexture = mpTextures.back().get(); -- cgit