mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 15:04:28 +01:00
ebiten: Bug fix: Wrong uniform type was used
This change also includes PanicOnErrorAtImageAt, which panics when an error is detected at (*Image).At. This function is only for testing. Fixes #1349
This commit is contained in:
parent
3dab49fc39
commit
abbb929148
@ -17,3 +17,7 @@ package ebiten
|
|||||||
var (
|
var (
|
||||||
ImageToBytes = imageToBytes
|
ImageToBytes = imageToBytes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func PanicOnErrorAtImageAt() {
|
||||||
|
panicOnErrorAtImageAt = true
|
||||||
|
}
|
||||||
|
7
image.go
7
image.go
@ -24,6 +24,10 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/mipmap"
|
"github.com/hajimehoshi/ebiten/internal/mipmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// panicOnErrorAtImageAt indicates whether (*Image).At panics on an error or not.
|
||||||
|
// This value is set only on testing.
|
||||||
|
var panicOnErrorAtImageAt bool
|
||||||
|
|
||||||
// Image represents a rectangle set of pixels.
|
// Image represents a rectangle set of pixels.
|
||||||
// The pixel format is alpha-premultiplied RGBA.
|
// The pixel format is alpha-premultiplied RGBA.
|
||||||
// Image implements image.Image and draw.Image.
|
// Image implements image.Image and draw.Image.
|
||||||
@ -726,6 +730,9 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
}
|
}
|
||||||
pix, err := i.mipmap.Pixels(x, y, 1, 1)
|
pix, err := i.mipmap.Pixels(x, y, 1, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if panicOnErrorAtImageAt {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
theUIContext.setError(err)
|
theUIContext.setError(err)
|
||||||
return color.RGBA{}
|
return color.RGBA{}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ func skipTooSlowTests(t *testing.T) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
PanicOnErrorAtImageAt()
|
||||||
t.MainWithRunLoop(m)
|
t.MainWithRunLoop(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
shader.go
50
shader.go
@ -149,13 +149,21 @@ func (s *Shader) Dispose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Shader) convertUniforms(uniforms map[string]interface{}) []interface{} {
|
func (s *Shader) convertUniforms(uniforms map[string]interface{}) []interface{} {
|
||||||
names := map[string]int{}
|
type index struct {
|
||||||
|
resultIndex int
|
||||||
|
shaderUniformIndex int
|
||||||
|
}
|
||||||
|
|
||||||
|
names := map[string]index{}
|
||||||
var idx int
|
var idx int
|
||||||
for _, n := range s.uniformNames {
|
for i, n := range s.uniformNames {
|
||||||
if strings.HasPrefix(n, "__") {
|
if strings.HasPrefix(n, "__") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
names[n] = idx
|
names[n] = index{
|
||||||
|
resultIndex: idx,
|
||||||
|
shaderUniformIndex: i,
|
||||||
|
}
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,16 +171,16 @@ func (s *Shader) convertUniforms(uniforms map[string]interface{}) []interface{}
|
|||||||
for name, idx := range names {
|
for name, idx := range names {
|
||||||
if v, ok := uniforms[name]; ok {
|
if v, ok := uniforms[name]; ok {
|
||||||
// TODO: Check the uniform variable types?
|
// TODO: Check the uniform variable types?
|
||||||
us[idx] = v
|
us[idx.resultIndex] = v
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t := s.uniformTypes[idx]
|
t := s.uniformTypes[idx.shaderUniformIndex]
|
||||||
v := zeroUniformValue(t)
|
v := zeroUniformValue(t)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
panic(fmt.Sprintf("ebiten: unexpected uniform variable type: %s", t.String()))
|
panic(fmt.Sprintf("ebiten: unexpected uniform variable type: %s", t.String()))
|
||||||
}
|
}
|
||||||
us[idx] = v
|
us[idx.resultIndex] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Panic if uniforms include an invalid name
|
// TODO: Panic if uniforms include an invalid name
|
||||||
@ -188,39 +196,17 @@ func zeroUniformValue(t shaderir.Type) interface{} {
|
|||||||
return 0
|
return 0
|
||||||
case shaderir.Float:
|
case shaderir.Float:
|
||||||
return float32(0)
|
return float32(0)
|
||||||
case shaderir.Vec2:
|
|
||||||
return make([]float32, 2)
|
|
||||||
case shaderir.Vec3:
|
|
||||||
return make([]float32, 3)
|
|
||||||
case shaderir.Vec4:
|
|
||||||
return make([]float32, 4)
|
|
||||||
case shaderir.Mat2:
|
|
||||||
return make([]float32, 4)
|
|
||||||
case shaderir.Mat3:
|
|
||||||
return make([]float32, 9)
|
|
||||||
case shaderir.Mat4:
|
|
||||||
return make([]float32, 16)
|
|
||||||
case shaderir.Array:
|
case shaderir.Array:
|
||||||
switch t.Sub[0].Main {
|
switch t.Sub[0].Main {
|
||||||
case shaderir.Bool:
|
case shaderir.Bool:
|
||||||
return make([]bool, t.Length)
|
return make([]bool, t.Length)
|
||||||
case shaderir.Int:
|
case shaderir.Int:
|
||||||
return make([]int, t.Length)
|
return make([]int, t.Length)
|
||||||
case shaderir.Float:
|
default:
|
||||||
return make([]float32, t.Length)
|
return make([]float32, t.FloatNum())
|
||||||
case shaderir.Vec2:
|
|
||||||
return make([]float32, t.Length*2)
|
|
||||||
case shaderir.Vec3:
|
|
||||||
return make([]float32, t.Length*3)
|
|
||||||
case shaderir.Vec4:
|
|
||||||
return make([]float32, t.Length*4)
|
|
||||||
case shaderir.Mat2:
|
|
||||||
return make([]float32, t.Length*4)
|
|
||||||
case shaderir.Mat3:
|
|
||||||
return make([]float32, t.Length*9)
|
|
||||||
case shaderir.Mat4:
|
|
||||||
return make([]float32, t.Length*16)
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return make([]float32, t.FloatNum())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user