From 321f5e376e0f15ed4448d95948bbfcbe3ede9a2f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 29 Feb 2016 01:44:09 +0900 Subject: [PATCH] opengl: Cache a composition mode --- internal/graphics/opengl/context_desktop.go | 11 ++++++++--- internal/graphics/opengl/context_js.go | 15 ++++++++++----- internal/graphics/opengl/types.go | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/internal/graphics/opengl/context_desktop.go b/internal/graphics/opengl/context_desktop.go index b84127668..f4aad11dc 100644 --- a/internal/graphics/opengl/context_desktop.go +++ b/internal/graphics/opengl/context_desktop.go @@ -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)) }) } diff --git a/internal/graphics/opengl/context_js.go b/internal/graphics/opengl/context_js.go index 6df06443a..6154b877a 100644 --- a/internal/graphics/opengl/context_js.go +++ b/internal/graphics/opengl/context_js.go @@ -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)) } diff --git a/internal/graphics/opengl/types.go b/internal/graphics/opengl/types.go index fc72b93b6..1485efc09 100644 --- a/internal/graphics/opengl/types.go +++ b/internal/graphics/opengl/types.go @@ -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) {