From: Mikko Rasa Date: Wed, 17 Mar 2021 23:06:08 +0000 (+0200) Subject: Support layout qualifiers on GLSL interface blocks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c315e77b7791fe92d42e1566b5adaddf2699a758;p=libs%2Fgl.git Support layout qualifiers on GLSL interface blocks --- diff --git a/source/glsl/debug.cpp b/source/glsl/debug.cpp index 99d6edaa..810ac742 100644 --- a/source/glsl/debug.cpp +++ b/source/glsl/debug.cpp @@ -388,13 +388,14 @@ void DumpTree::visit(InterfaceBlock &iface) head += " (linked)"; append(head); - begin_sub(); - last_branch(); + vector 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) diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index 52026c4d..928b4250 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -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); diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 9e1f1913..ac35216a 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -273,6 +273,12 @@ RefPtr Parser::parse_global_declaration() tokenizer.expect(";"); return iface_lo; } + else if(is_interface_qualifier(token) && tokenizer.peek_token(2)=="{") + { + RefPtr iface = parse_interface_block(); + iface->layout = layout; + return iface; + } else { RefPtr var = parse_variable_declaration(); diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index f7c8ed29..1caf4d95 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -429,6 +429,7 @@ struct VariableDeclaration: Statement struct InterfaceBlock: Statement { + NodePtr layout; std::string interface; std::string block_name; NodePtr members; diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index cc030eab..808bcfa5 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -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); }