ebiten: Error when the entrypoint is missing

Fixes #1323
This commit is contained in:
Hajime Hoshi 2020-09-01 00:37:14 +09:00
parent 557b321086
commit 20a01ed328
2 changed files with 19 additions and 2 deletions

View File

@ -116,12 +116,22 @@ func NewShader(src []byte) (*Shader, error) {
return nil, err
}
// TODO: Create a pseudo vertex entrypoint to treat the attribute values correctly.
s, err := shader.Compile(fs, f, "__vertex", "Fragment", graphics.ShaderImageNum)
const (
vert = "__vertex"
frag = "Fragment"
)
s, err := shader.Compile(fs, f, vert, frag, graphics.ShaderImageNum)
if err != nil {
return nil, err
}
if s.VertexFunc.Block == nil {
return nil, fmt.Errorf("ebiten: vertex shader entry point '%s' is missing", vert)
}
if s.FragmentFunc.Block == nil {
return nil, fmt.Errorf("ebiten: fragment shader entry point '%s' is missing", frag)
}
return &Shader{
shader: mipmap.NewShader(s),
}, nil

View File

@ -174,3 +174,10 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
t.Errorf("error must be non-nil but was nil")
}
}
func TestShaderNoMain(t *testing.T) {
if _, err := NewShader([]byte(`package main
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
}