mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
opengl: Cache a composition mode
This commit is contained in:
parent
8ae1e292ab
commit
321f5e376e
@ -49,6 +49,7 @@ func (p Program) id() programID {
|
|||||||
type context struct {
|
type context struct {
|
||||||
locationCache *locationCache
|
locationCache *locationCache
|
||||||
funcs chan func()
|
funcs chan func()
|
||||||
|
lastCompositionMode CompositionMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() *Context {
|
func NewContext() *Context {
|
||||||
@ -72,6 +73,7 @@ func NewContext() *Context {
|
|||||||
}
|
}
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
c.funcs = make(chan func())
|
c.funcs = make(chan func())
|
||||||
|
c.lastCompositionMode = CompositionModeUnknown
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +112,11 @@ func (c *Context) Init() {
|
|||||||
|
|
||||||
func (c *Context) BlendFunc(mode CompositionMode) {
|
func (c *Context) BlendFunc(mode CompositionMode) {
|
||||||
c.RunOnContextThread(func() {
|
c.RunOnContextThread(func() {
|
||||||
|
if c.lastCompositionMode == mode {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.lastCompositionMode = mode
|
||||||
s, d := c.operations(mode)
|
s, d := c.operations(mode)
|
||||||
// TODO: Cache and don't call this often
|
|
||||||
gl.BlendFunc(uint32(s), uint32(d))
|
gl.BlendFunc(uint32(s), uint32(d))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ type context struct {
|
|||||||
lastFramebuffer Framebuffer
|
lastFramebuffer Framebuffer
|
||||||
locationCache *locationCache
|
locationCache *locationCache
|
||||||
lastProgramID programID
|
lastProgramID programID
|
||||||
|
lastCompositionMode CompositionMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() *Context {
|
func NewContext() *Context {
|
||||||
@ -114,6 +115,7 @@ func NewContext() *Context {
|
|||||||
}
|
}
|
||||||
c.gl = gl
|
c.gl = gl
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
|
c.lastCompositionMode = CompositionModeUnknown
|
||||||
c.init()
|
c.init()
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@ -127,8 +129,11 @@ func (c *Context) init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) BlendFunc(mode CompositionMode) {
|
func (c *Context) BlendFunc(mode CompositionMode) {
|
||||||
|
if c.lastCompositionMode == mode {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.lastCompositionMode = mode
|
||||||
s, d := c.operations(mode)
|
s, d := c.operations(mode)
|
||||||
// TODO: Cache and don't call this often
|
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.BlendFunc(int(s), int(d))
|
gl.BlendFunc(int(s), int(d))
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ type Context struct {
|
|||||||
type CompositionMode int
|
type CompositionMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CompositionModeSourceOver CompositionMode = iota
|
CompositionModeSourceOver CompositionMode = iota // This value must be 0 (= initial value)
|
||||||
CompositionModeClear
|
CompositionModeClear
|
||||||
CompositionModeCopy
|
CompositionModeCopy
|
||||||
CompositionModeDesination
|
CompositionModeDesination
|
||||||
@ -57,6 +57,7 @@ const (
|
|||||||
CompositionModeDestinationAtop
|
CompositionModeDestinationAtop
|
||||||
CompositionModeXor
|
CompositionModeXor
|
||||||
CompositionModeLighter
|
CompositionModeLighter
|
||||||
|
CompositionModeUnknown
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Context) operations(mode CompositionMode) (src operation, dst operation) {
|
func (c *Context) operations(mode CompositionMode) (src operation, dst operation) {
|
||||||
|
Loading…
Reference in New Issue
Block a user