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)
6 #ifndef UNISON_VIDEO_BACKEND_TEXTURE_HPP
7 #define UNISON_VIDEO_BACKEND_TEXTURE_HPP
9 #include <unison/video/Blittable.hpp>
10 #include <unison/video/Surface.hpp>
11 #include <unison/video/Texture.hpp>
24 /// Backend-specific texture interface
25 class Texture : public Blittable
31 /// Get the size of the texture
32 /// \return The texture size
35 /// Called when referenced
38 /// Called when a reference goes away
41 /// Get the number of references to the texture
42 /// \return The reference count
45 /// Get the equavalent surface to the texture
46 virtual const Surface get_surface() = 0;
48 /// Save the texture, called when the window is about to be created or recreated
49 virtual void save() = 0;
51 /// Save all the textures
52 static std::vector<Surface> save_textures();
55 static void load_textures(const std::vector<Surface> &surfaces);
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();
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);
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);
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);
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);
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);
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);
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);
96 /// The surface the texture is based from
99 /// The size of the texture
102 /// The number of references to the texture
105 /// All of the textures in existence
106 static std::vector<Texture *> textures;
108 /// The subset of all textures that have names
109 static std::map<std::string, TextureID> named_textures;