X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=79c95932b6c52b03f45c669d58a68f71d5e2bbeb;hp=c9db211b2172480300732c6106526c75e6070bbc;hb=fe2fc291a4fc618425c64112c9ffd3519f0b8a3e;hpb=3b0cb993f410b05fc6309d41aa292f4e57c35519 diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index c9db211b..79c95932 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -3,6 +3,7 @@ #include "animation.h" #include "armature.h" #include "camera.h" +#include "error.h" #include "font.h" #include "keyframe.h" #include "light.h" @@ -33,7 +34,9 @@ namespace GL { void init_shaderlib(DataFile::BuiltinSource &); void init_builtin_data(DataFile::BuiltinSource &); -Resources::Resources(): +Resources *Resources::global_resources = 0; + +Resources::Resources(bool set_as_global): default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR), default_tex_anisotropy(1.0f), srgb_conversion(false), @@ -46,23 +49,51 @@ Resources::Resources(): add_type().suffix(".kframe").keyword("keyframe"); add_type().keyword("light"); add_type().suffix(".lightn").keyword("lighting"); - add_type().suffix(".mat").creator(&Resources::create_material); - add_type().keyword("mesh").creator(&Resources::create_mesh); - add_type().suffix(".glsl").suffix(".spv").creator(&Resources::create_module); + add_type().suffix(".mat") + .creator(&Resources::create_material).notify(&Resources::set_debug_name); + add_type().keyword("mesh") + .creator(&Resources::create_mesh).notify(&Resources::set_debug_name); + add_type().suffix(".glsl").suffix(".spv") + .creator(&Resources::create_module); add_type().keyword("object"); add_type().suffix(".seq").keyword("sequence"); add_type().keyword("pose"); - add_type().keyword("shader").creator(&Resources::create_program); - add_type().suffix(".samp").keyword("sampler"); - add_type().suffix(".scene").creator(&Resources::create_scene); - add_type().suffix(".tech").keyword("technique"); - add_type().base().suffix(".tex1d").keyword("texture1d"); - add_type().base().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d); - add_type().base().suffix(".tex3d").keyword("texture3d"); - add_type().base().suffix(".texcb").keyword("texture_cube"); - add_type().base().suffix(".tex2da").keyword("texture2d_array"); + add_type().keyword("shader") + .creator(&Resources::create_program).notify(&Resources::set_debug_name); + add_type().suffix(".samp").keyword("sampler") + .notify(&Resources::set_debug_name); + add_type().suffix(".scene") + .creator(&Resources::create_scene); + add_type().suffix(".tech").keyword("technique") + .notify(&Resources::set_debug_name); + add_type().base().suffix(".tex1d").keyword("texture1d") + .notify(&Resources::set_debug_name); + add_type().base().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d") + .creator(&Resources::create_texture2d).notify(&Resources::set_debug_name); + add_type().base().suffix(".tex3d").keyword("texture3d") + .notify(&Resources::set_debug_name); + add_type().base().suffix(".texcb").keyword("texture_cube") + .notify(&Resources::set_debug_name); + add_type().base().suffix(".tex2da").keyword("texture2d_array") + .notify(&Resources::set_debug_name); 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() @@ -210,6 +241,15 @@ Module *Resources::create_module(const string &name) return module.release(); } } + else if(ext==".spv") + { + if((io = open_raw(FS::basepart(name)+".glsl"))) + { + RefPtr module = new SpirVModule; + module->load_source(*io, this, name); + return module.release(); + } + } return 0; } @@ -231,6 +271,14 @@ Program *Resources::create_program(const string &name) return 0; } +template +void Resources::set_debug_name(const string &name, T &item) +{ +#ifdef DEBUG + item.set_debug_name(name); +#endif +} + Resources::Loader::Loader(Resources &r): DerivedObjectLoader(r)