From 04b3418c3bce92eb263e75e6f0a1bd6c2546f84b Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Wed, 20 Mar 2019 12:18:36 +0100 Subject: [PATCH] added an activate function and an exported TextureID so that other GL code can also use the canvas --- backend/gogl/gogl.go | 10 ++++++++++ backend/xmobile/gen/gen.go | 1 + backend/xmobile/xmobile.go | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/backend/gogl/gogl.go b/backend/gogl/gogl.go index db791b6..7f982dd 100644 --- a/backend/gogl/gogl.go +++ b/backend/gogl/gogl.go @@ -257,6 +257,8 @@ func New(x, y, w, h int, ctx *GLContext) (*GoGLBackend, error) { type GoGLBackendOffscreen struct { GoGLBackend + TextureID uint32 + offscrBuf offscreenBuffer offscrImg Image } @@ -281,6 +283,7 @@ func NewOffscreen(w, h int, alpha bool, ctx *GLContext) (*GoGLBackendOffscreen, bo.offscrImg.w = bo.offscrBuf.w bo.offscrImg.h = bo.offscrBuf.h bo.offscrImg.tex = bo.offscrBuf.tex + bo.TextureID = bo.offscrBuf.tex } b.disableTextureRenderTarget = func() { b.enableTextureRenderTarget(&bo.offscrBuf) @@ -326,6 +329,13 @@ func glError() error { return nil } +// Activate only needs to be called if there is other +// code also using the GL state +func (b *GoGLBackend) Activate() { + activeContext = nil + b.activate() +} + var activeContext *GoGLBackend func (b *GoGLBackend) activate() { diff --git a/backend/xmobile/gen/gen.go b/backend/xmobile/gen/gen.go index f62214b..51317a4 100644 --- a/backend/xmobile/gen/gen.go +++ b/backend/xmobile/gen/gen.go @@ -258,6 +258,7 @@ func rewriteMain(src string) string { "type XMobileBackend struct {\n", 1) src = strings.Replace(src, "func NewGLContext() (*GLContext, error) {", "func NewGLContext(glctx gl.Context) (*GLContext, error) {", 1) + src = strings.Replace(src, "TextureID uint32", "TextureID gl.Texture", 1) src = strings.Replace(src, ` err := gl.Init() diff --git a/backend/xmobile/xmobile.go b/backend/xmobile/xmobile.go index 06c749b..7a27c3c 100755 --- a/backend/xmobile/xmobile.go +++ b/backend/xmobile/xmobile.go @@ -252,6 +252,8 @@ func New(x, y, w, h int, ctx *GLContext) (*XMobileBackend, error) { type XMobileBackendOffscreen struct { XMobileBackend + TextureID gl.Texture + offscrBuf offscreenBuffer offscrImg Image } @@ -274,6 +276,7 @@ func NewOffscreen(w, h int, alpha bool, ctx *GLContext) (*XMobileBackendOffscree bo.offscrImg.w = bo.offscrBuf.w bo.offscrImg.h = bo.offscrBuf.h bo.offscrImg.tex = bo.offscrBuf.tex + bo.TextureID = bo.offscrBuf.tex } b.disableTextureRenderTarget = func() { b.enableTextureRenderTarget(&bo.offscrBuf) @@ -319,6 +322,13 @@ func glError(b *XMobileBackend) error { return nil } +// Activate only needs to be called if there is other +// code also using the GL state +func (b *XMobileBackend) Activate() { + activeContext = nil + b.activate() +} + var activeContext *XMobileBackend func (b *XMobileBackend) activate() {