shader: Accept an ast directly

This is a preparation to modify the AST before passign to Compile.
This commit is contained in:
Hajime Hoshi 2020-06-06 23:11:59 +09:00
parent fe308f1971
commit dde7d00231
2 changed files with 11 additions and 9 deletions

View File

@ -17,7 +17,6 @@ package shader
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"strconv"
"strings"
@ -106,13 +105,7 @@ func (p *ParseError) Error() string {
return strings.Join(p.errs, "\n")
}
func Compile(src []byte, vertexEntry, fragmentEntry string) (*shaderir.Program, error) {
fs := token.NewFileSet()
f, err := parser.ParseFile(fs, "", src, parser.AllErrors)
if err != nil {
return nil, err
}
func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string) (*shaderir.Program, error) {
s := &compileState{
fs: fs,
vertexEntry: vertexEntry,

View File

@ -15,6 +15,9 @@
package ebiten
import (
"go/parser"
"go/token"
"github.com/hajimehoshi/ebiten/internal/buffered"
"github.com/hajimehoshi/ebiten/internal/shader"
)
@ -24,7 +27,13 @@ type Shader struct {
}
func NewShader(src []byte) (*Shader, error) {
s, err := shader.Compile(src, "Vertex", "Fragment")
fs := token.NewFileSet()
f, err := parser.ParseFile(fs, "", src, parser.AllErrors)
if err != nil {
return nil, err
}
s, err := shader.Compile(fs, f, "Vertex", "Fragment")
if err != nil {
return nil, err
}