mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
graphics: Refactoring: Now all Image objects are generated from New* funcs
This commit is contained in:
parent
9f2b53d24c
commit
da0196911d
@ -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
|
||||
|
17
image.go
17
image.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user