shaderir: Add func params

This commit is contained in:
Hajime Hoshi 2020-05-13 23:31:17 +09:00
parent 919fc29016
commit 3d7c102472
4 changed files with 53 additions and 10 deletions

View File

@ -80,8 +80,27 @@ func (p *Program) glslVarDecl(t *Type, varname string) string {
} }
func (p *Program) glslFunc(f *Func) []string { func (p *Program) glslFunc(f *Func) []string {
var args []string
var idx int
for _, t := range f.InParams {
args = append(args, "in "+p.glslVarDecl(&t, fmt.Sprintf("l%d", idx)))
idx++
}
for _, t := range f.InOutParams {
args = append(args, "inout "+p.glslVarDecl(&t, fmt.Sprintf("l%d", idx)))
idx++
}
for _, t := range f.OutParams {
args = append(args, "out "+p.glslVarDecl(&t, fmt.Sprintf("l%d", idx)))
idx++
}
argsstr := "void"
if len(args) > 0 {
argsstr = strings.Join(args, ", ")
}
return []string{ return []string{
fmt.Sprintf(`void %s(void) {`, f.Name), fmt.Sprintf(`void %s(%s) {`, f.Name, argsstr),
`}`, `}`,
} }
} }

View File

@ -90,7 +90,7 @@ attribute vec2 A0;
varying vec3 V0;`, varying vec3 V0;`,
}, },
{ {
Name: "Function", Name: "Func",
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
@ -99,6 +99,29 @@ varying vec3 V0;`,
}, },
}, },
Glsl: `void F0(void) { Glsl: `void F0(void) {
}`,
},
{
Name: "FuncParams",
Program: Program{
Funcs: []Func{
{
Name: "F0",
InParams: []Type{
{Main: Float},
{Main: Vec2},
{Main: Vec4},
},
InOutParams: []Type{
{Main: Mat2},
},
OutParams: []Type{
{Main: Mat4},
},
},
},
},
Glsl: `void F0(in float l0, in vec2 l1, in vec4 l2, inout mat2 l3, out mat4 l4) {
}`, }`,
}, },
} }

View File

@ -32,10 +32,11 @@ type Variable struct {
} }
type Func struct { type Func struct {
Name string Name string
InParams []Type InParams []Type
OutParams []Type InOutParams []Type
Block Block OutParams []Type
Block Block
} }
type Block struct { type Block struct {

View File

@ -39,7 +39,7 @@ func now() int64 {
} }
func fixed26_6ToFloat64(x fixed.Int26_6) float64 { func fixed26_6ToFloat64(x fixed.Int26_6) float64 {
return float64(x >> 6) + float64(x & ((1 << 6) - 1)) / float64(1 << 6) return float64(x>>6) + float64(x&((1<<6)-1))/float64(1<<6)
} }
const ( const (
@ -343,8 +343,8 @@ func MeasureString(text string, face font.Face) image.Point {
if fx > w { if fx > w {
w = fx w = fx
} }
if (fy+faceHeight) > h { if (fy + faceHeight) > h {
h = fy+faceHeight h = fy + faceHeight
} }
prevR = r prevR = r
@ -352,7 +352,7 @@ func MeasureString(text string, face font.Face) image.Point {
bounds := image.Point{ bounds := image.Point{
X: int(math.Ceil(fixed26_6ToFloat64(w))), X: int(math.Ceil(fixed26_6ToFloat64(w))),
Y: int(math.Ceil(fixed26_6ToFloat64(h+faceDescent))), Y: int(math.Ceil(fixed26_6ToFloat64(h + faceDescent))),
} }
return bounds return bounds