mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
Use the shared context
This commit is contained in:
parent
0628d1342f
commit
8ff19c031d
@ -36,9 +36,6 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
|||||||
ids: newIds(),
|
ids: newIds(),
|
||||||
}
|
}
|
||||||
|
|
||||||
C.glEnable(C.GL_TEXTURE_2D)
|
|
||||||
C.glEnable(C.GL_BLEND)
|
|
||||||
|
|
||||||
// The main framebuffer should be created sooner than any other
|
// The main framebuffer should be created sooner than any other
|
||||||
// framebuffers!
|
// framebuffers!
|
||||||
mainFramebuffer := C.GLint(0)
|
mainFramebuffer := C.GLint(0)
|
||||||
@ -59,6 +56,8 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
|||||||
panic("initializing the offscreen failed: " + err.Error())
|
panic("initializing the offscreen failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.Init()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +101,11 @@ func (context *Context) DrawTextureParts(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (context *Context) Init() {
|
||||||
|
C.glEnable(C.GL_TEXTURE_2D)
|
||||||
|
C.glEnable(C.GL_BLEND)
|
||||||
|
}
|
||||||
|
|
||||||
func (context *Context) ResetOffscreen() {
|
func (context *Context) ResetOffscreen() {
|
||||||
context.SetOffscreen(context.screenId)
|
context.SetOffscreen(context.screenId)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
|||||||
|
|
||||||
func (device *Device) Update(draw func(graphics.Context)) {
|
func (device *Device) Update(draw func(graphics.Context)) {
|
||||||
context := device.context
|
context := device.context
|
||||||
|
context.Init()
|
||||||
context.ResetOffscreen()
|
context.ResetOffscreen()
|
||||||
context.Clear()
|
context.Clear()
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ package cocoa
|
|||||||
// void StartApplication(void);
|
// void StartApplication(void);
|
||||||
// void* CreateGLContext(void* sharedGLContext);
|
// void* CreateGLContext(void* sharedGLContext);
|
||||||
// void SetCurrentGLContext(void* glContext);
|
// void SetCurrentGLContext(void* glContext);
|
||||||
// void* CreateWindow(size_t width, size_t height, const char* title, void* glContext);
|
// void* CreateWindow(size_t width, size_t height, const char* title, void* sharedGLContext);
|
||||||
// void PollEvents(void);
|
// void PollEvents(void);
|
||||||
// void BeginDrawing(void* window);
|
// void BeginDrawing(void* window);
|
||||||
// void EndDrawing(void* window);
|
// void EndDrawing(void* window);
|
||||||
|
@ -36,13 +36,16 @@ void SetCurrentGLContext(void* glContext) {
|
|||||||
[(NSOpenGLContext*)glContext makeCurrentContext];
|
[(NSOpenGLContext*)glContext makeCurrentContext];
|
||||||
}
|
}
|
||||||
|
|
||||||
// This takes the ownership of glContext.
|
void* CreateWindow(size_t width, size_t height, const char* title, void* sharedGLContext) {
|
||||||
void* CreateWindow(size_t width, size_t height, const char* title, void* glContext) {
|
NSOpenGLContext* glContext = CreateGLContext(sharedGLContext);
|
||||||
|
[glContext makeCurrentContext];
|
||||||
|
|
||||||
NSSize size = NSMakeSize(width, height);
|
NSSize size = NSMakeSize(width, height);
|
||||||
EbitenWindow* window = [[EbitenWindow alloc]
|
EbitenWindow* window = [[EbitenWindow alloc]
|
||||||
initWithSize:size
|
initWithSize:size
|
||||||
glContext:(NSOpenGLContext*)glContext];
|
glContext:glContext];
|
||||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
[window setTitle: [[NSString alloc]
|
||||||
|
initWithUTF8String:title]];
|
||||||
[window makeKeyAndOrderFront:nil];
|
[window makeKeyAndOrderFront:nil];
|
||||||
|
|
||||||
[(NSOpenGLContext*)glContext setView:[window contentView]];
|
[(NSOpenGLContext*)glContext setView:[window contentView]];
|
||||||
|
Loading…
Reference in New Issue
Block a user