diff --git a/example/blocks/game.go b/example/blocks/game.go index 1ff719396..bdded8273 100644 --- a/example/blocks/game.go +++ b/example/blocks/game.go @@ -3,6 +3,7 @@ package blocks import ( "github.com/hajimehoshi/go-ebiten/graphics" "github.com/hajimehoshi/go-ebiten/ui" + _ "image/png" ) type Size struct { diff --git a/example/blocks/textures.go b/example/blocks/textures.go index d00eb35b2..9d06bede3 100644 --- a/example/blocks/textures.go +++ b/example/blocks/textures.go @@ -3,7 +3,6 @@ package blocks import ( "github.com/hajimehoshi/go-ebiten/graphics" "image" - _ "image/png" "os" "sync" ) @@ -64,36 +63,30 @@ func (t *Textures) loop() { if err != nil { panic(err) } - ch := t.textureFactory.CreateTexture( + id, err := t.textureFactory.CreateTexture( img, graphics.FilterNearest) - go func() { - e := <-ch - if e.Error != nil { - panic(e.Error) - } - t.Lock() - defer t.Unlock() - t.textures[name] = e.Id - }() + if err != nil { + panic(err) + } + t.Lock() + defer t.Unlock() + t.textures[name] = id }() case s := <-t.renderTargetSizes: name := s.name size := s.size go func() { - ch := t.textureFactory.CreateRenderTarget( + id, err := t.textureFactory.CreateRenderTarget( size.Width, size.Height, graphics.FilterNearest) - go func() { - e := <-ch - if e.Error != nil { - panic(e.Error) - } - t.Lock() - defer t.Unlock() - t.renderTargets[name] = e.Id - }() + if err != nil { + panic(err) + } + t.Lock() + defer t.Unlock() + t.renderTargets[name] = id }() } } diff --git a/graphics/texture_factory.go b/graphics/texture_factory.go index bce414c64..40060429e 100644 --- a/graphics/texture_factory.go +++ b/graphics/texture_factory.go @@ -17,17 +17,7 @@ type TextureId int // all alpha of a render target is maximum. type RenderTargetId int -type TextureCreatedEvent struct { - Id TextureId - Error error -} - -type RenderTargetCreatedEvent struct { - Id RenderTargetId - Error error -} - type TextureFactory interface { - CreateRenderTarget(width, height int, filter Filter) <-chan RenderTargetCreatedEvent - CreateTexture(img image.Image, filter Filter) <-chan TextureCreatedEvent + CreateRenderTarget(width, height int, filter Filter) (RenderTargetId, error) + CreateTexture(img image.Image, filter Filter) (TextureId, error) } diff --git a/ui/cocoa/shared_context.go b/ui/cocoa/shared_context.go index 485fe6548..a56b0e407 100644 --- a/ui/cocoa/shared_context.go +++ b/ui/cocoa/shared_context.go @@ -73,40 +73,24 @@ func (t *sharedContext) createGameWindow(width, height, scale int, title string) func (t *sharedContext) CreateTexture( img image.Image, - filter graphics.Filter) <-chan graphics.TextureCreatedEvent { - ch := make(chan graphics.TextureCreatedEvent) - go func() { - <-t.inited - var id graphics.TextureId - var err error - t.useGLContext(func() { - id, err = opengl.CreateTexture(img, filter) - }) - ch <- graphics.TextureCreatedEvent{ - Id: id, - Error: err, - } - close(ch) - }() - return ch + filter graphics.Filter) (graphics.TextureId, error) { + <-t.inited + var id graphics.TextureId + var err error + t.useGLContext(func() { + id, err = opengl.CreateTexture(img, filter) + }) + return id, err } func (t *sharedContext) CreateRenderTarget( width, height int, - filter graphics.Filter) <-chan graphics.RenderTargetCreatedEvent { - ch := make(chan graphics.RenderTargetCreatedEvent) - go func() { - <-t.inited - var id graphics.RenderTargetId - var err error - t.useGLContext(func() { - id, err = opengl.CreateRenderTarget(width, height, filter) - }) - ch <- graphics.RenderTargetCreatedEvent{ - Id: id, - Error: err, - } - close(ch) - }() - return ch + filter graphics.Filter) (graphics.RenderTargetId, error) { + <-t.inited + var id graphics.RenderTargetId + var err error + t.useGLContext(func() { + id, err = opengl.CreateRenderTarget(width, height, filter) + }) + return id, err }