mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
shaderir: Add func params
This commit is contained in:
parent
919fc29016
commit
3d7c102472
@ -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),
|
||||
`}`,
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ attribute vec2 A0;
|
||||
varying vec3 V0;`,
|
||||
},
|
||||
{
|
||||
Name: "Function",
|
||||
Name: "Func",
|
||||
Program: Program{
|
||||
Funcs: []Func{
|
||||
{
|
||||
@ -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) {
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ type Variable struct {
|
||||
type Func struct {
|
||||
Name string
|
||||
InParams []Type
|
||||
InOutParams []Type
|
||||
OutParams []Type
|
||||
Block Block
|
||||
}
|
||||
|
@ -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 (
|
||||
@ -343,8 +343,8 @@ 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
|
||||
@ -352,7 +352,7 @@ func MeasureString(text string, face font.Face) image.Point {
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user