mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 15:04:28 +01:00
shaderir: Implement call
This commit is contained in:
parent
5b69e81bd7
commit
57d80c185e
@ -152,8 +152,11 @@ func (p *Program) glslBlock(b *Block, f *Func, level int, localVarIndex int) []s
|
|||||||
case Selection:
|
case Selection:
|
||||||
return fmt.Sprintf("(%s) ? (%s) : (%s)", glslExpr(&e.Exprs[0]), glslExpr(&e.Exprs[1]), glslExpr(&e.Exprs[2]))
|
return fmt.Sprintf("(%s) ? (%s) : (%s)", glslExpr(&e.Exprs[0]), glslExpr(&e.Exprs[1]), glslExpr(&e.Exprs[2]))
|
||||||
case Call:
|
case Call:
|
||||||
// TODO: Take multiple args
|
var args []string
|
||||||
return fmt.Sprintf("(%s).(%s)", glslExpr(&e.Exprs[0]), glslExpr(&e.Exprs[1]))
|
for _, exp := range e.Exprs {
|
||||||
|
args = append(args, glslExpr(&exp))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s(%s)", e.Ident, strings.Join(args, ", "))
|
||||||
case FieldSelector:
|
case FieldSelector:
|
||||||
return fmt.Sprintf("(%s).%s", glslExpr(&e.Exprs[0]), glslExpr(&e.Exprs[1]))
|
return fmt.Sprintf("(%s).%s", glslExpr(&e.Exprs[0]), glslExpr(&e.Exprs[1]))
|
||||||
case Index:
|
case Index:
|
||||||
|
@ -27,6 +27,13 @@ func block(localVars []Type, stmts ...Stmt) Block {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exprStmt(expr Expr) Stmt {
|
||||||
|
return Stmt{
|
||||||
|
Type: ExprStmt,
|
||||||
|
Exprs: []Expr{expr},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func blockStmt(block Block) Stmt {
|
func blockStmt(block Block) Stmt {
|
||||||
return Stmt{
|
return Stmt{
|
||||||
Type: BlockStmt,
|
Type: BlockStmt,
|
||||||
@ -99,6 +106,14 @@ func selectionExpr(cond, a, b Expr) Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func callExpr(name string, args ...Expr) Expr {
|
||||||
|
return Expr{
|
||||||
|
Type: Call,
|
||||||
|
Ident: name,
|
||||||
|
Exprs: args,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func fieldSelectorExpr(a, b Expr) Expr {
|
func fieldSelectorExpr(a, b Expr) Expr {
|
||||||
return Expr{
|
return Expr{
|
||||||
Type: FieldSelector,
|
Type: FieldSelector,
|
||||||
@ -324,6 +339,43 @@ varying vec3 V0;`,
|
|||||||
},
|
},
|
||||||
Glsl: `void F0(in bool l0, in float l1, in float l2, out float l3) {
|
Glsl: `void F0(in bool l0, in float l1, in float l2, out float l3) {
|
||||||
l3 = (l0) ? (l1) : (l2);
|
l3 = (l0) ? (l1) : (l2);
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Call",
|
||||||
|
Program: Program{
|
||||||
|
Funcs: []Func{
|
||||||
|
{
|
||||||
|
Name: "F0",
|
||||||
|
InParams: []Type{
|
||||||
|
{Main: Float},
|
||||||
|
{Main: Float},
|
||||||
|
},
|
||||||
|
OutParams: []Type{
|
||||||
|
{Main: Vec2},
|
||||||
|
},
|
||||||
|
Block: block(
|
||||||
|
nil,
|
||||||
|
exprStmt(
|
||||||
|
callExpr(
|
||||||
|
"F1",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
assignStmt(
|
||||||
|
varNameExpr(Local, 2),
|
||||||
|
callExpr(
|
||||||
|
"F2",
|
||||||
|
varNameExpr(Local, 0),
|
||||||
|
varNameExpr(Local, 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Glsl: `void F0(in float l0, in float l1, out vec2 l2) {
|
||||||
|
F1();
|
||||||
|
l2 = F2(l0, l1);
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,8 @@ type Program struct {
|
|||||||
structTypes []Type
|
structTypes []Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: How to avoid the name with existing functions?
|
||||||
|
|
||||||
type Func struct {
|
type Func struct {
|
||||||
Name string
|
Name string
|
||||||
InParams []Type
|
InParams []Type
|
||||||
|
Loading…
Reference in New Issue
Block a user