27 #if defined(_DEBUG) && defined(_WINDOWS)
28 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
37 template class Singleton<Textures>;
38 template class Database<Texture>;
40 Textures * Textures::create() {
44 Textures::Lose Textures::g_lose;
45 Textures::Unlose Textures::g_unlose;
48 : Database<Texture>(
"config/textures.xml",
"Textures")
54 vr.lend_pre_uninit(&g_lose);
55 vr.lend_post_reinit(&g_unlose);
58 Textures::~Textures() {
69 (*this)[
name].apply_Texture();
73 (*this)[
id].apply_Texture();
77 return dynamic_cast<const Sprite *
>(&(*this)[
id]) != 0;
107 if(m_loaded && ((af != m_anisotropic_filtering) | (bilinear_filtering_ != m_bilinear_filtering) | (mipmapping_ != m_mipmapping))) {
110 m_anisotropic_filtering = af;
111 m_bilinear_filtering = bilinear_filtering_;
112 m_mipmapping = mipmapping_;
118 m_anisotropic_filtering = af;
119 m_bilinear_filtering = bilinear_filtering_;
120 m_mipmapping = mipmapping_;
124 void Textures::on_load() {
128 void Textures::on_clear() {
132 void Textures::on_lose() {
136 Texture * Textures::load(XML_Element_c &xml_element,
const String &
name,
const String &
filename) {
137 const XML_Element_c is_sprite_e = xml_element[
"is_sprite"];
138 const bool is_sprite = is_sprite_e.good() && is_sprite_e.to_bool();
141 const String filepath = xml_element[
"filepath"].to_string();
142 const bool tile = xml_element[
"tile"].to_bool();
147 Sprite *
s =
new Sprite();
149 size_t frame_number = 0;
152 if(
texture.value() ==
"token") {
153 const String identifier =
texture.to_string();
154 s->append_frame(identifier,
get_id(identifier));
156 else if(
texture.value() ==
"file") {
157 const String filepath =
texture[
"filepath"].to_string();
158 const bool tile =
texture[
"tile"].to_bool();
159 const String frame_name = name +
'/' +
ulltoa(frame_number);
163 const unsigned long id =
give(frame_name, texture,
false, filename);
165 s->append_frame(frame_name,
id);
167 else if(texture.value() ==
"is_sprite")
170 throw Database_Load_Entry_Failed(name);
181 bool Textures::m_loaded =
false;
182 bool Textures::m_bilinear_filtering =
true;
183 bool Textures::m_mipmapping =
true;
184 int Textures::m_anisotropic_filtering = 0;
185 bool Textures::m_lazy_loading =
false;
unsigned long give(const String &name, Texture *const &type, const bool &keep, const String &filename="")
Add an entry (which it will later delete)
int get_current_frame(const unsigned long &id)
Get the currently selected frame number for a Sprite.
void set_current_frame(const unsigned long &id, const int &frame_number)
Set the frame number for a Sprite.
static void init(struct bs2b *bs2b)
unsigned long get_id(const String &name) const
Get an id by name, possibly throwing an Error.
EGLImageKHR EGLint * name
void reload()
lose_resources + init
int get_num_frames(const unsigned long &id)
Get the number of frames; returns 0 if it is not a Sprite.
void set_current_frame(const int &frame_number)
Set this frame.
static void remove_pre_uninit(Event::Handler *const &handler)
A Texture Database Singleton.
Textures & get_Textures()
Get access to the singleton.
void apply_Texture(const String &name)
Apply a texture for upcoming polygons (Called by Video::apply_Texture)
GLenum GLenum GLuint texture
bool is_sprite(const String &sprite)
int get_current_frame() const
Get the currently selected frame number.
virtual Texture * load_Texture(const String &filename, const bool &repeat, const bool &lazy_loading=false)=0
Function for loading a Texture; used internally by Textures.
const bool & lost_resources()
Check to see if resources have been lost.
int get_num_frames() const
Get the number of frames.
virtual int get_maximum_anisotropy() const =0
Get the current level of anisotrophy.
static void set_texturing_mode(const int &anisotropic_filtering_, const bool &bilinear_filtering_, const bool &mipmapping_)
Check to see if Textures is set to use lazy loading if possible.
bool is_Sprite(const unsigned long &id)
Does this id point to a Sprite.
Video & get_Video()
Get access to the singleton.
String ulltoa(const unsigned long &number)