X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fbuiltin.cpp;h=670cfc2d9f4878b1d55abca1cf453adf8c628816;hb=ff00056daddbce2e6e16f7c09dcfcb5cde66e85c;hp=049740657a5c251432f5054a67a40d1fa4b98164;hpb=9ec831710f64a62ad5f2e896a55ae82a3519f29e;p=libs%2Fgl.git diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 04974065..670cfc2d 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -1,28 +1,11 @@ +#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 { @@ -35,20 +18,58 @@ Module *get_builtins_module() { initialized = true; + RefPtr io = Resources::get_builtins().open("_builtin.glsl"); + if(!io) + return 0; + Parser parser; - Module *module = new Module(parser.parse(builtins_src, "", BUILTIN_SOURCE)); + Module *module = new Module(parser.parse(*io, "", BUILTIN_SOURCE)); + + NodeList &shared_body = module->shared.content.body; + + RefPtr type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "void"; + type->kind = BasicTypeDeclaration::VOID; + shared_body.insert(shared_body.begin(), type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "bool"; + type->kind = BasicTypeDeclaration::BOOL; + shared_body.insert(shared_body.begin(), type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "int"; + type->size = 32; + type->kind = BasicTypeDeclaration::INT; + shared_body.insert(shared_body.begin(), type); + + type = new BasicTypeDeclaration; + type->source = BUILTIN_SOURCE; + type->name = "float"; + type->size = 32; + type->kind = BasicTypeDeclaration::FLOAT; + shared_body.insert(shared_body.begin(), type); + + TypeResolver().apply(module->shared); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + TypeResolver().apply(*i); builtins_module = module; } return builtins_module.get(); } -Stage *get_builtins(Stage::Type type) +const Stage *get_builtins(Stage::Type type) { 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;