Add CreateGLContext

This commit is contained in:
Hajime Hoshi 2013-11-25 02:12:07 +09:00
parent 638da2ed2c
commit 0628d1342f
2 changed files with 21 additions and 12 deletions

View File

@ -7,7 +7,9 @@ package cocoa
// #include "input.h"
//
// void StartApplication(void);
// void* CreateWindow(size_t width, size_t height, const char* title);
// void* CreateGLContext(void* sharedGLContext);
// void SetCurrentGLContext(void* glContext);
// void* CreateWindow(size_t width, size_t height, const char* title, void* glContext);
// void PollEvents(void);
// void BeginDrawing(void* window);
// void EndDrawing(void* window);
@ -77,14 +79,17 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
C.StartApplication()
ui.window = C.CreateWindow(C.size_t(ui.screenWidth * ui.screenScale),
C.size_t(ui.screenHeight * ui.screenScale),
cTitle)
context := C.CreateGLContext(unsafe.Pointer(nil))
C.SetCurrentGLContext(context);
ui.graphicsDevice = opengl.NewDevice(
ui.screenWidth,
ui.screenHeight,
ui.screenScale)
ui.window = C.CreateWindow(C.size_t(ui.screenWidth * ui.screenScale),
C.size_t(ui.screenHeight * ui.screenScale),
cTitle,
context)
currentUI = ui
return ui
}

View File

@ -15,7 +15,7 @@ void StartApplication() {
[app activateIgnoringOtherApps:YES];
}
void* CreateGLContext() {
void* CreateGLContext(void* sharedGLContext) {
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
@ -25,24 +25,27 @@ void* CreateGLContext() {
};
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
initWithAttributes:attributes];
NSOpenGLContext* glContext = [[NSOpenGLContext alloc] initWithFormat:format
shareContext:nil];
NSOpenGLContext* glContext =
[[NSOpenGLContext alloc] initWithFormat:format
shareContext:(NSOpenGLContext*)sharedGLContext];
[format release];
return glContext;
}
void* CreateWindow(size_t width, size_t height, const char* title) {
NSOpenGLContext* glContext = CreateGLContext();
[glContext makeCurrentContext];
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) {
NSSize size = NSMakeSize(width, height);
EbitenWindow* window = [[EbitenWindow alloc]
initWithSize:size
glContext:glContext];
glContext:(NSOpenGLContext*)glContext];
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
[window makeKeyAndOrderFront:nil];
[glContext setView:[window contentView]];
[(NSOpenGLContext*)glContext setView:[window contentView]];
return window;
}
@ -61,6 +64,7 @@ void PollEvents(void) {
}
void BeginDrawing(void* window) {
[[(EbitenWindow*)window glContext] makeCurrentContext];
glClear(GL_COLOR_BUFFER_BIT);
}