1 #include <msp/gl/resources.h>
2 #include <msp/io/seekable.h>
13 void populate_types(Stage &stage)
15 for(NodeList<Statement>::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
16 if(TypeDeclaration *type = dynamic_cast<TypeDeclaration *>(i->get()))
17 stage.types[type->name] = type;
20 Module *get_builtins_module()
22 static RefPtr<Module> builtins_module;
23 static bool initialized = false;
28 RefPtr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
33 Module *module = new Module(parser.parse(*io, "<builtin>", BUILTIN_SOURCE));
35 NodeList<Statement> &shared_body = module->shared.content.body;
36 NodeList<Statement>::iterator insert_point = shared_body.begin();
38 RefPtr<BasicTypeDeclaration> type = new BasicTypeDeclaration;
39 type->source = BUILTIN_SOURCE;
41 type->kind = BasicTypeDeclaration::VOID;
42 shared_body.insert(insert_point, type);
44 type = new BasicTypeDeclaration;
45 type->source = BUILTIN_SOURCE;
48 type->kind = BasicTypeDeclaration::BOOL;
49 shared_body.insert(insert_point, type);
51 type = new BasicTypeDeclaration;
52 type->source = BUILTIN_SOURCE;
55 type->kind = BasicTypeDeclaration::INT;
56 shared_body.insert(insert_point, type);
58 type = new BasicTypeDeclaration;
59 type->source = BUILTIN_SOURCE;
62 type->kind = BasicTypeDeclaration::FLOAT;
63 shared_body.insert(insert_point, type);
65 populate_types(module->shared);
66 for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
69 builtins_module = module;
71 return builtins_module.get();
74 const Stage *get_builtins(Stage::Type type)
76 Module *module = get_builtins_module();
80 if(type==Stage::SHARED)
81 return &module->shared;
82 for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)