mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57: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(),
|
||||
}
|
||||
|
||||
C.glEnable(C.GL_TEXTURE_2D)
|
||||
C.glEnable(C.GL_BLEND)
|
||||
|
||||
// The main framebuffer should be created sooner than any other
|
||||
// framebuffers!
|
||||
mainFramebuffer := C.GLint(0)
|
||||
@ -59,6 +56,8 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
||||
panic("initializing the offscreen failed: " + err.Error())
|
||||
}
|
||||
|
||||
context.Init()
|
||||
|
||||
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() {
|
||||
context.SetOffscreen(context.screenId)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
||||
|
||||
func (device *Device) Update(draw func(graphics.Context)) {
|
||||
context := device.context
|
||||
context.Init()
|
||||
context.ResetOffscreen()
|
||||
context.Clear()
|
||||
|
||||
|
@ -9,7 +9,7 @@ package cocoa
|
||||
// void StartApplication(void);
|
||||
// void* CreateGLContext(void* sharedGLContext);
|
||||
// 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 BeginDrawing(void* window);
|
||||
// void EndDrawing(void* window);
|
||||
|
@ -36,13 +36,16 @@ void SetCurrentGLContext(void* glContext) {
|
||||
[(NSOpenGLContext*)glContext makeCurrentContext];
|
||||
}
|
||||
|
||||
// This takes the ownership of 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) {
|
||||
NSOpenGLContext* glContext = CreateGLContext(sharedGLContext);
|
||||
[glContext makeCurrentContext];
|
||||
|
||||
NSSize size = NSMakeSize(width, height);
|
||||
EbitenWindow* window = [[EbitenWindow alloc]
|
||||
initWithSize:size
|
||||
glContext:(NSOpenGLContext*)glContext];
|
||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
||||
glContext:glContext];
|
||||
[window setTitle: [[NSString alloc]
|
||||
initWithUTF8String:title]];
|
||||
[window makeKeyAndOrderFront:nil];
|
||||
|
||||
[(NSOpenGLContext*)glContext setView:[window contentView]];
|
||||
|
Loading…
Reference in New Issue
Block a user