853.5.3
by Gord Allott
added texture caching support |
1 |
/*
|
2 |
* Copyright (C) 2010 Canonical Ltd
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License version 3 as
|
|
6 |
* published by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
* Authored by Gordon Allott <gord.allott@canonical.com>
|
|
17 |
*/
|
|
18 |
||
19 |
#ifndef TEXTURECACHE_H
|
|
20 |
#define TEXTURECACHE_H
|
|
21 |
#include <Nux/Nux.h> |
|
22 |
#include <string> |
|
23 |
#include <map> |
|
24 |
#include <vector> |
|
25 |
#include <sigc++/sigc++.h> |
|
26 |
||
27 |
/* Basically a nice simple texture cache system, you ask the cache for a texture by id
|
|
28 |
* if the texture does not exist it calls the callback function you provide it with to create the
|
|
29 |
* texture, then returns it.
|
|
30 |
* you should remember to ref/unref the textures yourself however
|
|
31 |
*/
|
|
32 |
||
33 |
class TextureCache |
|
34 |
{
|
|
35 |
||
36 |
public: |
|
37 |
// id, width, height, texture
|
|
853.5.10
by Gord Allott
changed struct name and made con/de/structor private |
38 |
typedef sigc::slot<void, const char *, int, int, nux::BaseTexture **> CreateTextureCallback; |
853.5.3
by Gord Allott
added texture caching support |
39 |
|
40 |
/* don't new this class, use getdefault */
|
|
41 |
||
42 |
static TextureCache * GetDefault (); |
|
853.5.10
by Gord Allott
changed struct name and made con/de/structor private |
43 |
nux::BaseTexture * FindTexture (const char *texture_id, int width, int height, CreateTextureCallback callback); |
853.5.3
by Gord Allott
added texture caching support |
44 |
|
45 |
protected: |
|
853.5.10
by Gord Allott
changed struct name and made con/de/structor private |
46 |
TextureCache (); |
47 |
~TextureCache (); |
|
853.5.3
by Gord Allott
added texture caching support |
48 |
char * Hash (const char *id, int width, int height); |
49 |
std::map<std::string, nux::BaseTexture *> _cache; |
|
853.5.7
by Gord Allott
moved texture cache over to a nux destroy signa |
50 |
std::map<nux::BaseTexture *, std::string> _cache_inverse; // just for faster lookups |
51 |
void OnDestroyNotify (nux::Trackable *Object); |
|
853.5.3
by Gord Allott
added texture caching support |
52 |
};
|
53 |
||
54 |
#endif // TEXTURECACHE_H |