]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/builtin.cpp
Fix opcode for matrix inverse
[libs/gl.git] / source / glsl / builtin.cpp
index 670cfc2d9f4878b1d55abca1cf453adf8c628816..83e480e5cf417b5943abb7841ebcb32256f8136e 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/gl/resources.h>
 #include <msp/io/seekable.h>
 #include "builtin.h"
-#include "generate.h"
 #include "parser.h"
 
 using namespace std;
@@ -10,6 +9,18 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+void add_builtin_type(Stage &stage, const std::string &name, BasicTypeDeclaration::Kind kind, unsigned size, unsigned sign)
+{
+       RefPtr<BasicTypeDeclaration> type = new BasicTypeDeclaration;
+       type->source = BUILTIN_SOURCE;
+       type->name = name;
+       type->kind = kind;
+       type->size = size;
+       type->sign = sign;
+       stage.content.body.push_back(type);
+       stage.types[name] = type.get();
+}
+
 Module *get_builtins_module()
 {
        static RefPtr<Module> builtins_module;
@@ -22,42 +33,23 @@ Module *get_builtins_module()
                if(!io)
                        return 0;
 
-               Parser parser;
-               Module *module = new Module(parser.parse(*io, "<builtin>", BUILTIN_SOURCE));
-
-               NodeList<Statement> &shared_body = module->shared.content.body;
-
-               RefPtr<BasicTypeDeclaration> 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<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-                       TypeResolver().apply(*i);
+               builtins_module = new Module;
+               add_builtin_type(builtins_module->shared, "void", BasicTypeDeclaration::VOID, 0, true);
+               add_builtin_type(builtins_module->shared, "bool", BasicTypeDeclaration::BOOL, 1, true);
+               add_builtin_type(builtins_module->shared, "int", BasicTypeDeclaration::INT, 32, true);
+               add_builtin_type(builtins_module->shared, "uint", BasicTypeDeclaration::INT, 32, false);
+               add_builtin_type(builtins_module->shared, "float", BasicTypeDeclaration::FLOAT, 32, true);
 
-               builtins_module = module;
+               try
+               {
+                       Parser parser(0);
+                       parser.parse(*builtins_module, *io, "<builtin>", BUILTIN_SOURCE);
+               }
+               catch(...)
+               {
+                       builtins_module = 0;
+                       throw;
+               }
        }
        return builtins_module.get();
 }