mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/shader: add type checks for the builtin function texture2D
Note that texture2D is usually not called by users. Closes #2184
This commit is contained in:
parent
63eee0600e
commit
590147acda
@ -431,7 +431,18 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}
|
}
|
||||||
t = shaderir.Type{Main: shaderir.Mat4}
|
t = shaderir.Type{Main: shaderir.Mat4}
|
||||||
case shaderir.Texture2DF:
|
case shaderir.Texture2DF:
|
||||||
// TODO: Check arg types.
|
if len(args) != 2 {
|
||||||
|
cs.addError(e.Pos(), fmt.Sprintf("number of %s's arguments must be 2 but %d", callee.BuiltinFunc, len(args)))
|
||||||
|
return nil, nil, nil, false
|
||||||
|
}
|
||||||
|
if argts[0].Main != shaderir.Texture {
|
||||||
|
cs.addError(e.Pos(), fmt.Sprintf("cannot use %s as texture value in argument to %s", argts[0].String(), callee.BuiltinFunc))
|
||||||
|
return nil, nil, nil, false
|
||||||
|
}
|
||||||
|
if argts[1].Main != shaderir.Vec2 {
|
||||||
|
cs.addError(e.Pos(), fmt.Sprintf("cannot use %s as vec2 value in argument to %s", argts[1].String(), callee.BuiltinFunc))
|
||||||
|
return nil, nil, nil, false
|
||||||
|
}
|
||||||
t = shaderir.Type{Main: shaderir.Vec4}
|
t = shaderir.Type{Main: shaderir.Vec4}
|
||||||
case shaderir.DiscardF:
|
case shaderir.DiscardF:
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
@ -744,7 +755,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
Type: shaderir.TextureVariable,
|
Type: shaderir.TextureVariable,
|
||||||
Index: i,
|
Index: i,
|
||||||
},
|
},
|
||||||
}, nil, nil, true
|
}, []shaderir.Type{{Main: shaderir.Texture}}, nil, true
|
||||||
}
|
}
|
||||||
if e.Name == "true" || e.Name == "false" {
|
if e.Name == "true" || e.Name == "false" {
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
|
@ -133,6 +133,7 @@ const (
|
|||||||
Mat2
|
Mat2
|
||||||
Mat3
|
Mat3
|
||||||
Mat4
|
Mat4
|
||||||
|
Texture
|
||||||
Array
|
Array
|
||||||
Struct
|
Struct
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user