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 "ogl_texturecache.hxx"
12 #include <com/sun/star/geometry/IntegerSize2D.hpp>
16 using namespace ::com::sun::star
;
20 TextureCache::TextureCache() :
26 TextureCache::~TextureCache()
31 void TextureCache::flush()
33 // un-bind any texture
34 glBindTexture(GL_TEXTURE_2D
, 0);
36 // delete all cached textures
37 TextureCacheMapT::const_iterator aCurr
=maCache
.begin();
38 const TextureCacheMapT::const_iterator aEnd
=maCache
.end();
39 while( aCurr
!= aEnd
)
41 glDeleteTextures(1, &aCurr
->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 TextureCacheMapT::iterator aNext
;
57 TextureCacheMapT::iterator aCurr
=maCache
.begin();
58 const TextureCacheMapT::iterator aEnd
=maCache
.end();
59 while( aCurr
!= aEnd
)
62 if( aCurr
->second
.bOld
)
64 glDeleteTextures(1, &aCurr
->second
.nTexture
);
69 aCurr
->second
.bOld
= true;
78 unsigned int TextureCache::getTexture( const geometry::IntegerSize2D
& rPixelSize
,
79 const sal_Int8
* pPixel
,
80 sal_uInt32 nPixelCrc32
) const
82 unsigned int nTexture(0);
84 // texture already cached?
85 TextureCacheMapT::iterator aCacheEntry
;
86 if( (aCacheEntry
=maCache
.find(nPixelCrc32
)) == maCache
.end() )
88 // nope, insert new entry
89 glGenTextures(1, &nTexture
);
90 glBindTexture(GL_TEXTURE_2D
, nTexture
);
92 // TODO(E3): handle limited texture sizes -
93 // glGetIntegerv(GL_MAX_TEXTURE_SIZE)
94 glTexImage2D(GL_TEXTURE_2D
,
101 GL_UNSIGNED_INT_8_8_8_8_REV
,
104 maCache
[nPixelCrc32
].nTexture
= nTexture
;
111 nTexture
= aCacheEntry
->second
.nTexture
;
112 aCacheEntry
->second
.bOld
= false;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */