ebiten: Change the type of Uniforms to map[string]interface{}

Fixes #1324
This commit is contained in:
Hajime Hoshi
2020-09-06 20:10:33 +09:00
parent 52fcab7a90
commit 850303b770
5 changed files with 49 additions and 16 deletions
+30 -2
View File
@@ -19,6 +19,7 @@ import (
"fmt"
"go/parser"
"go/token"
"strings"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/mipmap"
@@ -102,7 +103,8 @@ func __vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2, vec4) {
}
type Shader struct {
shader *mipmap.Shader
shader *mipmap.Shader
uniformNames []string
}
func NewShader(src []byte) (*Shader, error) {
@@ -133,7 +135,8 @@ func NewShader(src []byte) (*Shader, error) {
}
return &Shader{
shader: mipmap.NewShader(s),
shader: mipmap.NewShader(s),
uniformNames: s.UniformNames,
}, nil
}
@@ -141,3 +144,28 @@ func (s *Shader) Dispose() {
s.shader.MarkDisposed()
s.shader = nil
}
func (s *Shader) convertUniforms(uniforms map[string]interface{}) []interface{} {
names := map[string]int{}
var idx int
for _, n := range s.uniformNames {
if strings.HasPrefix(n, "__") {
continue
}
names[n] = idx
idx++
}
us := make([]interface{}, len(names))
for n, u := range uniforms {
idx, ok := names[n]
if !ok {
// TODO: Panic here?
continue
}
us[idx] = u
}
// TODO: Check the uniform variable types?
return us
}