mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/shaderir: refactoring
This commit is contained in:
parent
e2c25dbc6d
commit
7dbb078a9e
@ -19,7 +19,6 @@ import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
@ -99,12 +98,6 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
|
||||
structNames: map[string]string{},
|
||||
}
|
||||
|
||||
indexToFunc := map[int]*shaderir.Func{}
|
||||
for _, f := range p.Funcs {
|
||||
f := f
|
||||
indexToFunc[f.Index] = &f
|
||||
}
|
||||
|
||||
// Vertex func
|
||||
var vslines []string
|
||||
{
|
||||
@ -136,12 +129,7 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
|
||||
|
||||
var funcs []*shaderir.Func
|
||||
if p.VertexFunc.Block != nil {
|
||||
indices := p.ReachableFuncIndicesFromVertexShader()
|
||||
sort.Ints(indices)
|
||||
funcs = make([]*shaderir.Func, 0, len(indices))
|
||||
for _, idx := range indices {
|
||||
funcs = append(funcs, indexToFunc[idx])
|
||||
}
|
||||
funcs = p.ReachableFuncsFromVertexShader()
|
||||
} else {
|
||||
// When a vertex entry point is not defined, allow to put all the functions. This is useful for testing.
|
||||
funcs = make([]*shaderir.Func, 0, len(p.Funcs))
|
||||
@ -234,12 +222,7 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
|
||||
|
||||
var funcs []*shaderir.Func
|
||||
if p.VertexFunc.Block != nil {
|
||||
indices := p.ReachableFuncIndicesFromFragmentShader()
|
||||
sort.Ints(indices)
|
||||
funcs = make([]*shaderir.Func, 0, len(indices))
|
||||
for _, idx := range indices {
|
||||
funcs = append(funcs, indexToFunc[idx])
|
||||
}
|
||||
funcs = p.ReachableFuncsFromFragmentShader()
|
||||
} else {
|
||||
// When a fragment entry point is not defined, allow to put all the functions. This is useful for testing.
|
||||
funcs = make([]*shaderir.Func, 0, len(p.Funcs))
|
||||
|
@ -18,6 +18,7 @@ package shaderir
|
||||
import (
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -363,22 +364,28 @@ func IsValidSwizzling(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Program) ReachableFuncIndicesFromVertexShader() []int {
|
||||
return p.reachableFuncIndicesFromBlockEntryPoint(p.VertexFunc.Block)
|
||||
func (p *Program) ReachableFuncsFromVertexShader() []*Func {
|
||||
return p.reachableFuncsFromBlockEntryPoint(p.VertexFunc.Block)
|
||||
}
|
||||
|
||||
func (p *Program) ReachableFuncIndicesFromFragmentShader() []int {
|
||||
return p.reachableFuncIndicesFromBlockEntryPoint(p.FragmentFunc.Block)
|
||||
func (p *Program) ReachableFuncsFromFragmentShader() []*Func {
|
||||
return p.reachableFuncsFromBlockEntryPoint(p.FragmentFunc.Block)
|
||||
}
|
||||
|
||||
func (p *Program) reachableFuncIndicesFromBlockEntryPoint(b *Block) []int {
|
||||
func (p *Program) reachableFuncsFromBlockEntryPoint(b *Block) []*Func {
|
||||
indexToFunc := map[int]*Func{}
|
||||
for _, f := range p.Funcs {
|
||||
f := f
|
||||
indexToFunc[f.Index] = &f
|
||||
}
|
||||
visited := map[int]struct{}{}
|
||||
return reachableFuncIndicesFromBlock(b, indexToFunc, visited)
|
||||
indices := reachableFuncIndicesFromBlock(b, indexToFunc, visited)
|
||||
sort.Ints(indices)
|
||||
funcs := make([]*Func, 0, len(indices))
|
||||
for _, i := range indices {
|
||||
funcs = append(funcs, indexToFunc[i])
|
||||
}
|
||||
return funcs
|
||||
}
|
||||
|
||||
func reachableFuncIndicesFromBlock(b *Block, indexToFunc map[int]*Func, visited map[int]struct{}) []int {
|
||||
|
Loading…
Reference in New Issue
Block a user