diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 30bd2598a..a4713a86a 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -120,10 +120,10 @@ func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) { context.setOffscreen(renderTarget) } -func (context *Context) setOffscreen(renderTarget *grendertarget.RenderTarget) { +func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) { C.glFlush() - renderTarget.SetAsOffscreen(func(framebuffer interface{}) { + rt.SetAsOffscreen(func(framebuffer interface{}) { f := framebuffer.(rendertarget.Framebuffer) C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f)) err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER) @@ -135,13 +135,13 @@ func (context *Context) setOffscreen(renderTarget *grendertarget.RenderTarget) { C.glBlendFuncSeparate(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA, C.GL_ZERO, C.GL_ONE) - isUsingMainFramebuffer := renderTarget == context.mainFramebufferTexture + isUsingMainFramebuffer := rt == context.mainFramebufferTexture setter := &viewportSetter{ isUsingMainFramebuffer, context.screenHeight * context.screenScale, context, } - renderTarget.SetAsViewport(setter.Set) + rt.SetAsViewport(setter.Set) }) } @@ -178,14 +178,14 @@ func (context *Context) flush() { func (context *Context) newRenderTarget(width, height int, filter texture.Filter) ( graphics.RenderTargetId, error) { - renderTarget, err := rendertarget.New(width, height, filter) + renderTarget, texture, err := rendertarget.New(width, height, filter) if err != nil { return 0, nil } renderTargetId := graphics.RenderTargetId(<-newId) textureId := graphics.TextureId(<-newId) context.renderTargets[renderTargetId] = renderTarget - context.textures[textureId] = renderTarget.Texture() + context.textures[textureId] = texture context.renderTargetToTexture[renderTargetId] = textureId context.setOffscreen(renderTarget) diff --git a/graphics/opengl/rendertarget/render_target.go b/graphics/opengl/rendertarget/render_target.go index 681ee1956..46ef34860 100644 --- a/graphics/opengl/rendertarget/render_target.go +++ b/graphics/opengl/rendertarget/render_target.go @@ -6,6 +6,7 @@ package rendertarget import "C" import ( "github.com/hajimehoshi/go-ebiten/graphics/opengl/texture" + gtexture "github.com/hajimehoshi/go-ebiten/graphics/texture" "github.com/hajimehoshi/go-ebiten/graphics/rendertarget" ) @@ -32,17 +33,17 @@ func createFramebuffer(nativeTexture C.GLuint) C.GLuint { } func New(width, height int, filter texture.Filter) ( - *rendertarget.RenderTarget, error) { + *rendertarget.RenderTarget, *gtexture.Texture, error) { tex, err := texture.New(width, height, filter) if err != nil { - return nil, err + return nil, nil, err } f := func(native interface{}) interface{}{ return createFramebuffer(C.GLuint(native.(texture.Native))) } framebuffer := tex.CreateFramebuffer(f) return rendertarget.NewWithFramebuffer(tex, - Framebuffer(framebuffer.(C.GLuint))), nil + Framebuffer(framebuffer.(C.GLuint))), tex, nil } func NewWithFramebuffer(width, height int, framebuffer Framebuffer, diff --git a/graphics/rendertarget/render_target.go b/graphics/rendertarget/render_target.go index f623604ad..e67abdf3c 100644 --- a/graphics/rendertarget/render_target.go +++ b/graphics/rendertarget/render_target.go @@ -16,11 +16,6 @@ func NewWithFramebuffer(texture *texture.Texture, framebuffer interface{}) *Rend } } -// TODO: Remove this -func (renderTarget *RenderTarget) Texture() *texture.Texture { - return renderTarget.texture -} - func (renderTarget *RenderTarget) SetAsViewport(setter func(x, y, width, height int)) { renderTarget.texture.SetAsViewport(setter) }