opengl: Cache a composition mode

This commit is contained in:
Hajime Hoshi 2016-02-29 01:44:09 +09:00
parent 8ae1e292ab
commit 321f5e376e
3 changed files with 20 additions and 9 deletions

View File

@ -49,6 +49,7 @@ func (p Program) id() programID {
type context struct {
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))
})
}

View File

@ -67,6 +67,7 @@ type context struct {
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))
}

View File

@ -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) {