mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
shaderir: Remove Variable and VariableType
This commit is contained in:
parent
094d845edd
commit
156ed320cc
@ -189,44 +189,39 @@ func (p *Program) glslBlock(b *Block, level int, localVarIndex int) []string {
|
|||||||
return fmt.Sprintf("%d", e.Int)
|
return fmt.Sprintf("%d", e.Int)
|
||||||
case FloatExpr:
|
case FloatExpr:
|
||||||
return fmt.Sprintf("%.9e", e.Float)
|
return fmt.Sprintf("%.9e", e.Float)
|
||||||
case VarName:
|
case UniformVariable:
|
||||||
switch e.Variable.Type {
|
return fmt.Sprintf("U%d", e.Index)
|
||||||
case Uniform:
|
case LocalVariable:
|
||||||
return fmt.Sprintf("U%d", e.Variable.Index)
|
idx := e.Index
|
||||||
case StructMember:
|
switch b {
|
||||||
return fmt.Sprintf("M%d", e.Variable.Index)
|
case &p.VertexFunc.Block:
|
||||||
case Local:
|
na := len(p.Attributes)
|
||||||
idx := e.Variable.Index
|
nv := len(p.Varyings)
|
||||||
switch b {
|
switch {
|
||||||
case &p.VertexFunc.Block:
|
case idx < na:
|
||||||
na := len(p.Attributes)
|
return fmt.Sprintf("A%d", idx)
|
||||||
nv := len(p.Varyings)
|
case idx < na+nv:
|
||||||
switch {
|
return fmt.Sprintf("V%d", idx-na)
|
||||||
case idx < na:
|
case idx == na+nv:
|
||||||
return fmt.Sprintf("A%d", idx)
|
return "gl_Position"
|
||||||
case idx < na+nv:
|
|
||||||
return fmt.Sprintf("V%d", idx-na)
|
|
||||||
case idx == na+nv:
|
|
||||||
return "gl_Position"
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("l%d", idx-(na+nv+1))
|
|
||||||
}
|
|
||||||
case &p.FragmentFunc.Block:
|
|
||||||
nv := len(p.Varyings)
|
|
||||||
switch {
|
|
||||||
case idx < nv:
|
|
||||||
return fmt.Sprintf("V%d", idx)
|
|
||||||
case idx == nv:
|
|
||||||
return "gl_FragCoord"
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("l%d", idx-(nv+1))
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("l%d", idx)
|
return fmt.Sprintf("l%d", idx-(na+nv+1))
|
||||||
|
}
|
||||||
|
case &p.FragmentFunc.Block:
|
||||||
|
nv := len(p.Varyings)
|
||||||
|
switch {
|
||||||
|
case idx < nv:
|
||||||
|
return fmt.Sprintf("V%d", idx)
|
||||||
|
case idx == nv:
|
||||||
|
return "gl_FragCoord"
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("l%d", idx-(nv+1))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("?(unexpected variable type: %d)", e.Variable.Type)
|
return fmt.Sprintf("l%d", idx)
|
||||||
}
|
}
|
||||||
|
case StructMember:
|
||||||
|
return fmt.Sprintf("M%d", e.Index)
|
||||||
case BuiltinFuncExpr:
|
case BuiltinFuncExpr:
|
||||||
return string(e.BuiltinFunc)
|
return string(e.BuiltinFunc)
|
||||||
case SwizzlingExpr:
|
case SwizzlingExpr:
|
||||||
|
@ -81,13 +81,17 @@ func floatExpr(value float32) Expr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func varNameExpr(vt VariableType, index int) Expr {
|
func uniformVariableExpr(index int) Expr {
|
||||||
return Expr{
|
return Expr{
|
||||||
Type: VarName,
|
Type: UniformVariable,
|
||||||
Variable: Variable{
|
Index: index,
|
||||||
Type: vt,
|
}
|
||||||
Index: index,
|
}
|
||||||
},
|
|
||||||
|
func localVariableExpr(index int) Expr {
|
||||||
|
return Expr{
|
||||||
|
Type: LocalVariable,
|
||||||
|
Index: index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +247,7 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
returnStmt(
|
returnStmt(
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -337,11 +341,11 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
binaryExpr(
|
binaryExpr(
|
||||||
Add,
|
Add,
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -369,11 +373,11 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 3),
|
localVariableExpr(3),
|
||||||
selectionExpr(
|
selectionExpr(
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -405,11 +409,11 @@ varying vec3 V0;`,
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
callExpr(
|
callExpr(
|
||||||
functionExpr(2),
|
functionExpr(2),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -437,11 +441,11 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
callExpr(
|
callExpr(
|
||||||
builtinFuncExpr(Min),
|
builtinFuncExpr(Min),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -467,9 +471,9 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
fieldSelectorExpr(
|
fieldSelectorExpr(
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
swizzlingExpr("xz"),
|
swizzlingExpr("xz"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -499,21 +503,21 @@ varying vec3 V0;`,
|
|||||||
ifStmt(
|
ifStmt(
|
||||||
binaryExpr(
|
binaryExpr(
|
||||||
EqualOp,
|
EqualOp,
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
floatExpr(0),
|
floatExpr(0),
|
||||||
),
|
),
|
||||||
block(
|
block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
block(
|
block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -552,8 +556,8 @@ varying vec3 V0;`,
|
|||||||
block(
|
block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -586,16 +590,16 @@ varying vec3 V0;`,
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 5),
|
localVariableExpr(5),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 3),
|
localVariableExpr(3),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 4),
|
localVariableExpr(4),
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -633,16 +637,16 @@ void main(void) {
|
|||||||
Block: block(
|
Block: block(
|
||||||
nil,
|
nil,
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 5),
|
localVariableExpr(5),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 3),
|
localVariableExpr(3),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 4),
|
localVariableExpr(4),
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@ -654,16 +658,16 @@ void main(void) {
|
|||||||
{Main: Float},
|
{Main: Float},
|
||||||
},
|
},
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 5),
|
localVariableExpr(5),
|
||||||
varNameExpr(Local, 0),
|
localVariableExpr(0),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 3),
|
localVariableExpr(3),
|
||||||
varNameExpr(Local, 1),
|
localVariableExpr(1),
|
||||||
),
|
),
|
||||||
assignStmt(
|
assignStmt(
|
||||||
varNameExpr(Local, 4),
|
localVariableExpr(4),
|
||||||
varNameExpr(Local, 2),
|
localVariableExpr(2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -83,7 +83,6 @@ const (
|
|||||||
type Expr struct {
|
type Expr struct {
|
||||||
Type ExprType
|
Type ExprType
|
||||||
Exprs []Expr
|
Exprs []Expr
|
||||||
Variable Variable
|
|
||||||
Int int32
|
Int int32
|
||||||
Float float32
|
Float float32
|
||||||
BuiltinFunc BuiltinFunc
|
BuiltinFunc BuiltinFunc
|
||||||
@ -97,7 +96,9 @@ type ExprType int
|
|||||||
const (
|
const (
|
||||||
IntExpr ExprType = iota
|
IntExpr ExprType = iota
|
||||||
FloatExpr
|
FloatExpr
|
||||||
VarName
|
UniformVariable
|
||||||
|
LocalVariable
|
||||||
|
StructMember
|
||||||
BuiltinFuncExpr
|
BuiltinFuncExpr
|
||||||
SwizzlingExpr
|
SwizzlingExpr
|
||||||
FunctionExpr
|
FunctionExpr
|
||||||
@ -109,19 +110,6 @@ const (
|
|||||||
Index
|
Index
|
||||||
)
|
)
|
||||||
|
|
||||||
type Variable struct {
|
|
||||||
Type VariableType
|
|
||||||
Index int
|
|
||||||
}
|
|
||||||
|
|
||||||
type VariableType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
Uniform VariableType = iota
|
|
||||||
StructMember
|
|
||||||
Local
|
|
||||||
)
|
|
||||||
|
|
||||||
type Op string
|
type Op string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user