mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shaderir: refactoring: remove Program.TextureNum
This commit is contained in:
parent
f9650fbb8c
commit
c2bea16776
@ -124,7 +124,7 @@ func CompileShader(src []byte) (*shaderir.Program, error) {
|
||||
vert = "__vertex"
|
||||
frag = "Fragment"
|
||||
)
|
||||
ir, err := shader.Compile(fs, f, vert, frag, ShaderImageCount)
|
||||
ir, err := shader.Compile(fs, f, vert, frag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -14,8 +14,12 @@
|
||||
|
||||
package graphics
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
const (
|
||||
ShaderImageCount = 4
|
||||
ShaderImageCount = shaderir.TextureCount
|
||||
|
||||
// PreservedUniformVariablesCount represents the number of preserved uniform variables.
|
||||
// Any shaders in Ebitengine must have these uniform variables.
|
||||
|
@ -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) (*shaderir.Program, error) {
|
||||
s := &compileState{
|
||||
fs: fs,
|
||||
vertexEntry: vertexEntry,
|
||||
@ -198,7 +198,6 @@ func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string,
|
||||
|
||||
// TODO: Make a call graph and reorder the elements.
|
||||
|
||||
s.ir.TextureNum = textureNum
|
||||
return &s.ir, nil
|
||||
}
|
||||
|
||||
|
@ -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 || 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 < shaderir.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 || 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 < shaderir.TextureCount; i++ {
|
||||
fslines = append(fslines, fmt.Sprintf("uniform sampler2D T%d;", i))
|
||||
}
|
||||
for i, t := range p.Varyings {
|
||||
|
@ -111,13 +111,12 @@ func Compile(p *shaderir.Program) (string, []int) {
|
||||
}
|
||||
lines = append(lines, "}")
|
||||
}
|
||||
if p.TextureNum > 0 {
|
||||
lines = append(lines, "")
|
||||
for i := 0; i < p.TextureNum; i++ {
|
||||
lines = append(lines, fmt.Sprintf("Texture2D T%[1]d : register(t%[1]d);", i))
|
||||
}
|
||||
lines = append(lines, "SamplerState samp : register(s0);")
|
||||
|
||||
lines = append(lines, "")
|
||||
for i := 0; i < shaderir.TextureCount; i++ {
|
||||
lines = append(lines, fmt.Sprintf("Texture2D T%[1]d : register(t%[1]d);", i))
|
||||
}
|
||||
lines = append(lines, "SamplerState samp : register(s0);")
|
||||
|
||||
if len(p.Funcs) > 0 {
|
||||
lines = append(lines, "")
|
||||
|
@ -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 < shaderir.TextureCount; i++ {
|
||||
lines[len(lines)-1] += ","
|
||||
lines = append(lines, fmt.Sprintf("\ttexture2d<float> 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 < shaderir.TextureCount; i++ {
|
||||
lines[len(lines)-1] += ","
|
||||
lines = append(lines, fmt.Sprintf("\ttexture2d<float> 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 < shaderir.TextureCount; i++ {
|
||||
args = append(args, fmt.Sprintf("texture2d<float> 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 < shaderir.TextureCount; i++ {
|
||||
args = append(args, fmt.Sprintf("T%d", i))
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const TextureCount = 4
|
||||
|
||||
type Program struct {
|
||||
UniformNames []string
|
||||
Uniforms []Type
|
||||
TextureNum int
|
||||
Attributes []Type
|
||||
Varyings []Type
|
||||
Funcs []Func
|
||||
|
Loading…
Reference in New Issue
Block a user