X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fresources%2Fresources.cpp;h=ef8b93255fca8927104d35e4434e4a68cf5ee1bf;hb=22d5405729048ee2677a1e45e309e6328de64a26;hp=d52dbe34fb61c745e74c4cad108cdd0a604990e7;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index d52dbe34..ef8b9325 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -8,11 +8,11 @@ #include "lighting.h" #include "material.h" #include "mesh.h" +#include "module.h" #include "object.h" #include "pipelinetemplate.h" #include "pose.h" #include "program.h" -#include "programcompiler.h" #include "resourcemanager.h" #include "resources.h" #include "sampler.h" @@ -21,6 +21,7 @@ #include "texture2d.h" #include "texture2darray.h" #include "texturecube.h" +#include "glsl/compiler.h" using namespace std; @@ -28,6 +29,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), @@ -43,10 +45,11 @@ Resources::Resources(): 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").creator(&Resources::create_module); add_type().keyword("object"); add_type().suffix(".pipe").keyword("pipeline"); 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(".tech").keyword("technique"); add_type().base().suffix(".tex1d").keyword("texture1d"); @@ -65,6 +68,7 @@ const DataFile::CollectionSource &Resources::get_builtins() if(!init_done) { + init_builtin_data(builtins); init_shaderlib(builtins); init_done = true; } @@ -164,20 +168,30 @@ Texture2D *Resources::create_texture2d(const string &name) return 0; } +Module *Resources::create_module(const string &name) +{ + if(RefPtr io = open_raw(name)) + { + RefPtr module = new Module; + module->load_source(*io, this, name); + return module.release(); + } + + return 0; +} + Program *Resources::create_program(const string &name) { string ext = FS::extpart(name); - if(ext==".shader") - return 0; - - if(RefPtr io = open_raw(name)) + string base = FS::basepart(name); + string ext2 = FS::extpart(base); + if(ext==".shader" && ext2==".glsl") { - ProgramCompiler compiler; - compiler.compile(*io, this, name); - RefPtr program = new Program; - compiler.add_shaders(*program); - program->link(); - return program.release(); + Module &module = get(base); + RefPtr shprog = new Program; + shprog->add_stages(module); + shprog->link(); + return shprog.release(); } return 0;