ebiten/internal/shader/type.go

87 lines
1.9 KiB
Go
Raw Normal View History

2020-05-08 17:46:01 +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 shader
import (
"fmt"
"go/ast"
"github.com/hajimehoshi/ebiten/internal/shaderir"
2020-05-08 17:46:01 +02:00
)
// TODO: What about array types?
2020-05-10 17:13:08 +02:00
type typ struct {
ir shaderir.Type
name string
2020-05-10 17:13:08 +02:00
}
func (cs *compileState) parseType(expr ast.Expr) typ {
2020-05-08 17:46:01 +02:00
switch t := expr.(type) {
case *ast.Ident:
switch t.Name {
case "bool":
return typ{
ir: shaderir.Type{Main: shaderir.Bool},
}
case "int":
return typ{
ir: shaderir.Type{Main: shaderir.Int},
}
2020-05-08 17:46:01 +02:00
case "float":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Float},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "vec2":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Vec2},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "vec3":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Vec3},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "vec4":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Vec4},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "mat2":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Mat2},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "mat3":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Mat3},
2020-05-10 17:13:08 +02:00
}
2020-05-08 17:46:01 +02:00
case "mat4":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Mat4},
2020-05-10 17:13:08 +02:00
}
case "texture2d":
2020-05-10 17:13:08 +02:00
return typ{
ir: shaderir.Type{Main: shaderir.Texture2D},
2020-05-10 17:13:08 +02:00
}
2020-05-10 16:56:56 +02:00
default:
cs.addError(t.Pos(), fmt.Sprintf("unexpected type: %s", t.Name))
2020-05-10 17:13:08 +02:00
return typ{}
}
case *ast.StructType:
cs.addError(t.Pos(), "struct is not implemented")
2020-05-10 17:13:08 +02:00
return typ{}
default:
cs.addError(t.Pos(), fmt.Sprintf("unepxected type: %v", t))
return typ{}
2020-05-08 17:46:01 +02:00
}
}