Initial integration, lots of broken stuff
[supertux.git] / src / unison / include / unison / video / backend / Texture.hpp
1 //          Copyright Timothy Goya 2007.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UNISON_VIDEO_BACKEND_TEXTURE_HPP
7 #define UNISON_VIDEO_BACKEND_TEXTURE_HPP
8
9 #include <unison/video/Blittable.hpp>
10 #include <unison/video/Surface.hpp>
11 #include <unison/video/Texture.hpp>
12
13 #include <string>
14 #include <vector>
15 #include <map>
16
17 namespace Unison
18 {
19    namespace Video
20    {
21       namespace Backend
22       {
23          class Renderer;
24          /// Backend-specific texture interface
25          class Texture : public Blittable
26          {
27             public:
28                /// Destructor
29                virtual ~Texture();
30
31                /// Get the size of the texture
32                /// \return The texture size 
33                Area get_size();
34
35                /// Called when referenced
36                void ref();
37
38                /// Called when a reference goes away
39                void unref();
40
41                /// Get the number of references to the texture
42                /// \return The reference count
43                int get_refcount();
44
45                /// Get the equavalent surface to the texture
46                virtual const Surface get_surface() = 0;
47
48                /// Save the texture, called when the window is about to be created or recreated
49                virtual void save() = 0;
50
51                /// Save all the textures
52                static std::vector<Surface> save_textures();
53
54                /// Load the textures
55                static void load_textures(const std::vector<Surface> &surfaces);
56
57                /// Recover previously used but now unused texture IDs
58                /// \return A map of what IDs changed during recovery
59                static std::map<TextureID, TextureID> recover_texture_ids();
60
61                /// Retrieve the texture ID for the filename
62                /// \param[in] filename The filename of the image file
63                /// \return The texture ID of the texture
64                static TextureID get_texture_id(const std::string &filename);
65
66                /// Retrieve the texture ID for the filename
67                /// \param[in] filename The filename of the image file
68                /// \param[in] colorkey The colorkey used by the file
69                /// \return The texture ID of the texture
70                static TextureID get_texture_id(const std::string &filename, const Color &colorkey);
71
72                /// Retrieve the texture ID for the surface
73                /// \param[in] surface The surface to optimize
74                /// \return The texture ID of the texture
75                static TextureID get_texture_id(const Surface &surface);
76
77                /// Retrieve the texture ID for the texture
78                /// \param[in] texture The texture
79                /// \return The texture ID of the texture
80                static TextureID get_texture_id(Texture *texture);
81
82                /// Retrieve the texture corresponding to the texture ID
83                /// \param[in] id The texture ID
84                /// \return The corresponding texture
85                static Texture *get_texture(TextureID id);
86
87                /// Retrieve the name associated with the texture ID
88                /// \param[in] texture The texture
89                /// \return The texture ID of the texture
90                static std::string get_name(TextureID id);
91             protected:
92                /// Create a texture from the given surface with the given name
93                /// \param[in] surface The surface to optimize
94                Texture(const Surface &surface);
95
96                /// The surface the texture is based from
97                Surface surface;
98
99                /// The size of the texture
100                Area size;
101
102                /// The number of references to the texture
103                int refcount;
104
105                /// All of the textures in existence
106                static std::vector<Texture *> textures;
107
108                /// The subset of all textures that have names
109                static std::map<std::string, TextureID> named_textures;
110          };
111       }
112    }
113 }
114
115 #endif