mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-27 04:08:53 +01:00
graphics: Refactoring
This commit is contained in:
parent
302f5a5437
commit
11e67d0eed
7
image.go
7
image.go
@ -20,7 +20,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -195,11 +194,7 @@ type DrawImageOptions struct {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func NewImage(width, height int, filter Filter) (*Image, error) {
|
func NewImage(width, height int, filter Filter) (*Image, error) {
|
||||||
i, err := graphics.NewImage(width, height, glFilter(filter))
|
img, err := newImageImpl(width, height, filter)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
img, err := newImageImpl(i, filter)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
27
imageimpl.go
27
imageimpl.go
@ -41,12 +41,15 @@ type imageImpl struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImageImpl(image *graphics.Image, filter Filter) (*imageImpl, error) {
|
func newImageImpl(width, height int, filter Filter) (*imageImpl, error) {
|
||||||
w, h := image.Size()
|
img, err := graphics.NewImage(width, height, glFilter(filter))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
image: image,
|
image: img,
|
||||||
width: w,
|
width: width,
|
||||||
height: h,
|
height: height,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||||
@ -86,16 +89,18 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
||||||
i, err := graphics.NewScreenFramebufferImage(width, height)
|
img, err := graphics.NewScreenFramebufferImage(width, height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
img, err := newImageImpl(i, FilterNearest)
|
i := &imageImpl{
|
||||||
if err != nil {
|
image: img,
|
||||||
return nil, err
|
width: width,
|
||||||
|
height: height,
|
||||||
|
screen: true,
|
||||||
}
|
}
|
||||||
img.screen = true
|
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||||
return img, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) Fill(clr color.Color) error {
|
func (i *imageImpl) Fill(clr color.Color) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user