X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fbuiltin.cpp;h=12602707db80ca5043b6582f5b6917422cb2f477;hb=91e65bc9e24a6889995081035f6f6f0a78a6c20e;hp=7aecda3c244bbd31d028021687f1352bc9dd584e;hpb=696a97bd7411d69953c1a9e4b5f3dfb4c1d848f1;p=libs%2Fgl.git diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 7aecda3c..12602707 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -1,57 +1,92 @@ +#include +#include #include "builtin.h" -#include "generate.h" #include "parser.h" using namespace std; -namespace { - -const char builtins_src[] = - "#pragma MSP stage(vertex)\n" - "out gl_PerVertex {\n" - " vec4 gl_Position;\n" - " float gl_ClipDistance[];\n" - "};\n" - "#pragma MSP stage(geometry)\n" - "in gl_PerVertex {\n" - " vec4 gl_Position;\n" - " float gl_ClipDistance[];\n" - "} gl_in[];\n" - "out gl_PerVertex {\n" - " vec4 gl_Position;\n" - " float gl_ClipDistance[];\n" - "};\n"; - -} - namespace Msp { namespace GL { namespace SL { -Module *create_builtins_module() +void populate_types(Stage &stage) { - Parser parser; - Module *module = new Module(parser.parse(builtins_src, "")); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) - { - VariableResolver resolver; - i->content.visit(resolver); - for(map::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j) - j->second->linked_declaration = j->second; - } - return module; + for(NodeList::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i) + if(TypeDeclaration *type = dynamic_cast(i->get())) + stage.types[type->name] = type; } -Module &get_builtins_module() +Module *get_builtins_module() { - static RefPtr builtins_module = create_builtins_module(); - return *builtins_module; + static RefPtr builtins_module; + static bool initialized = false; + if(!initialized) + { + initialized = true; + + RefPtr io = Resources::get_builtins().open("_builtin.glsl"); + if(!io) + return 0; + + Parser parser; + Module *module = new Module(parser.parse(*io, "", BUILTIN_SOURCE)); + + NodeList &shared_body = module->shared.content.body; + NodeList::iterator insert_point = shared_body.begin(); + + RefPtr type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "void"; + type->kind = BasicTypeDeclaration::VOID; + shared_body.insert(insert_point, type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "bool"; + type->size = 1; + type->kind = BasicTypeDeclaration::BOOL; + shared_body.insert(insert_point, type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "int"; + type->size = 32; + type->kind = BasicTypeDeclaration::INT; + shared_body.insert(insert_point, type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "uint"; + type->size = 32; + type->sign = false; + type->kind = BasicTypeDeclaration::INT; + shared_body.insert(insert_point, type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "float"; + type->size = 32; + type->kind = BasicTypeDeclaration::FLOAT; + shared_body.insert(insert_point, type); + + populate_types(module->shared); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + populate_types(*i); + + builtins_module = module; + } + return builtins_module.get(); } -Stage *get_builtins(StageType type) +const Stage *get_builtins(Stage::Type type) { - Module &module = get_builtins_module(); - for(list::iterator i=module.stages.begin(); i!=module.stages.end(); ++i) + Module *module = get_builtins_module(); + if(!module) + return 0; + + if(type==Stage::SHARED) + return &module->shared; + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) if(i->type==type) return &*i; return 0;