2020-05-11 17:19:42 +02:00
|
|
|
// Copyright 2020 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package shaderir
|
|
|
|
|
|
|
|
type Program struct {
|
2020-05-14 16:47:15 +02:00
|
|
|
Uniforms []Type
|
|
|
|
Attributes []Type
|
|
|
|
Varyings []Type
|
2020-05-11 17:19:42 +02:00
|
|
|
Funcs []Func
|
|
|
|
VertexEntry string
|
|
|
|
FragmentEntry string
|
|
|
|
|
|
|
|
structNames map[string]string
|
|
|
|
structTypes []Type
|
|
|
|
}
|
|
|
|
|
|
|
|
type Func struct {
|
2020-05-13 16:31:17 +02:00
|
|
|
Name string
|
|
|
|
InParams []Type
|
|
|
|
InOutParams []Type
|
|
|
|
OutParams []Type
|
|
|
|
Block Block
|
2020-05-11 17:19:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Block struct {
|
|
|
|
LocalVars []Type
|
|
|
|
Stmts []Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
type Stmt struct {
|
2020-05-14 20:12:23 +02:00
|
|
|
Type StmtType
|
|
|
|
Exprs []Expr
|
|
|
|
Blocks []Block
|
|
|
|
ForInit Expr
|
|
|
|
ForRest Expr
|
2020-05-11 17:19:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type StmtType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ExprStmt StmtType = iota
|
2020-05-13 18:45:33 +02:00
|
|
|
BlockStmt
|
2020-05-11 17:19:42 +02:00
|
|
|
Assign
|
|
|
|
If
|
|
|
|
For
|
|
|
|
Continue
|
|
|
|
Break
|
2020-05-13 20:14:39 +02:00
|
|
|
Return
|
2020-05-11 17:19:42 +02:00
|
|
|
Discard
|
|
|
|
)
|
|
|
|
|
|
|
|
type Expr struct {
|
2020-05-14 16:47:15 +02:00
|
|
|
Type ExprType
|
|
|
|
Exprs []Expr
|
|
|
|
Variable Variable
|
2020-05-14 19:10:07 +02:00
|
|
|
Num float64
|
|
|
|
Ident string
|
2020-05-14 16:47:15 +02:00
|
|
|
Op Op
|
2020-05-11 17:19:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ExprType int
|
|
|
|
|
|
|
|
const (
|
2020-05-14 19:10:07 +02:00
|
|
|
Numeric ExprType = iota
|
2020-05-14 16:47:15 +02:00
|
|
|
VarName
|
2020-05-11 17:19:42 +02:00
|
|
|
Ident
|
|
|
|
Unary
|
|
|
|
Binary
|
|
|
|
Call
|
|
|
|
Selector
|
|
|
|
Index
|
|
|
|
)
|
|
|
|
|
2020-05-14 16:47:15 +02:00
|
|
|
type Variable struct {
|
|
|
|
Type VariableType
|
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
|
|
|
type VariableType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Uniform VariableType = iota
|
|
|
|
Attribute
|
|
|
|
Varying
|
|
|
|
Local
|
|
|
|
)
|
|
|
|
|
2020-05-11 17:19:42 +02:00
|
|
|
type Op string
|
|
|
|
|
|
|
|
const (
|
|
|
|
Add Op = "+"
|
|
|
|
Sub Op = "-"
|
|
|
|
Neg Op = "!"
|
|
|
|
Mul Op = "*"
|
|
|
|
Div Op = "/"
|
|
|
|
Mod Op = "%"
|
|
|
|
LShift Op = "<<"
|
|
|
|
RShift Op = ">>"
|
|
|
|
LT Op = "<"
|
|
|
|
LE Op = "<="
|
|
|
|
GT Op = ">"
|
|
|
|
GE Op = ">="
|
|
|
|
Eq Op = "=="
|
|
|
|
NE Op = "!="
|
|
|
|
And Op = "&"
|
|
|
|
Xor Op = "^"
|
|
|
|
Or Op = "|"
|
|
|
|
AndAnd Op = "&&"
|
|
|
|
OrOr Op = "||"
|
|
|
|
Cond Op = "?:"
|
|
|
|
)
|