Remove EbitenWindow.glContext_

This commit is contained in:
Hajime Hoshi 2013-11-24 02:00:09 +09:00
parent 0a16107cd6
commit 3c979825db
3 changed files with 25 additions and 35 deletions

View File

@ -6,9 +6,7 @@
#import "ebiten_content_view.h" #import "ebiten_content_view.h"
@implementation EbitenWindow { @implementation EbitenWindow
NSOpenGLContext* glContext_;
}
- (id)initWithSize:(NSSize)size { - (id)initWithSize:(NSSize)size {
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask | NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
@ -41,23 +39,6 @@
return self; return self;
} }
- (void)initializeGLContext {
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 32,
0,
};
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
initWithAttributes:attributes];
self->glContext_ = [[NSOpenGLContext alloc] initWithFormat:format
shareContext:nil];
[self->glContext_ makeCurrentContext];
[format release];
}
- (BOOL)windowShouldClose:(id)sender { - (BOOL)windowShouldClose:(id)sender {
if ([sender isDocumentEdited]) { if ([sender isDocumentEdited]) {
// TODO: add the application's name // TODO: add the application's name
@ -86,15 +67,6 @@
} }
} }
- (void)beginDrawing {
[self->glContext_ setView:[self contentView]];
glClear(GL_COLOR_BUFFER_BIT);
}
- (void)endDrawing {
[self->glContext_ flushBuffer];
}
- (BOOL)canBecomeMainWindow { - (BOOL)canBecomeMainWindow {
return YES; return YES;
} }

View File

@ -8,9 +8,6 @@
@interface EbitenWindow : NSWindow<NSWindowDelegate> @interface EbitenWindow : NSWindow<NSWindowDelegate>
- (id)initWithSize:(NSSize)size; - (id)initWithSize:(NSSize)size;
- (void)initializeGLContext;
- (void)beginDrawing;
- (void)endDrawing;
@end @end

View File

@ -1,10 +1,13 @@
// -*- objc -*- // -*- objc -*-
#include <stdlib.h> #include <stdlib.h>
#include <OpenGL/gl.h>
#import "ebiten_controller.h" #import "ebiten_controller.h"
#import "ebiten_window.h" #import "ebiten_window.h"
static NSOpenGLContext* glContext_;
void StartApplication() { void StartApplication() {
EbitenController* controller = [[EbitenController alloc] init]; EbitenController* controller = [[EbitenController alloc] init];
NSApplication* app = [NSApplication sharedApplication]; NSApplication* app = [NSApplication sharedApplication];
@ -14,13 +17,30 @@ void StartApplication() {
[app activateIgnoringOtherApps:YES]; [app activateIgnoringOtherApps:YES];
} }
void* CreateGLContext() {
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 32,
0,
};
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
initWithAttributes:attributes];
NSOpenGLContext* glContext = [[NSOpenGLContext alloc] initWithFormat:format
shareContext:nil];
[format release];
return glContext;
}
void* CreateWindow(size_t width, size_t height, const char* title) { void* CreateWindow(size_t width, size_t height, const char* title) {
NSSize size = NSMakeSize(width, height); NSSize size = NSMakeSize(width, height);
EbitenWindow* window = [[EbitenWindow alloc] EbitenWindow* window = [[EbitenWindow alloc]
initWithSize:size]; initWithSize:size];
[window setTitle: [[NSString alloc] initWithUTF8String:title]]; [window setTitle: [[NSString alloc] initWithUTF8String:title]];
[window makeKeyAndOrderFront:nil]; [window makeKeyAndOrderFront:nil];
[window initializeGLContext]; glContext_ = CreateGLContext();
[glContext_ makeCurrentContext];
return window; return window;
} }
@ -38,9 +58,10 @@ void PollEvents(void) {
} }
void BeginDrawing(void* window) { void BeginDrawing(void* window) {
[(EbitenWindow*)window beginDrawing]; [glContext_ setView:[(EbitenWindow*)window contentView]];
glClear(GL_COLOR_BUFFER_BIT);
} }
void EndDrawing(void* window) { void EndDrawing(void* window) {
[(EbitenWindow*)window endDrawing]; [glContext_ flushBuffer];
} }