Refactoring

This commit is contained in:
Hajime Hoshi 2013-11-28 09:57:30 +09:00
parent 861449cbd7
commit c9e8036617
3 changed files with 9 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import (
type Framebuffer C.GLuint type Framebuffer C.GLuint
func createFramebuffer(nativeTexture C.GLuint) C.GLuint { func createFramebuffer(nativeTexture C.GLuint) Framebuffer {
framebuffer := C.GLuint(0) framebuffer := C.GLuint(0)
C.glGenFramebuffers(1, &framebuffer) C.glGenFramebuffers(1, &framebuffer)
@ -33,7 +33,7 @@ func createFramebuffer(nativeTexture C.GLuint) C.GLuint {
C.glClearColor(0, 0, 0, 1) C.glClearColor(0, 0, 0, 1)
C.glClear(C.GL_COLOR_BUFFER_BIT) C.glClear(C.GL_COLOR_BUFFER_BIT)
return framebuffer return Framebuffer(framebuffer)
} }
// TODO: Rename them // TODO: Rename them
@ -46,9 +46,7 @@ func New(width, height int, filter texture.Filter) (
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) return gtexture.NewRenderTarget(tex, f), tex, nil
return gtexture.NewRenderTarget(tex,
Framebuffer(framebuffer.(C.GLuint))), tex, nil
} }
func NewWithFramebuffer(width, height int, framebuffer Framebuffer) ( func NewWithFramebuffer(width, height int, framebuffer Framebuffer) (
@ -57,5 +55,8 @@ func NewWithFramebuffer(width, height int, framebuffer Framebuffer) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
return gtexture.NewRenderTarget(tex, framebuffer), nil f := func(native interface{}) interface{} {
return framebuffer
}
return gtexture.NewRenderTarget(tex, f), nil
} }

View File

@ -5,10 +5,10 @@ type RenderTarget struct {
framebuffer interface{} framebuffer interface{}
} }
func NewRenderTarget(texture *Texture, framebuffer interface{}) *RenderTarget { func NewRenderTarget(texture *Texture, create func(native interface{}) interface{}) *RenderTarget {
return &RenderTarget{ return &RenderTarget{
texture: texture, texture: texture,
framebuffer: framebuffer, framebuffer: create(texture.native),
} }
} }

View File

@ -110,8 +110,3 @@ func (texture *Texture) DrawParts(parts []graphics.TexturePart, drawable Drawabl
} }
drawable.Draw(texture.native, quads) drawable.Draw(texture.native, quads)
} }
func (texture *Texture) CreateFramebuffer(
create func(native interface{}) interface{}) interface{} {
return create(texture.native)
}