]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/builtin.cpp
Add support for uint types in GLSL
[libs/gl.git] / source / glsl / builtin.cpp
index 955266fe0a1ce4ad3a8abfcd9fb3afb0340266f8..12602707db80ca5043b6582f5b6917422cb2f477 100644 (file)
@@ -1,32 +1,21 @@
+#include <msp/gl/resources.h>
+#include <msp/io/seekable.h>
 #include "builtin.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 {
 
+void populate_types(Stage &stage)
+{
+       for(NodeList<Statement>::const_iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i)
+               if(TypeDeclaration *type = dynamic_cast<TypeDeclaration *>(i->get()))
+                       stage.types[type->name] = type;
+}
+
 Module *get_builtins_module()
 {
        static RefPtr<Module> builtins_module;
@@ -35,15 +24,61 @@ Module *get_builtins_module()
        {
                initialized = true;
 
+               RefPtr<IO::Seekable> io = Resources::get_builtins().open("_builtin.glsl");
+               if(!io)
+                       return 0;
+
                Parser parser;
-               Module *module = new Module(parser.parse(builtins_src, "<builtin>", BUILTIN_SOURCE));
+               Module *module = new Module(parser.parse(*io, "<builtin>", BUILTIN_SOURCE));
+
+               NodeList<Statement> &shared_body = module->shared.content.body;
+               NodeList<Statement>::iterator insert_point = shared_body.begin();
+
+               RefPtr<BasicTypeDeclaration> type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "void";
+               type->kind = BasicTypeDeclaration::VOID;
+               shared_body.insert(insert_point, type);
+
+               type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "bool";
+               type->size = 1;
+               type->kind = BasicTypeDeclaration::BOOL;
+               shared_body.insert(insert_point, type);
+
+               type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "int";
+               type->size = 32;
+               type->kind = BasicTypeDeclaration::INT;
+               shared_body.insert(insert_point, type);
+
+               type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "uint";
+               type->size = 32;
+               type->sign = false;
+               type->kind = BasicTypeDeclaration::INT;
+               shared_body.insert(insert_point, type);
+
+               type = new BasicTypeDeclaration;
+               type->source = BUILTIN_SOURCE;
+               type->name = "float";
+               type->size = 32;
+               type->kind = BasicTypeDeclaration::FLOAT;
+               shared_body.insert(insert_point, type);
+
+               populate_types(module->shared);
+               for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+                       populate_types(*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)