]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Give declaration nodes to all GLSL types.
[libs/gl.git] / source / glsl / generate.cpp
index b91c2e2614ef2d577ce1e501893222eed678507d..c4a29110ffc8783f6d671340a5bdb05f8d0c5759 100644 (file)
@@ -114,6 +114,55 @@ void BlockHierarchyResolver::enter(Block &block)
 }
 
 
+TypeResolver::TypeResolver():
+       stage(0)
+{ }
+
+void TypeResolver::apply(Stage &s)
+{
+       stage = &s;
+       s.types.clear();
+       s.content.visit(*this);
+}
+
+void TypeResolver::visit(BasicTypeDeclaration &type)
+{
+       map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
+       type.base_type = (i!=stage->types.end() ? i->second : 0);
+
+       if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type)
+               if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
+                       if(basic_base->kind==BasicTypeDeclaration::VECTOR)
+                       {
+                               type.kind = BasicTypeDeclaration::MATRIX;
+                               type.size |= basic_base->size<<16;
+                       }
+
+       stage->types.insert(make_pair(type.name, &type));
+}
+
+void TypeResolver::visit(ImageTypeDeclaration &type)
+{
+       map<string, TypeDeclaration *>::iterator i = stage->types.find(type.base);
+       type.base_type = (i!=stage->types.end() ? i->second : 0);
+
+       stage->types.insert(make_pair(type.name, &type));
+}
+
+void TypeResolver::visit(StructDeclaration &strct)
+{
+       stage->types.insert(make_pair(strct.name, &strct));
+       TraversingVisitor::visit(strct);
+}
+
+void TypeResolver::visit(VariableDeclaration &var)
+{
+       map<string, TypeDeclaration *>::iterator i = stage->types.find(var.type);
+       if(i!=stage->types.end())
+               var.type_declaration = i->second;
+}
+
+
 VariableResolver::VariableResolver():
        stage(0),
        r_members(0),
@@ -125,7 +174,6 @@ VariableResolver::VariableResolver():
 void VariableResolver::apply(Stage &s)
 {
        stage = &s;
-       s.types.clear();
        s.interface_blocks.clear();
        s.content.visit(*this);
 }
@@ -151,8 +199,8 @@ void VariableResolver::visit(VariableReference &var)
 
        if(var.declaration)
        {
-               if(var.declaration->type_declaration)
-                       r_members = &var.declaration->type_declaration->members.variables;
+               if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(var.declaration->type_declaration))
+                       r_members = &strct->members.variables;
        }
        else
        {
@@ -228,8 +276,8 @@ void VariableResolver::visit(MemberAccess &memacc)
                if(i!=r_members->end())
                {
                        memacc.declaration = i->second;
-                       if(i->second->type_declaration)
-                               r_members = &i->second->type_declaration->members.variables;
+                       if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(i->second->type_declaration))
+                               r_members = &strct->members.variables;
                }
                else
                        r_members = 0;
@@ -292,18 +340,8 @@ void VariableResolver::visit(FunctionCall &call)
        r_iface_ref = 0;
 }
 
-void VariableResolver::visit(StructDeclaration &strct)
-{
-       TraversingVisitor::visit(strct);
-       stage->types.insert(make_pair(strct.name, &strct));
-}
-
 void VariableResolver::visit(VariableDeclaration &var)
 {
-       map<string, StructDeclaration *>::iterator i = stage->types.find(var.type);
-       if(i!=stage->types.end())
-               var.type_declaration = i->second;
-
        if(!block_interface.empty() && var.interface.empty())
                var.interface = block_interface;