1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
14 #include <com/sun/star/geometry/IntegerSize2D.hpp>
16 #include "ogl_texturecache.hxx"
19 using namespace ::com::sun::star
;
23 TextureCache::TextureCache() :
29 TextureCache::~TextureCache()
34 void TextureCache::flush()
36 // un-bind any texture
37 glBindTexture(GL_TEXTURE_2D
, 0);
39 // delete all cached textures
40 for( const auto& rCache
: maCache
)
42 glDeleteTextures( 1, &rCache
.second
.nTexture
);
50 void TextureCache::prune()
52 // un-bind any texture
53 glBindTexture(GL_TEXTURE_2D
, 0);
55 // delete already "old" textures, mark "new" entries "old"
56 const TextureCacheMapT::const_iterator aEnd
= maCache
.end();
57 for( auto aCurr
= maCache
.begin(); aCurr
!= aEnd
; /* increment managed in loop */)
59 if( aCurr
->second
.bOld
)
61 glDeleteTextures( 1, &aCurr
->second
.nTexture
);
62 aCurr
= maCache
.erase( aCurr
);
66 aCurr
->second
.bOld
= true;
75 unsigned int TextureCache::getTexture( const geometry::IntegerSize2D
& rPixelSize
,
76 const sal_Int8
* pPixel
,
77 sal_uInt32 nPixelCrc32
) const
79 unsigned int nTexture(0);
81 // texture already cached?
82 TextureCacheMapT::iterator aCacheEntry
;
83 if( (aCacheEntry
=maCache
.find(nPixelCrc32
)) == maCache
.end() )
85 // nope, insert new entry
86 glGenTextures(1, &nTexture
);
87 glBindTexture(GL_TEXTURE_2D
, nTexture
);
89 // TODO(E3): handle limited texture sizes -
90 // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
91 glTexImage2D(GL_TEXTURE_2D
,
98 GL_UNSIGNED_INT_8_8_8_8_REV
,
101 maCache
[nPixelCrc32
].nTexture
= nTexture
;
108 nTexture
= aCacheEntry
->second
.nTexture
;
109 aCacheEntry
->second
.bOld
= false;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */