diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-08-19 11:51:15 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-08-24 19:08:10 +0900 |
commit | b26ba85d04e81f48622dfdbb71d9d80b54dacc40 (patch) | |
tree | a349a4e646dbe809fdfbf468b94188052b1bcedc /vcl/inc/opengl | |
parent | 652e3d2dbdd2d6f43953da3ae37cfc98d350328d (diff) |
Fixed (fixed size) texture atlas for "caching" OpenGL texures
Change-Id: I7fe90c0a0033b4d9a341a4f0b8356d7f7133e93e
Diffstat (limited to 'vcl/inc/opengl')
-rw-r--r-- | vcl/inc/opengl/FixedTextureAtlas.hxx | 39 | ||||
-rw-r--r-- | vcl/inc/opengl/texture.hxx | 43 |
2 files changed, 80 insertions, 2 deletions
diff --git a/vcl/inc/opengl/FixedTextureAtlas.hxx b/vcl/inc/opengl/FixedTextureAtlas.hxx new file mode 100644 index 000000000000..c4f5d6065696 --- /dev/null +++ b/vcl/inc/opengl/FixedTextureAtlas.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_VCL_INC_OPENGL_FIXED_TEXTURE_ATLAS_H +#define INCLUDED_VCL_INC_OPENGL_FIXED_TEXTURE_ATLAS_H + +#include "opengl/texture.hxx" + + +class VCL_PLUGIN_PUBLIC FixedTextureAtlasManager +{ + std::vector<std::unique_ptr<ImplOpenGLTexture>> mpTextures; + + int mWidthFactor; + int mHeightFactor; + int mSubTextureSize; + + void CreateNewTexture(); + +public: + FixedTextureAtlasManager(int nWidthFactor, int nHeightFactor, int nTextureSize); + OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData); + + int GetSubtextureSize() + { + return mSubTextureSize; + } +}; + +#endif // INCLUDED_VCL_INC_OPENGL_FIXED_TEXTURE_ATLAS_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx index b68397641326..51f7040ab9ef 100644 --- a/vcl/inc/opengl/texture.hxx +++ b/vcl/inc/opengl/texture.hxx @@ -26,6 +26,8 @@ #include <rtl/ustring.hxx> #include <tools/gen.hxx> +#include <memory> + class ImplOpenGLTexture { public: @@ -35,10 +37,45 @@ public: int mnHeight; GLenum mnFilter; + std::unique_ptr<std::vector<int>> mpSlotReferences; + int mnFreeSlots; + ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate ); ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData ); ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight ); ~ImplOpenGLTexture(); + + bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData); + + void IncreaseRefCount(int nSlotNumber) + { + mnRefCount++; + if (mpSlotReferences && nSlotNumber >= 0) + { + if (mpSlotReferences->at(nSlotNumber) == 0) + mnFreeSlots--; + mpSlotReferences->at(nSlotNumber)++; + } + } + + void DecreaseRefCount(int nSlotNumber) + { + mnRefCount--; + if (mpSlotReferences && nSlotNumber >= 0) + { + mpSlotReferences->at(nSlotNumber)--; + if (mpSlotReferences->at(nSlotNumber) == 0) + mnFreeSlots++; + } + } + + bool ExistRefs() + { + return mnRefCount > 0; + } + + bool InitializeSlots(int nSlotSize); + int FindFreeSlot(); }; class VCL_PLUGIN_PUBLIC OpenGLTexture @@ -46,12 +83,14 @@ class VCL_PLUGIN_PUBLIC OpenGLTexture private: // if the rect size doesn't match the mpImpl one, this instance // is a sub-area from the real OpenGL texture - Rectangle maRect; - + Rectangle maRect; ImplOpenGLTexture* mpImpl; + int mnSlotNumber; public: OpenGLTexture(); + OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber = 0); + OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true ); OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData ); OpenGLTexture( int nX, int nY, int nWidth, int nHeight ); |