mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/shader: refactoring
This commit is contained in:
parent
e6d79889f9
commit
df32901dce
@ -17,8 +17,6 @@ package graphics
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shader"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
@ -114,17 +112,11 @@ func CompileShader(src []byte) (*shaderir.Program, error) {
|
||||
buf.Write(src)
|
||||
buf.WriteString(shaderSuffix)
|
||||
|
||||
fs := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fs, "", buf.Bytes(), parser.AllErrors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
const (
|
||||
vert = "__vertex"
|
||||
frag = "Fragment"
|
||||
)
|
||||
ir, err := shader.Compile(fs, f, vert, frag, ShaderImageCount)
|
||||
ir, err := shader.Compile(buf.Bytes(), vert, frag, ShaderImageCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
gconstant "go/constant"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"strings"
|
||||
|
||||
@ -180,7 +181,13 @@ func (p *ParseError) Error() string {
|
||||
return strings.Join(p.errs, "\n")
|
||||
}
|
||||
|
||||
func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string, textureCount int) (*shaderir.Program, error) {
|
||||
func Compile(src []byte, vertexEntry, fragmentEntry string, textureCount int) (*shaderir.Program, error) {
|
||||
fs := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fs, "", src, parser.AllErrors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &compileState{
|
||||
fs: fs,
|
||||
vertexEntry: vertexEntry,
|
||||
|
@ -16,8 +16,6 @@ package shader_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -170,13 +168,7 @@ func TestCompile(t *testing.T) {
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "", tc.Src, parser.AllErrors)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := shader.Compile(fset, f, "Vertex", "Fragment", 0)
|
||||
s, err := shader.Compile(tc.Src, "Vertex", "Fragment", 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -16,8 +16,6 @@ package shader_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -26,18 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func compileToIR(src []byte) (*shaderir.Program, error) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "", src, parser.AllErrors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ir, err := shader.Compile(fset, f, "Vertex", "Fragment", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ir, nil
|
||||
return shader.Compile(src, "Vertex", "Fragment", 0)
|
||||
}
|
||||
|
||||
func TestSyntaxShadowing(t *testing.T) {
|
||||
|
@ -15,8 +15,6 @@
|
||||
package shaderir_test
|
||||
|
||||
import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shader"
|
||||
@ -24,18 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func compileToIR(src []byte) (*shaderir.Program, error) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "", src, parser.AllErrors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ir, err := shader.Compile(fset, f, "Vertex", "Fragment", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ir, nil
|
||||
return shader.Compile(src, "Vertex", "Fragment", 0)
|
||||
}
|
||||
|
||||
func areIntSlicesEqual(a, b []int) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user