Remove RenderTarget.Texture

This commit is contained in:
Hajime Hoshi 2013-10-27 22:09:19 +09:00
parent 0bf319f7d0
commit f290a137a9
3 changed files with 10 additions and 14 deletions

View File

@ -120,10 +120,10 @@ func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
context.setOffscreen(renderTarget) context.setOffscreen(renderTarget)
} }
func (context *Context) setOffscreen(renderTarget *grendertarget.RenderTarget) { func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) {
C.glFlush() C.glFlush()
renderTarget.SetAsOffscreen(func(framebuffer interface{}) { rt.SetAsOffscreen(func(framebuffer interface{}) {
f := framebuffer.(rendertarget.Framebuffer) f := framebuffer.(rendertarget.Framebuffer)
C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f)) C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f))
err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER) 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.glBlendFuncSeparate(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA,
C.GL_ZERO, C.GL_ONE) C.GL_ZERO, C.GL_ONE)
isUsingMainFramebuffer := renderTarget == context.mainFramebufferTexture isUsingMainFramebuffer := rt == context.mainFramebufferTexture
setter := &viewportSetter{ setter := &viewportSetter{
isUsingMainFramebuffer, isUsingMainFramebuffer,
context.screenHeight * context.screenScale, context.screenHeight * context.screenScale,
context, 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) ( func (context *Context) newRenderTarget(width, height int, filter texture.Filter) (
graphics.RenderTargetId, error) { graphics.RenderTargetId, error) {
renderTarget, err := rendertarget.New(width, height, filter) renderTarget, texture, err := rendertarget.New(width, height, filter)
if err != nil { if err != nil {
return 0, nil return 0, nil
} }
renderTargetId := graphics.RenderTargetId(<-newId) renderTargetId := graphics.RenderTargetId(<-newId)
textureId := graphics.TextureId(<-newId) textureId := graphics.TextureId(<-newId)
context.renderTargets[renderTargetId] = renderTarget context.renderTargets[renderTargetId] = renderTarget
context.textures[textureId] = renderTarget.Texture() context.textures[textureId] = texture
context.renderTargetToTexture[renderTargetId] = textureId context.renderTargetToTexture[renderTargetId] = textureId
context.setOffscreen(renderTarget) context.setOffscreen(renderTarget)

View File

@ -6,6 +6,7 @@ package rendertarget
import "C" import "C"
import ( import (
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture" "github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
gtexture "github.com/hajimehoshi/go-ebiten/graphics/texture"
"github.com/hajimehoshi/go-ebiten/graphics/rendertarget" "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) ( func New(width, height int, filter texture.Filter) (
*rendertarget.RenderTarget, error) { *rendertarget.RenderTarget, *gtexture.Texture, error) {
tex, err := texture.New(width, height, filter) tex, err := texture.New(width, height, filter)
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
f := func(native interface{}) interface{}{ f := func(native interface{}) interface{}{
return createFramebuffer(C.GLuint(native.(texture.Native))) return createFramebuffer(C.GLuint(native.(texture.Native)))
} }
framebuffer := tex.CreateFramebuffer(f) framebuffer := tex.CreateFramebuffer(f)
return rendertarget.NewWithFramebuffer(tex, return rendertarget.NewWithFramebuffer(tex,
Framebuffer(framebuffer.(C.GLuint))), nil Framebuffer(framebuffer.(C.GLuint))), tex, nil
} }
func NewWithFramebuffer(width, height int, framebuffer Framebuffer, func NewWithFramebuffer(width, height int, framebuffer Framebuffer,

View File

@ -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)) { func (renderTarget *RenderTarget) SetAsViewport(setter func(x, y, width, height int)) {
renderTarget.texture.SetAsViewport(setter) renderTarget.texture.SetAsViewport(setter)
} }