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

View File

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

View File

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