mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
Refactoring
This commit is contained in:
parent
11a9b77be3
commit
ca4275d347
@ -9,10 +9,16 @@ type SharedContext struct {
|
|||||||
ids *ids
|
ids *ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSharedContext() *SharedContext {
|
var sharedContext *SharedContext = nil
|
||||||
return &SharedContext{
|
|
||||||
|
func Initialize() *SharedContext {
|
||||||
|
if sharedContext != nil {
|
||||||
|
panic("OpenGL is already initialized")
|
||||||
|
}
|
||||||
|
sharedContext = &SharedContext{
|
||||||
ids: newIds(),
|
ids: newIds(),
|
||||||
}
|
}
|
||||||
|
return sharedContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SharedContext) CreateContext(screenWidth, screenHeight, screenScale int) *Context {
|
func (s *SharedContext) CreateContext(screenWidth, screenHeight, screenScale int) *Context {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
type sharedContext struct {
|
type sharedContext struct {
|
||||||
inited chan struct{}
|
inited chan struct{}
|
||||||
graphicsSharedContext *opengl.SharedContext
|
sharedContext *opengl.SharedContext
|
||||||
events chan interface{}
|
events chan interface{}
|
||||||
funcs chan func()
|
funcs chan func()
|
||||||
funcsDone chan struct{}
|
funcsDone chan struct{}
|
||||||
@ -36,7 +36,7 @@ func (t *sharedContext) run() {
|
|||||||
var sharedGLContext *C.NSOpenGLContext
|
var sharedGLContext *C.NSOpenGLContext
|
||||||
go func() {
|
go func() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
t.graphicsSharedContext = opengl.NewSharedContext()
|
t.sharedContext = opengl.Initialize()
|
||||||
sharedGLContext = C.CreateGLContext(nil)
|
sharedGLContext = C.CreateGLContext(nil)
|
||||||
close(t.inited)
|
close(t.inited)
|
||||||
t.loop(sharedGLContext)
|
t.loop(sharedGLContext)
|
||||||
@ -44,7 +44,7 @@ func (t *sharedContext) run() {
|
|||||||
<-t.inited
|
<-t.inited
|
||||||
go func() {
|
go func() {
|
||||||
for w := range t.gameWindows {
|
for w := range t.gameWindows {
|
||||||
w.run(t.graphicsSharedContext, sharedGLContext)
|
w.run(t.sharedContext, sharedGLContext)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func (t *sharedContext) CreateTexture(tag interface{}, img image.Image, filter g
|
|||||||
var id graphics.TextureId
|
var id graphics.TextureId
|
||||||
var err error
|
var err error
|
||||||
t.useGLContext(func() {
|
t.useGLContext(func() {
|
||||||
id, err = t.graphicsSharedContext.CreateTexture(img, filter)
|
id, err = t.sharedContext.CreateTexture(img, filter)
|
||||||
})
|
})
|
||||||
if t.events == nil {
|
if t.events == nil {
|
||||||
return
|
return
|
||||||
@ -107,7 +107,7 @@ func (t *sharedContext) CreateRenderTarget(tag interface{}, width, height int) {
|
|||||||
var id graphics.RenderTargetId
|
var id graphics.RenderTargetId
|
||||||
var err error
|
var err error
|
||||||
t.useGLContext(func() {
|
t.useGLContext(func() {
|
||||||
id, err = t.graphicsSharedContext.CreateRenderTarget(width, height)
|
id, err = t.sharedContext.CreateRenderTarget(width, height)
|
||||||
})
|
})
|
||||||
if t.events == nil {
|
if t.events == nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user