|
|
@@ -18,42 +18,75 @@
|
|
|
namespace env { namespace detail {
|
|
|
extern void resize_screen(math::vec2i const&);
|
|
|
}}
|
|
|
+static std::shared_ptr<graphics::direct_renderer> renderer;
|
|
|
+static std::shared_ptr<engine::game_dispatch> game;
|
|
|
|
|
|
@implementation GameView {
|
|
|
- BOOL initialized;
|
|
|
- std::shared_ptr<graphics::direct_renderer> renderer;
|
|
|
- std::shared_ptr<engine::game_dispatch> game;
|
|
|
};
|
|
|
|
|
|
+//-(id)initWithCoder:(NSCoder *)aDecoder {
|
|
|
+// if (!(self = [super initWithCoder:aDecoder])) {
|
|
|
+// return nil;
|
|
|
+// }
|
|
|
+//
|
|
|
+// NSOpenGLPixelFormatAttribute attr[] = {
|
|
|
+// NSOpenGLPFADoubleBuffer,
|
|
|
+// NSOpenGLPFAOpenGLProfile,
|
|
|
+// NSOpenGLProfileVersion3_2Core,
|
|
|
+// 0
|
|
|
+// };
|
|
|
+//
|
|
|
+// // create pixel format
|
|
|
+// NSOpenGLPixelFormat *nsglFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
|
|
+//
|
|
|
+// NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:nsglFormat
|
|
|
+// shareContext:nil];
|
|
|
+// [self setOpenGLContext:context];
|
|
|
+// [self setPixelFormat:nsglFormat];
|
|
|
+// [[self openGLContext] makeCurrentContext];
|
|
|
+//
|
|
|
+// using namespace graphics;
|
|
|
+// renderer = std::make_shared<direct_renderer>(driver::openGL);
|
|
|
+// game = std::make_shared<engine::game_dispatch>(renderer);
|
|
|
+//
|
|
|
+// renderer->clear();
|
|
|
+//
|
|
|
+// return self;
|
|
|
+//}
|
|
|
+
|
|
|
- (id)initWithFrame:(NSRect)aRect {
|
|
|
NSOpenGLPixelFormatAttribute attr[] = {
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
+ NSOpenGLPFAOpenGLProfile,
|
|
|
+ NSOpenGLProfileVersion3_2Core,
|
|
|
0
|
|
|
};
|
|
|
|
|
|
// create pixel format
|
|
|
NSOpenGLPixelFormat *nsglFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
|
|
-
|
|
|
+
|
|
|
// create the context...
|
|
|
if (!(self = [super initWithFrame:aRect pixelFormat:nsglFormat])) {
|
|
|
return nil;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// make the context current
|
|
|
+ NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:nsglFormat
|
|
|
+ shareContext:nil];
|
|
|
+ [self setOpenGLContext:context];
|
|
|
[[self openGLContext] makeCurrentContext];
|
|
|
|
|
|
// rest of your init method ...
|
|
|
- using namespace graphics;
|
|
|
- renderer = std::make_shared<direct_renderer>(driver::openGL);
|
|
|
- game = std::make_shared<engine::game_dispatch>(renderer);
|
|
|
|
|
|
- renderer->clear();
|
|
|
-
|
|
|
- initialized = YES;
|
|
|
return self;
|
|
|
}
|
|
|
|
|
|
- (void)prepareOpenGL {
|
|
|
+ using graphics::direct_renderer;
|
|
|
+ using graphics::driver;
|
|
|
+ renderer = std::make_shared<direct_renderer>(driver::openGL);
|
|
|
+ game = std::make_shared<engine::game_dispatch>(renderer);
|
|
|
+ renderer->clear();
|
|
|
// enable vertical sychronization to refresh rate
|
|
|
const GLint vals = 0x01;
|
|
|
[[self openGLContext] setValues:&vals forParameter:NSOpenGLCPSwapInterval];
|
|
|
@@ -64,13 +97,12 @@ namespace env { namespace detail {
|
|
|
}
|
|
|
|
|
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
|
- if (!initialized) return;
|
|
|
// glClear(GL_COLOR_BUFFER_BIT);
|
|
|
// glLoadIdentity();
|
|
|
|
|
|
env::detail::resize_screen({{(int)dirtyRect.size.width,
|
|
|
(int)dirtyRect.size.height}});
|
|
|
- if (initialized) game->render();
|
|
|
+ if (game) game->render();
|
|
|
// glFlush();
|
|
|
// the correct way to do double buffering on Mac is this:
|
|
|
[[self openGLContext] flushBuffer];
|