From 88fe3d1287953c37d6095496e1789f7dbbe1f247 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 24 Dec 2022 15:55:05 +0900 Subject: [PATCH] internal/shaderir: rename TextureNum to TextureCount --- internal/shader/shader.go | 4 ++-- internal/shaderir/glsl/glsl.go | 8 ++++---- internal/shaderir/hlsl/hlsl.go | 4 ++-- internal/shaderir/msl/msl.go | 8 ++++---- internal/shaderir/program.go | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/shader/shader.go b/internal/shader/shader.go index 1494137ca..b1b048334 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -180,7 +180,7 @@ func (p *ParseError) Error() string { return strings.Join(p.errs, "\n") } -func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string, textureNum int) (*shaderir.Program, error) { +func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string, textureCount int) (*shaderir.Program, error) { s := &compileState{ fs: fs, vertexEntry: vertexEntry, @@ -198,7 +198,7 @@ func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string, // TODO: Make a call graph and reorder the elements. - s.ir.TextureNum = textureNum + s.ir.TextureCount = textureCount return &s.ir, nil } diff --git a/internal/shaderir/glsl/glsl.go b/internal/shaderir/glsl/glsl.go index 3a4455c3f..c9d1bc8cf 100644 --- a/internal/shaderir/glsl/glsl.go +++ b/internal/shaderir/glsl/glsl.go @@ -128,12 +128,12 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh { vslines = append(vslines, strings.Split(VertexPrelude(version), "\n")...) vslines = append(vslines, "", "{{.Structs}}") - if len(p.Uniforms) > 0 || p.TextureNum > 0 || len(p.Attributes) > 0 || len(p.Varyings) > 0 { + if len(p.Uniforms) > 0 || p.TextureCount > 0 || len(p.Attributes) > 0 || len(p.Varyings) > 0 { vslines = append(vslines, "") for i, t := range p.Uniforms { vslines = append(vslines, fmt.Sprintf("uniform %s;", c.varDecl(p, &t, fmt.Sprintf("U%d", i)))) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { vslines = append(vslines, fmt.Sprintf("uniform sampler2D T%d;", i)) } for i, t := range p.Attributes { @@ -225,12 +225,12 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh { fslines = append(fslines, strings.Split(FragmentPrelude(version), "\n")...) fslines = append(fslines, "", "{{.Structs}}") - if len(p.Uniforms) > 0 || p.TextureNum > 0 || len(p.Varyings) > 0 { + if len(p.Uniforms) > 0 || p.TextureCount > 0 || len(p.Varyings) > 0 { fslines = append(fslines, "") for i, t := range p.Uniforms { fslines = append(fslines, fmt.Sprintf("uniform %s;", c.varDecl(p, &t, fmt.Sprintf("U%d", i)))) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { fslines = append(fslines, fmt.Sprintf("uniform sampler2D T%d;", i)) } for i, t := range p.Varyings { diff --git a/internal/shaderir/hlsl/hlsl.go b/internal/shaderir/hlsl/hlsl.go index 526b07e90..a9b06c082 100644 --- a/internal/shaderir/hlsl/hlsl.go +++ b/internal/shaderir/hlsl/hlsl.go @@ -111,9 +111,9 @@ func Compile(p *shaderir.Program) (string, []int) { } lines = append(lines, "}") } - if p.TextureNum > 0 { + if p.TextureCount > 0 { lines = append(lines, "") - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { lines = append(lines, fmt.Sprintf("Texture2D T%[1]d : register(t%[1]d);", i)) } lines = append(lines, "SamplerState samp : register(s0);") diff --git a/internal/shaderir/msl/msl.go b/internal/shaderir/msl/msl.go index dbcbc1a66..0b7395829 100644 --- a/internal/shaderir/msl/msl.go +++ b/internal/shaderir/msl/msl.go @@ -109,7 +109,7 @@ func Compile(p *shaderir.Program, vertex, fragment string) (shader string) { lines[len(lines)-1] += "," lines = append(lines, fmt.Sprintf("\tconstant %s [[buffer(%d)]]", c.varDecl(p, &u, fmt.Sprintf("U%d", i), true), i+1)) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { lines[len(lines)-1] += "," lines = append(lines, fmt.Sprintf("\ttexture2d T%[1]d [[texture(%[1]d)]]", i)) } @@ -131,7 +131,7 @@ func Compile(p *shaderir.Program, vertex, fragment string) (shader string) { lines[len(lines)-1] += "," lines = append(lines, fmt.Sprintf("\tconstant %s [[buffer(%d)]]", c.varDecl(p, &u, fmt.Sprintf("U%d", i), true), i+1)) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { lines[len(lines)-1] += "," lines = append(lines, fmt.Sprintf("\ttexture2d T%[1]d [[texture(%[1]d)]]", i)) } @@ -220,7 +220,7 @@ func (c *compileContext) function(p *shaderir.Program, f *shaderir.Func, prototy for i, u := range p.Uniforms { args = append(args, "constant "+c.varDecl(p, &u, fmt.Sprintf("U%d", i), true)) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { args = append(args, fmt.Sprintf("texture2d T%d", i)) } @@ -388,7 +388,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl for i := range p.Uniforms { args = append(args, fmt.Sprintf("U%d", i)) } - for i := 0; i < p.TextureNum; i++ { + for i := 0; i < p.TextureCount; i++ { args = append(args, fmt.Sprintf("T%d", i)) } } diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 8040df413..38074552b 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -25,7 +25,7 @@ import ( type Program struct { UniformNames []string Uniforms []Type - TextureNum int + TextureCount int Attributes []Type Varyings []Type Funcs []Func