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