#include "animation.h"
#include "armature.h"
#include "camera.h"
+#include "error.h"
#include "font.h"
#include "keyframe.h"
#include "light.h"
void init_shaderlib(DataFile::BuiltinSource &);
void init_builtin_data(DataFile::BuiltinSource &);
-Resources::Resources():
- default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
- default_tex_anisotropy(1.0f),
+Resources *Resources::global_resources = 0;
+
+Resources::Resources(bool set_as_global):
srgb_conversion(false),
resource_manager(0)
{
add_type<Animation>().suffix(".anim").keyword("animation");
add_type<Armature>().suffix(".arma").keyword("armature");
- add_type<Camera>().keyword("camera");
+ add_type<Camera>().keyword("camera")
+ .notify(&Resources::set_debug_name<Camera>);
add_type<Font>().keyword("font");
add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
add_type<Light>().keyword("light");
- add_type<Lighting>().suffix(".lightn").keyword("lighting");
+ add_type<Lighting>().suffix(".lightn").keyword("lighting")
+ .notify(&Resources::set_debug_name<Lighting>);
add_type<Material>().suffix(".mat")
.creator(&Resources::create_material).notify(&Resources::set_debug_name<Material>);
add_type<Mesh>().keyword("mesh")
.notify(&Resources::set_debug_name<Texture2DArray>);
add_source(get_builtins());
+
+ if(set_as_global && !global_resources)
+ global_resources = this;
+}
+
+Resources::~Resources()
+{
+ if(this==global_resources)
+ global_resources = 0;
+}
+
+Resources &Resources::get_global()
+{
+ if(!global_resources)
+ throw invalid_operation("no global resources");
+ return *global_resources;
}
const DataFile::CollectionSource &Resources::get_builtins()
return builtins;
}
-void Resources::set_default_texture_filter(TextureFilter tf)
-{
- default_tex_filter = tf;
-}
-
-void Resources::set_default_texture_anisotropy(float a)
-{
- default_tex_anisotropy = a;
-}
-
void Resources::set_srgb_conversion(bool c)
{
srgb_conversion = c;
image.load_io(*io);
tex = new Texture2D(resource_manager);
- Sampler &samp = tex->get_default_sampler();
- if(is_mipmapped(default_tex_filter))
- {
- tex->set_auto_generate_mipmap(true);
- samp.set_mag_filter(LINEAR);
- }
- else
- samp.set_mag_filter(default_tex_filter);
- samp.set_min_filter(default_tex_filter);
- samp.set_max_anisotropy(default_tex_anisotropy);
if(resource_manager)
resource_manager->set_resource_location(*tex, *this, name);
Module &module = get<Module>(base);
RefPtr<Program> shprog = new Program;
shprog->add_stages(module);
- shprog->link();
return shprog.release();
}