Remove opengl.RenderTarget

This commit is contained in:
Hajime Hoshi 2013-10-17 10:32:16 +09:00
parent db4e3fdc03
commit c8011ffe88
3 changed files with 15 additions and 26 deletions

View File

@ -15,13 +15,13 @@ import (
)
type Context struct {
screen *RenderTarget
screen *Texture
screenWidth int
screenHeight int
screenScale int
textures map[C.GLuint]*Texture
currentOffscreen *RenderTarget
mainFramebufferTexture *RenderTarget
currentOffscreen *Texture
mainFramebufferTexture *Texture
}
func newContext(screenWidth, screenHeight, screenScale int) *Context {
@ -49,7 +49,7 @@ func (context *Context) Init() {
screenID := context.NewRenderTarget(
context.screenWidth, context.screenHeight)
context.screen = (*RenderTarget)(context.textures[C.GLuint(screenID)])
context.screen = context.textures[C.GLuint(screenID)]
}
func (context *Context) TextureID(renderTargetID graphics.RenderTargetID) graphics.TextureID {
@ -149,15 +149,15 @@ func abs(x int) int {
}
func (context *Context) SetOffscreen(renderTargetID graphics.RenderTargetID) {
renderTarget :=
(*RenderTarget)(context.textures[C.GLuint(renderTargetID)])
renderTarget := context.textures[C.GLuint(renderTargetID)]
// TODO: This is a kind of side-effect.
if renderTarget.framebuffer == 0 {
renderTarget.framebuffer = createFramebuffer(renderTarget.id)
}
context.setOffscreen(renderTarget)
}
func (context *Context) setOffscreen(renderTarget *RenderTarget) {
func (context *Context) setOffscreen(renderTarget *Texture) {
context.currentOffscreen = renderTarget
C.glFlush()
@ -293,11 +293,12 @@ func (context *Context) NewRenderTarget(width, height int) graphics.RenderTarget
renderTarget := newRenderTarget(width, height)
context.textures[renderTarget.id] = (*Texture)(renderTarget)
context.SetOffscreen(renderTarget.ID())
//context.setOffscreen((*Texture)(renderTarget))
context.SetOffscreen(graphics.RenderTargetID(renderTarget.id))
context.Clear()
context.resetOffscreen()
return renderTarget.ID()
return graphics.RenderTargetID(renderTarget.id)
}
func (context *Context) NewTextureFromImage(img image.Image) (

View File

@ -53,7 +53,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
{0, scale, 0},
},
}
context.DrawTexture(context.screen.TextureID(),
context.DrawTexture(graphics.TextureID(context.screen.id),
geometryMatrix, matrix.IdentityColor())
context.flush()
}

View File

@ -103,9 +103,8 @@ func (err textureError) Error() string {
return "Texture Error: " + string(err)
}
func newRenderTarget(width, height int) *RenderTarget {
renderTarget := createTexture(width, height, nil)
return (*RenderTarget)(renderTarget)
func newRenderTarget(width, height int) *Texture {
return createTexture(width, height, nil)
}
func newTextureFromImage(img image.Image) (*Texture, error) {
@ -123,8 +122,8 @@ func newTextureFromImage(img image.Image) (*Texture, error) {
}
func newRenderTargetWithFramebuffer(width, height int,
framebuffer C.GLuint) *RenderTarget {
texture := &Texture{
framebuffer C.GLuint) *Texture {
return &Texture{
id: 0,
width: width,
height: height,
@ -132,15 +131,4 @@ func newRenderTargetWithFramebuffer(width, height int,
textureHeight: int(clp2(uint64(height))),
framebuffer: framebuffer,
}
return (*RenderTarget)(texture)
}
type RenderTarget Texture
func (renderTarget *RenderTarget) TextureID() graphics.TextureID {
return graphics.TextureID(renderTarget.id)
}
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
return graphics.RenderTargetID(renderTarget.id)
}