mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
shader: Enable to put global variables anywhere
This commit is contained in:
parent
39c09a4f88
commit
382ba75139
@ -140,8 +140,16 @@ func (s *compileState) addError(pos token.Pos, str string) {
|
||||
}
|
||||
|
||||
func (cs *compileState) parse(f *ast.File) {
|
||||
// Parse GenDecl for global variables, and then parse functions.
|
||||
for _, d := range f.Decls {
|
||||
cs.parseDecl(&cs.global, d)
|
||||
if _, ok := d.(*ast.FuncDecl); !ok {
|
||||
cs.parseDecl(&cs.global, d)
|
||||
}
|
||||
}
|
||||
for _, d := range f.Decls {
|
||||
if _, ok := d.(*ast.FuncDecl); ok {
|
||||
cs.parseDecl(&cs.global, d)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cs.errs) > 0 {
|
||||
|
@ -135,8 +135,6 @@ func Foo(foo vec2) vec4 {
|
||||
Name: "vertex",
|
||||
Src: `package main
|
||||
|
||||
var ScreenSize vec2
|
||||
|
||||
func Vertex(position vec2, texCoord vec2, color vec4) (position vec4, texCoord vec2, color vec4) {
|
||||
projectionMatrix := mat4(
|
||||
2 / ScreenSize.x, 0, 0, 0,
|
||||
@ -145,7 +143,9 @@ func Vertex(position vec2, texCoord vec2, color vec4) (position vec4, texCoord v
|
||||
-1, -1, 0, 1,
|
||||
)
|
||||
return projectionMatrix * vec4(position, 0, 1), texCoord, color
|
||||
}`,
|
||||
}
|
||||
|
||||
var ScreenSize vec2`,
|
||||
VS: `uniform vec2 U0;
|
||||
attribute vec2 A0;
|
||||
attribute vec2 A1;
|
||||
@ -161,6 +161,9 @@ void main(void) {
|
||||
V1 = A2;
|
||||
return;
|
||||
}`,
|
||||
FS: `uniform vec2 U0;
|
||||
varying vec2 V0;
|
||||
varying vec4 V1;`,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user