1 #include <msp/gl/resources.h>
2 #include <msp/io/seekable.h>
12 void populate_types(Stage &stage)
14 for(NodeList<Statement>::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
15 if(TypeDeclaration *type = dynamic_cast<TypeDeclaration *>(i->get()))
16 stage.types[type->name] = type;
19 Module *get_builtins_module()
21 static RefPtr<Module> builtins_module;
22 static bool initialized = false;
27 RefPtr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
32 Module *module = new Module(parser.parse(*io, "<builtin>", BUILTIN_SOURCE));
34 NodeList<Statement> &shared_body = module->shared.content.body;
35 NodeList<Statement>::iterator insert_point = shared_body.begin();
37 RefPtr<BasicTypeDeclaration> type = new BasicTypeDeclaration;
38 type->source = BUILTIN_SOURCE;
40 type->kind = BasicTypeDeclaration::VOID;
41 shared_body.insert(insert_point, type);
43 type = new BasicTypeDeclaration;
44 type->source = BUILTIN_SOURCE;
47 type->kind = BasicTypeDeclaration::BOOL;
48 shared_body.insert(insert_point, type);
50 type = new BasicTypeDeclaration;
51 type->source = BUILTIN_SOURCE;
54 type->kind = BasicTypeDeclaration::INT;
55 shared_body.insert(insert_point, type);
57 type = new BasicTypeDeclaration;
58 type->source = BUILTIN_SOURCE;
61 type->kind = BasicTypeDeclaration::FLOAT;
62 shared_body.insert(insert_point, type);
64 populate_types(module->shared);
65 for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
68 builtins_module = module;
70 return builtins_module.get();
73 const Stage *get_builtins(Stage::Type type)
75 Module *module = get_builtins_module();
79 if(type==Stage::SHARED)
80 return &module->shared;
81 for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)