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