diff --git a/image_test.go b/image_test.go index 1ed9a7e13..a3051f36c 100644 --- a/image_test.go +++ b/image_test.go @@ -563,7 +563,7 @@ func TestImageEdge(t *testing.T) { // Issue #419 func TestImageTooManyFill(t *testing.T) { - const width = 256 + const width = 1024 src, _ := NewImage(1, 1, FilterNearest) dst, _ := NewImage(width, 1, FilterNearest) diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 5949a4256..0740d9f19 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -201,10 +201,32 @@ func (c *fillCommand) Exec(indexOffsetInBytes int) error { cr, cg, cb, ca := c.color.R, c.color.G, c.color.B, c.color.A const max = math.MaxUint8 - r := float64(cr) / max - g := float64(cg) / max - b := float64(cb) / max - a := float64(ca) / max + r := float32(cr) / max + g := float32(cg) / max + b := float32(cb) / max + a := float32(ca) / max + + // On some machines like MacBook Pro, exact 0 and exact 1 might cause problems + // at glClear() (#452). + if r == 0 { + r = math.Nextafter32(r, 1) + } + if g == 0 { + g = math.Nextafter32(g, 1) + } + if b == 0 { + b = math.Nextafter32(b, 1) + } + if r == 1 { + r = math.Nextafter32(r, 0) + } + if g == 1 { + g = math.Nextafter32(g, 0) + } + if b == 1 { + b = math.Nextafter32(b, 0) + } + if err := opengl.GetContext().FillFramebuffer(r, g, b, a); err != nil { return err } diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index 16ea2923f..2eabe9080 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -281,9 +281,9 @@ func (c *Context) setViewportImpl(width, height int) { }) } -func (c *Context) FillFramebuffer(r, g, b, a float64) error { +func (c *Context) FillFramebuffer(r, g, b, a float32) error { return c.runOnContextThread(func() error { - gl.ClearColor(float32(r), float32(g), float32(b), float32(a)) + gl.ClearColor(r, g, b, a) gl.Clear(gl.COLOR_BUFFER_BIT) return nil }) diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 599e01f8a..59f8c125d 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -252,10 +252,10 @@ func (c *Context) setViewportImpl(width, height int) { gl.Viewport(0, 0, width, height) } -func (c *Context) FillFramebuffer(r, g, b, a float64) error { +func (c *Context) FillFramebuffer(r, g, b, a float32) error { // TODO: Use f? gl := c.gl - gl.ClearColor(float32(r), float32(g), float32(b), float32(a)) + gl.ClearColor(r, g, b, a) gl.Clear(gl.COLOR_BUFFER_BIT) return nil } diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index 96d2da0a5..72ff8c15b 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -220,9 +220,9 @@ func (c *Context) setViewportImpl(width, height int) { gl.Viewport(0, 0, width, height) } -func (c *Context) FillFramebuffer(r, g, b, a float64) error { +func (c *Context) FillFramebuffer(r, g, b, a float32) error { gl := c.gl - gl.ClearColor(float32(r), float32(g), float32(b), float32(a)) + gl.ClearColor(r, g, b, a) gl.Clear(mgl.COLOR_BUFFER_BIT) return nil }