X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fbuiltin.cpp;h=217509a20b74c61e83091feda6dc856dd9a3cfcc;hp=9aa6a6c2b4dd6bcef9d71cc26ea9d6af6343646d;hb=e2ed3de4cbbc682ff490a3b0b760b8a45260f611;hpb=992516fcf616fe6ceb55f5a6767eb174aff3f830 diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 9aa6a6c2..217509a2 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "builtin.h" @@ -9,6 +10,18 @@ namespace Msp { namespace GL { namespace SL { +void add_builtin_type(Stage &stage, const string &name, BasicTypeDeclaration::Kind kind, unsigned size, unsigned sign) +{ + RefPtr type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = name; + type->kind = kind; + type->size = size; + type->sign = sign; + stage.content.body.push_back(type); + stage.types[name] = type.get(); +} + Module *get_builtins_module() { static RefPtr builtins_module; @@ -21,15 +34,28 @@ Module *get_builtins_module() if(!io) return 0; - Parser parser; - Module *module = new Module(parser.parse(*io, "", BUILTIN_SOURCE)); + builtins_module = new Module; + add_builtin_type(builtins_module->shared, "void", BasicTypeDeclaration::VOID, 0, true); + add_builtin_type(builtins_module->shared, "bool", BasicTypeDeclaration::BOOL, 1, true); + add_builtin_type(builtins_module->shared, "int", BasicTypeDeclaration::INT, 32, true); + add_builtin_type(builtins_module->shared, "uint", BasicTypeDeclaration::INT, 32, false); + add_builtin_type(builtins_module->shared, "float", BasicTypeDeclaration::FLOAT, 32, true); - builtins_module = module; + try + { + Parser parser(0); + parser.parse(*builtins_module, *io, "", BUILTIN_SOURCE); + } + catch(...) + { + builtins_module = 0; + throw; + } } return builtins_module.get(); } -Stage *get_builtins(Stage::Type type) +const Stage *get_builtins(Stage::Type type) { Module *module = get_builtins_module(); if(!module) @@ -37,10 +63,8 @@ Stage *get_builtins(Stage::Type type) 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; + auto i = find_member(module->stages, type, &Stage::type); + return (i!=module->stages.end() ? &*i : 0); } } // namespace SL