Skip to content

Commit

Permalink
shaderir: Add func params
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed May 13, 2020
1 parent 919fc29 commit 3d7c102
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
21 changes: 20 additions & 1 deletion internal/shaderir/glsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,27 @@ func (p *Program) glslVarDecl(t *Type, varname string) 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{
fmt.Sprintf(`void %s(void) {`, f.Name),
fmt.Sprintf(`void %s(%s) {`, f.Name, argsstr),
`}`,
}
}
25 changes: 24 additions & 1 deletion internal/shaderir/ir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ attribute vec2 A0;
varying vec3 V0;`,
},
{
Name: "Function",
Name: "Func",
Program: Program{
Funcs: []Func{
{
Expand All @@ -99,6 +99,29 @@ varying vec3 V0;`,
},
},
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) {
}`,
},
}
Expand Down
9 changes: 5 additions & 4 deletions internal/shaderir/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ type Variable struct {
}

type Func struct {
Name string
InParams []Type
OutParams []Type
Block Block
Name string
InParams []Type
InOutParams []Type
OutParams []Type
Block Block
}

type Block struct {
Expand Down
8 changes: 4 additions & 4 deletions text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func now() int64 {
}

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 (
Expand Down Expand Up @@ -343,16 +343,16 @@ func MeasureString(text string, face font.Face) image.Point {
if fx > w {
w = fx
}
if (fy+faceHeight) > h {
h = fy+faceHeight
if (fy + faceHeight) > h {
h = fy + faceHeight
}

prevR = r
}

bounds := image.Point{
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
Expand Down

0 comments on commit 3d7c102

Please sign in to comment.