added an activate function and an exported TextureID so that other GL code can also use the canvas

This commit is contained in:
Thomas Friedel 2019-03-20 12:18:36 +01:00
parent c98bc6c23d
commit 04b3418c3b
3 changed files with 21 additions and 0 deletions

View file

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

View file

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

View file

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