graphics: Refactoring: Now all Image objects are generated from New* funcs

This commit is contained in:
Hajime Hoshi 2016-05-15 21:08:39 +09:00
parent 9f2b53d24c
commit da0196911d
2 changed files with 19 additions and 25 deletions

View File

@ -14,10 +14,6 @@
package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/graphics"
)
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) {
c := &graphicsContext{}
if err := c.setSize(screenWidth, screenHeight, screenScale); err != nil {
@ -62,33 +58,14 @@ func (c *graphicsContext) setSize(screenWidth, screenHeight, screenScale int) er
if c.screen != nil {
c.screen.Dispose()
}
texture, err := graphics.NewTexture(glContext, screenWidth, screenHeight, glContext.Nearest)
screen, err := NewImage(screenWidth, screenHeight, FilterNearest)
if err != nil {
return err
}
screenF, err := graphics.NewFramebufferFromTexture(glContext, texture)
c.defaultRenderTarget, err = newImageWithZeroFramebuffer(screenWidth*screenScale, screenHeight*screenScale)
if err != nil {
return err
}
w, h := screenF.Size()
screen := &Image{
framebuffer: screenF,
texture: texture,
width: w,
height: h,
}
f, err := graphics.NewZeroFramebuffer(glContext, screenWidth*screenScale, screenHeight*screenScale)
if err != nil {
return err
}
w, h = f.Size()
c.defaultRenderTarget = &Image{
framebuffer: f,
texture: nil,
width: w,
height: h,
}
c.defaultRenderTarget.Clear()
c.screen = screen
c.screenScale = screenScale

View File

@ -384,3 +384,20 @@ func NewImageFromImage(img image.Image, filter Filter) (*Image, error) {
}
return eimg, nil
}
func newImageWithZeroFramebuffer(width, height int) (*Image, error) {
imageM.Lock()
defer imageM.Unlock()
f, err := graphics.NewZeroFramebuffer(glContext, width, height)
if err != nil {
return nil, err
}
img := &Image{
framebuffer: f,
texture: nil,
width: width,
height: height,
}
runtime.SetFinalizer(img, (*Image).Dispose)
return img, nil
}