The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
texture_cache.h
Go to the documentation of this file.
1 /*
2  * Dune D3D library - Tobias Alexander Franke 2011
3  * For copyright and license see LICENSE
4  * http://www.tobias-franke.eu
5  */
6 
9 #ifndef DUNE_TEXTURE_CACHE
10 #define DUNE_TEXTURE_CACHE
11 
12 #include <map>
13 
14 #include <D3D11.h>
15 #include <boost/noncopyable.hpp>
16 
17 #include "unicode.h"
18 #include "texture.h"
19 
20 namespace dune
21 {
29  class texture_cache : boost::noncopyable
30  {
31  protected:
32  static std::map<tstring, ID3D11ShaderResourceView*> texture_cache_;
33 
34  texture_cache() {};
35 
36  public:
38  static texture_cache& i();
39 
48  void add_texture(ID3D11Device* device, const tstring& filename);
49 
50  /*
51  * \ brief Request a shader resource view for a texture.
52  *
53  * Request a shader resource view for a texture identified by a filename. If the texture hasn't been loaded yet,
54  * it will be automatically added to the cache. Otherwise, the already cached texture's SRV will be returned.
55  *
56  * \param filename A string of the filename on the disk.
57  * \return An SRV.
58  */
59  ID3D11ShaderResourceView* srv(const tstring& filename) const;
60 
61  void generate_mips(ID3D11DeviceContext* context);
62 
64  void destroy();
65  };
66 
78  void load_texture(ID3D11Device* device, const tstring& filename, ID3D11ShaderResourceView** srv = nullptr);
79 
80  void load_texture(ID3D11Device* device, const tstring& filename, texture& t);
81 }
82 
83 #endif
A texture cache.
Definition: texture_cache.h:29
void add_texture(ID3D11Device *device, const tstring &filename)
Add a new texture to the cache.
Definition: texture_cache.cpp:258
void destroy()
Destroy the texture_cache and free all resources.
Definition: texture_cache.cpp:280
static texture_cache & i()
The static instance of the texture_cache.
Definition: texture_cache.cpp:252
Wrapper for a Direct3D texture object.
Definition: texture.h:25