internal/shader: bug fix: spaces around a compiler directive should be allowed

Closes #2771
This commit is contained in:
Hajime Hoshi 2023-09-22 01:43:08 +09:00
parent a3ff5f283b
commit 0e27a8a30b
2 changed files with 13 additions and 1 deletions

View File

@ -222,7 +222,9 @@ func ParseCompilerDirectives(src []byte) (shaderir.Unit, error) {
// TODO: Change the unit to pixels in v3 (#2645).
unit := shaderir.Texels
reUnit := regexp.MustCompile(`^//kage:unit\s+(.+)$`)
// Go's whitespace is U+0020 (SP), U+0009 (\t), U+000d (\r), and U+000A (\n).
// See https://go.dev/ref/spec#Tokens
reUnit := regexp.MustCompile(`^[ \t\r\n]*//kage:unit\s+([^ \t\r\n]+)[ \t\r\n]*$`)
var unitParsed bool
buf := bytes.NewBuffer(src)

View File

@ -3311,6 +3311,16 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}`,
err: true,
},
{
src: "\t " + `//kage:unit pixels` + " \t\r" + `
package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return position
}`,
unit: shaderir.Pixels,
err: false,
},
}
for _, c := range cases {
ir, err := compileToIR([]byte(c.src))