Use the shared context

This commit is contained in:
Hajime Hoshi 2013-11-25 22:27:59 +09:00
parent 0628d1342f
commit 8ff19c031d
4 changed files with 16 additions and 8 deletions

View File

@ -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)
}

View File

@ -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()

View File

@ -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);

View File

@ -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]];