From 1ce5df9e70385c8758eec39589a148e63238b0a8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 10 Apr 2021 03:46:29 +0300 Subject: [PATCH] Clear the empty name flag after emitting a member access --- source/glsl/output.cpp | 1 + tests/glsl/struct_in_anonymous_block.glsl | 54 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/glsl/struct_in_anonymous_block.glsl diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index c15c8c04..50b60c14 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -171,6 +171,7 @@ void Formatter::visit(MemberAccess &memacc) if(!r_empty_name) append('.'); append(memacc.member); + r_empty_name = false; } void Formatter::visit(Swizzle &swizzle) diff --git a/tests/glsl/struct_in_anonymous_block.glsl b/tests/glsl/struct_in_anonymous_block.glsl new file mode 100644 index 00000000..03d6af42 --- /dev/null +++ b/tests/glsl/struct_in_anonymous_block.glsl @@ -0,0 +1,54 @@ +struct MaterialParameters +{ + vec4 color; +}; +uniform Material +{ + MaterialParameters material; +}; +uniform Transform +{ + mat4 mvp; +}; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +void main() +{ + gl_Position = mvp*position; +} + +#pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; +void main() +{ + frag_color = material.color; +} + +/* Expected output: vertex +layout(binding=48) uniform Transform +{ + mat4 mvp; +}; +layout(location=0) in vec4 position; +void main() +{ + gl_Position = mvp*position; +} +*/ + +/* Expected output: fragment +struct MaterialParameters +{ + vec4 color; +}; +layout(binding=64) uniform Material +{ + MaterialParameters material; +}; +layout(location=0) out vec4 frag_color; +void main() +{ + frag_color = material.color; +} +*/ -- 2.45.2