X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=c9db211b2172480300732c6106526c75e6070bbc;hb=3b0cb993f410b05fc6309d41aa292f4e57c35519;hp=114a08ecf838f0f6fd6fbf5c517fa64e9a07fe5f;hpb=73bef37da97b6da0b99227f63235cb52c4e56c44;p=libs%2Fgl.git diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index 114a08ec..c9db211b 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -5,16 +5,19 @@ #include "camera.h" #include "font.h" #include "keyframe.h" +#include "light.h" #include "lighting.h" #include "material.h" #include "mesh.h" +#include "module.h" #include "object.h" -#include "pipelinetemplate.h" +#include "sequencetemplate.h" #include "pose.h" #include "program.h" #include "resourcemanager.h" #include "resources.h" #include "sampler.h" +#include "scene.h" #include "technique.h" #include "texture1d.h" #include "texture2d.h" @@ -28,6 +31,7 @@ namespace Msp { namespace GL { void init_shaderlib(DataFile::BuiltinSource &); +void init_builtin_data(DataFile::BuiltinSource &); Resources::Resources(): default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR), @@ -40,14 +44,17 @@ Resources::Resources(): add_type().keyword("camera"); add_type().keyword("font"); 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().keyword("object"); - add_type().suffix(".pipe").keyword("pipeline"); + add_type().suffix(".seq").keyword("sequence"); add_type().keyword("pose"); - add_type().keyword("shader").suffix(".glsl").creator(&Resources::create_program); + 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); @@ -65,6 +72,7 @@ const DataFile::CollectionSource &Resources::get_builtins() if(!init_done) { + init_builtin_data(builtins); init_shaderlib(builtins); init_done = true; } @@ -120,6 +128,19 @@ Mesh *Resources::create_mesh(const string &name) return 0; } +Scene *Resources::create_scene(const string &name) +{ + if(RefPtr io = open_raw(name)) + { + DataFile::Parser parser(*io, name); + Scene::GenericLoader ldr(*this); + ldr.load(parser); + return ldr.get_scene(); + } + + return 0; +} + Texture2D *Resources::create_texture2d(const string &name) { string ext = FS::extpart(name); @@ -128,20 +149,23 @@ Texture2D *Resources::create_texture2d(const string &name) if(RefPtr io = open_raw(name)) { - Graphics::Image image; - if(!resource_manager) - image.load_io(*io); - - RefPtr tex = new Texture2D(resource_manager); + RefPtr tex; if(ext==".tex2d") { + tex = new Texture2D(resource_manager); DataFile::Parser parser(*io, name); Texture2D::Loader ldr(*tex, *this); ldr.load(parser); } else { + // Verify that the image is loadable + Graphics::Image image; + if(!resource_manager) + image.load_io(*io); + + tex = new Texture2D(resource_manager); Sampler &samp = tex->get_default_sampler(); if(is_mipmapped(default_tex_filter)) { @@ -152,37 +176,74 @@ Texture2D *Resources::create_texture2d(const string &name) 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); + else + tex->image(image); } - if(resource_manager) - resource_manager->set_resource_location(*tex, *this, name); - else - tex->image(image); return tex.release(); } return 0; } -Program *Resources::create_program(const string &name) +Module *Resources::create_module(const string &name) { string ext = FS::extpart(name); - if(ext==".shader") + if(ext!=".glsl" && ext!=".spv") return 0; if(RefPtr io = open_raw(name)) { - SL::Compiler compiler; - compiler.load_source(*io, this, name); - compiler.compile(); - RefPtr program = new Program; - compiler.add_shaders(*program); - program->link(); - return program.release(); + if(ext==".glsl") + { + RefPtr module = new GlslModule; + module->load_source(*io, this, name); + return module.release(); + } + else if(ext==".spv") + { + RefPtr module = new SpirVModule; + module->load_code(*io); + return module.release(); + } + } + + return 0; +} + +Program *Resources::create_program(const string &name) +{ + string ext = FS::extpart(name); + string base = FS::basepart(name); + string ext2 = FS::extpart(base); + if(ext==".shader" && (ext2==".glsl" || ext2==".spv")) + { + Module &module = get(base); + RefPtr shprog = new Program; + shprog->add_stages(module); + shprog->link(); + return shprog.release(); } return 0; } + +Resources::Loader::Loader(Resources &r): + DerivedObjectLoader(r) +{ + add("scene", &Loader::scene); +} + +void Resources::Loader::scene(const string &name) +{ + Scene::GenericLoader ldr(obj); + load_sub_with(ldr); + obj.add(name, ldr.get_scene()); +} + } // namespace GL } // namespace Msp