]> git.tdb.fi Git - libs/gl.git/commitdiff
Support layout qualifiers on GLSL interface blocks
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Mar 2021 23:06:08 +0000 (01:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 18 Mar 2021 11:25:08 +0000 (13:25 +0200)
source/glsl/debug.cpp
source/glsl/output.cpp
source/glsl/parser.cpp
source/glsl/syntax.h
source/glsl/visitor.cpp

index 99d6edaaa0ab7b7f242e23c0ecc9fc2c04be47df..810ac742f43e906580d8abe6f69c136514df4dc4 100644 (file)
@@ -388,13 +388,14 @@ void DumpTree::visit(InterfaceBlock &iface)
                head += " (linked)";
        append(head);
 
-       begin_sub();
-       last_branch();
+       vector<Branch> branches;
        if(iface.type_declaration)
                append(format("Type: %%%d %s", get_label(*iface.type_declaration), iface.type_declaration->name));
-       else if(iface.members)
-               iface.members->visit(*this);
-       end_sub();
+       if(iface.layout)
+               branches.push_back(Branch("Layout", iface.layout.get()));
+       if(iface.members)
+               branches.push_back(Branch("Members", iface.members.get()));
+       append_subtree(branches);
 }
 
 void DumpTree::visit(FunctionDeclaration &func)
index 52026c4d81fc18e7a7c3ded35eb1c57bedbc449e..928b42508792ce47398e2955b050d5cdd2f5b37c 100644 (file)
@@ -306,6 +306,11 @@ void Formatter::visit(VariableDeclaration &var)
 
 void Formatter::visit(InterfaceBlock &iface)
 {
+       if(iface.layout)
+       {
+               iface.layout->visit(*this);
+               append(' ');
+       }
        append(format("%s %s\n", iface.interface, iface.block_name));
        if(iface.struct_declaration)
                iface.struct_declaration->members.visit(*this);
index 9e1f1913491cf98800352d25619557a3e120bfdc..ac35216a4cdd164aeb80b1d1f597e4b1fb4803ec 100644 (file)
@@ -273,6 +273,12 @@ RefPtr<Statement> Parser::parse_global_declaration()
                        tokenizer.expect(";");
                        return iface_lo;
                }
+               else if(is_interface_qualifier(token) && tokenizer.peek_token(2)=="{")
+               {
+                       RefPtr<InterfaceBlock> iface = parse_interface_block();
+                       iface->layout = layout;
+                       return iface;
+               }
                else
                {
                        RefPtr<VariableDeclaration> var = parse_variable_declaration();
index f7c8ed29cedc09229be11f5ce774d78f67107ee3..1caf4d9568c10f5b3c45faed04fd25cab14a606b 100644 (file)
@@ -429,6 +429,7 @@ struct VariableDeclaration: Statement
 
 struct InterfaceBlock: Statement
 {
+       NodePtr<Layout> layout;
        std::string interface;
        std::string block_name;
        NodePtr<Block> members;
index cc030eab7e31f33e71a8cb575f3013c7fdeab0df..808bcfa52dfc3757e70ea16ba4ec1fe451b75fe8 100644 (file)
@@ -88,6 +88,8 @@ void TraversingVisitor::visit(VariableDeclaration &var)
 
 void TraversingVisitor::visit(InterfaceBlock &iface)
 {
+       if(iface.layout)
+               iface.layout->visit(*this);
        if(iface.members)
                iface.members->visit(*this);
 }