mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
shader: Accept an ast directly
This is a preparation to modify the AST before passign to Compile.
This commit is contained in:
parent
fe308f1971
commit
dde7d00231
@ -17,7 +17,6 @@ package shader
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
"go/token"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -106,13 +105,7 @@ func (p *ParseError) Error() string {
|
|||||||
return strings.Join(p.errs, "\n")
|
return strings.Join(p.errs, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Compile(src []byte, vertexEntry, fragmentEntry string) (*shaderir.Program, error) {
|
func Compile(fs *token.FileSet, f *ast.File, vertexEntry, fragmentEntry string) (*shaderir.Program, error) {
|
||||||
fs := token.NewFileSet()
|
|
||||||
f, err := parser.ParseFile(fs, "", src, parser.AllErrors)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
s := &compileState{
|
s := &compileState{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
vertexEntry: vertexEntry,
|
vertexEntry: vertexEntry,
|
||||||
|
11
shader.go
11
shader.go
@ -15,6 +15,9 @@
|
|||||||
package ebiten
|
package ebiten
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go/parser"
|
||||||
|
"go/token"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/buffered"
|
"github.com/hajimehoshi/ebiten/internal/buffered"
|
||||||
"github.com/hajimehoshi/ebiten/internal/shader"
|
"github.com/hajimehoshi/ebiten/internal/shader"
|
||||||
)
|
)
|
||||||
@ -24,7 +27,13 @@ type Shader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewShader(src []byte) (*Shader, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user