diff --git a/libraries/gl/src/gl/OglplusHelpers.cpp b/libraries/gl/src/gl/OglplusHelpers.cpp index fc02d75329..587c6488c8 100644 --- a/libraries/gl/src/gl/OglplusHelpers.cpp +++ b/libraries/gl/src/gl/OglplusHelpers.cpp @@ -480,84 +480,3 @@ ShapeWrapperPtr loadLaser(const ProgramPtr& program) { return std::make_shared(shapes::ShapeWrapper("Position", shapes::Laser(), *program)); } -void TextureRecycler::setSize(const uvec2& size) { - if (size == _size) { - return; - } - _size = size; - while (!_readyTextures.empty()) { - _readyTextures.pop(); - } - std::set toDelete; - std::for_each(_allTextures.begin(), _allTextures.end(), [&](Map::const_reference item) { - if (!item.second._active && item.second._size != _size) { - toDelete.insert(item.first); - } - }); - std::for_each(toDelete.begin(), toDelete.end(), [&](Map::key_type key) { - _allTextures.erase(key); - }); -} - -void TextureRecycler::clear() { - while (!_readyTextures.empty()) { - _readyTextures.pop(); - } - _allTextures.clear(); -} - -TexturePtr TextureRecycler::getNextTexture() { - using namespace oglplus; - if (_readyTextures.empty()) { - TexturePtr newTexture(new Texture()); - - if (_useMipmaps) { - Context::Bound(oglplus::Texture::Target::_2D, *newTexture) - .MinFilter(TextureMinFilter::LinearMipmapLinear) - .MagFilter(TextureMagFilter::Linear) - .WrapS(TextureWrap::ClampToEdge) - .WrapT(TextureWrap::ClampToEdge) - .Anisotropy(8.0f) - .LODBias(-0.2f) - .Image2D(0, PixelDataInternalFormat::RGBA8, - _size.x, _size.y, - 0, PixelDataFormat::RGB, PixelDataType::UnsignedByte, nullptr); - } else { - Context::Bound(oglplus::Texture::Target::_2D, *newTexture) - .MinFilter(TextureMinFilter::Linear) - .MagFilter(TextureMagFilter::Linear) - .WrapS(TextureWrap::ClampToEdge) - .WrapT(TextureWrap::ClampToEdge) - .Image2D(0, PixelDataInternalFormat::RGBA8, - _size.x, _size.y, - 0, PixelDataFormat::RGB, PixelDataType::UnsignedByte, nullptr); - } - GLuint texId = GetName(*newTexture); - _allTextures[texId] = TexInfo{ newTexture, _size }; - _readyTextures.push(newTexture); - } - - TexturePtr result = _readyTextures.front(); - _readyTextures.pop(); - - GLuint texId = GetName(*result); - auto& item = _allTextures[texId]; - item._active = true; - - return result; -} - -void TextureRecycler::recycleTexture(GLuint texture) { - Q_ASSERT(_allTextures.count(texture)); - auto& item = _allTextures[texture]; - Q_ASSERT(item._active); - item._active = false; - if (item._size != _size) { - // Buh-bye - _allTextures.erase(texture); - return; - } - - _readyTextures.push(item._tex); -} - diff --git a/libraries/gl/src/gl/OglplusHelpers.h b/libraries/gl/src/gl/OglplusHelpers.h index ab47689312..52e63f9431 100644 --- a/libraries/gl/src/gl/OglplusHelpers.h +++ b/libraries/gl/src/gl/OglplusHelpers.h @@ -188,30 +188,3 @@ protected: using BasicFramebufferWrapperPtr = std::shared_ptr; -class TextureRecycler { -public: - TextureRecycler(bool useMipmaps) : _useMipmaps(useMipmaps) {} - void setSize(const uvec2& size); - void clear(); - TexturePtr getNextTexture(); - void recycleTexture(GLuint texture); - -private: - - struct TexInfo { - TexturePtr _tex; - uvec2 _size; - bool _active{ false }; - - TexInfo() {} - TexInfo(TexturePtr tex, const uvec2& size) : _tex(tex), _size(size) {} - }; - - using Map = std::map; - using Queue = std::queue; - - Map _allTextures; - Queue _readyTextures; - uvec2 _size{ 1920, 1080 }; - bool _useMipmaps; -};