From 815afe6670f9b40678f56561d0930a44c71053f2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 1 Jan 2020 01:39:45 +0900 Subject: [PATCH] graphicsdriver/opengl: Reduce calls of glBindTexture --- internal/graphicsdriver/opengl/context_desktop.go | 6 +++--- internal/graphicsdriver/opengl/pbo_desktop.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_desktop.go b/internal/graphicsdriver/opengl/context_desktop.go index 78e16c0f2..85ed406e6 100644 --- a/internal/graphicsdriver/opengl/context_desktop.go +++ b/internal/graphicsdriver/opengl/context_desktop.go @@ -548,8 +548,7 @@ func (c *context) newPixelBufferObject(width, height int) buffer { return bf } -func (c *context) mapPixelBuffer(buffer buffer, t textureNative) uintptr { - c.bindTexture(t) +func (c *context) mapPixelBuffer(buffer buffer) uintptr { var ptr uintptr _ = c.t.Call(func() error { gl.BindBuffer(gl.PIXEL_UNPACK_BUFFER, uint32(buffer)) @@ -561,7 +560,8 @@ func (c *context) mapPixelBuffer(buffer buffer, t textureNative) uintptr { return ptr } -func (c *context) unmapPixelBuffer(buffer buffer, width, height int) { +func (c *context) unmapPixelBuffer(buffer buffer, t textureNative, width, height int) { + c.bindTexture(t) _ = c.t.Call(func() error { gl.UnmapBuffer(gl.PIXEL_UNPACK_BUFFER) gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, nil) diff --git a/internal/graphicsdriver/opengl/pbo_desktop.go b/internal/graphicsdriver/opengl/pbo_desktop.go index 66d84a76c..42623c233 100644 --- a/internal/graphicsdriver/opengl/pbo_desktop.go +++ b/internal/graphicsdriver/opengl/pbo_desktop.go @@ -44,7 +44,7 @@ func (s *pboState) mapPBO(img *Image) { } s.image = img - s.mappedPBO = img.driver.context.mapPixelBuffer(img.pbo, img.textureNative) + s.mappedPBO = img.driver.context.mapPixelBuffer(img.pbo) if s.mappedPBO == 0 { panic("opengl: mapPixelBuffer failed") @@ -69,7 +69,7 @@ func (s *pboState) draw(pix []byte, x, y, width, height int) { func (s *pboState) unmapPBO() { i := s.image - i.driver.context.unmapPixelBuffer(i.pbo, i.width, i.height) + i.driver.context.unmapPixelBuffer(i.pbo, i.textureNative, i.width, i.height) s.image = nil s.mappedPBO = 0