1 #include <msp/core/algorithm.h>
2 #include <msp/gl/resources.h>
3 #include <msp/io/seekable.h>
13 void add_builtin_type(Stage &stage, const string &name, BasicTypeDeclaration::Kind kind, unsigned size, unsigned sign)
15 RefPtr<BasicTypeDeclaration> type = new BasicTypeDeclaration;
16 type->source = BUILTIN_SOURCE;
21 stage.content.body.push_back(type);
22 stage.types[name] = type.get();
25 Module *get_builtins_module()
27 static RefPtr<Module> builtins_module;
28 static bool initialized = false;
33 RefPtr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
37 builtins_module = new Module;
38 add_builtin_type(builtins_module->shared, "void", BasicTypeDeclaration::VOID, 0, true);
39 add_builtin_type(builtins_module->shared, "bool", BasicTypeDeclaration::BOOL, 1, true);
40 add_builtin_type(builtins_module->shared, "int", BasicTypeDeclaration::INT, 32, true);
41 add_builtin_type(builtins_module->shared, "uint", BasicTypeDeclaration::INT, 32, false);
42 add_builtin_type(builtins_module->shared, "float", BasicTypeDeclaration::FLOAT, 32, true);
47 parser.parse(*builtins_module, *io, "<builtin>", BUILTIN_SOURCE);
55 return builtins_module.get();
58 const Stage *get_builtins(Stage::Type type)
60 Module *module = get_builtins_module();
64 if(type==Stage::SHARED)
65 return &module->shared;
66 auto i = find_member(module->stages, type, &Stage::type);
67 return (i!=module->stages.end() ? &*i : 0);