mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Refactoring: Move adjustment logic for glClearColor to opengl package
This commit is contained in:
parent
8e7e960b56
commit
847ba9de0c
@ -205,28 +205,6 @@ func (c *fillCommand) Exec(indexOffsetInBytes int) error {
|
||||
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
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
package math
|
||||
|
||||
// NextPowerOf2Int returns a nearest power of 2 to x.
|
||||
func NextPowerOf2Int(x int) int {
|
||||
if x <= 0 {
|
||||
panic("x must be positive")
|
||||
|
@ -14,6 +14,34 @@
|
||||
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
var (
|
||||
zeroPlus float32
|
||||
oneMinus float32
|
||||
)
|
||||
|
||||
func init() {
|
||||
zeroPlus = math.Nextafter32(0, 1)
|
||||
oneMinus = math.Nextafter32(1, 0)
|
||||
}
|
||||
|
||||
// adjustForClearColor adjust the value x for glClearColor function.
|
||||
//
|
||||
// On some machines like MacBook Pro, exact 0 and exact 1 might cause problems
|
||||
// at glClear() (#452).
|
||||
func adjustForClearColor(x float32) float32 {
|
||||
if x <= 0 {
|
||||
return zeroPlus
|
||||
}
|
||||
if x >= 1 {
|
||||
return oneMinus
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
var (
|
||||
Nearest Filter
|
||||
Linear Filter
|
||||
|
@ -283,7 +283,10 @@ func (c *Context) setViewportImpl(width, height int) {
|
||||
|
||||
func (c *Context) FillFramebuffer(r, g, b, a float32) error {
|
||||
return c.runOnContextThread(func() error {
|
||||
gl.ClearColor(r, g, b, a)
|
||||
gl.ClearColor(adjustForClearColor(r),
|
||||
adjustForClearColor(g),
|
||||
adjustForClearColor(b),
|
||||
adjustForClearColor(a))
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
return nil
|
||||
})
|
||||
|
@ -255,7 +255,10 @@ func (c *Context) setViewportImpl(width, height int) {
|
||||
func (c *Context) FillFramebuffer(r, g, b, a float32) error {
|
||||
// TODO: Use f?
|
||||
gl := c.gl
|
||||
gl.ClearColor(r, g, b, a)
|
||||
gl.ClearColor(adjustForClearColor(r),
|
||||
adjustForClearColor(g),
|
||||
adjustForClearColor(b),
|
||||
adjustForClearColor(a))
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
return nil
|
||||
}
|
||||
|
@ -222,7 +222,10 @@ func (c *Context) setViewportImpl(width, height int) {
|
||||
|
||||
func (c *Context) FillFramebuffer(r, g, b, a float32) error {
|
||||
gl := c.gl
|
||||
gl.ClearColor(r, g, b, a)
|
||||
gl.ClearColor(adjustForClearColor(r),
|
||||
adjustForClearColor(g),
|
||||
adjustForClearColor(b),
|
||||
adjustForClearColor(a))
|
||||
gl.Clear(mgl.COLOR_BUFFER_BIT)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user