|
|
@@ -21,38 +21,7 @@ namespace env { namespace detail {
|
|
|
static std::shared_ptr<graphics::direct_renderer> renderer;
|
|
|
static std::shared_ptr<engine::game_dispatch> game;
|
|
|
|
|
|
-@implementation GameView {
|
|
|
-};
|
|
|
-
|
|
|
-//-(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;
|
|
|
-//}
|
|
|
+@implementation GameView
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)aRect {
|
|
|
NSOpenGLPixelFormatAttribute attr[] = {
|
|
|
@@ -74,10 +43,9 @@ static std::shared_ptr<engine::game_dispatch> game;
|
|
|
NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:nsglFormat
|
|
|
shareContext:nil];
|
|
|
[self setOpenGLContext:context];
|
|
|
+ [self setPixelFormat:nsglFormat];
|
|
|
[[self openGLContext] makeCurrentContext];
|
|
|
|
|
|
- // rest of your init method ...
|
|
|
-
|
|
|
return self;
|
|
|
}
|
|
|
|
|
|
@@ -86,7 +54,9 @@ static std::shared_ptr<engine::game_dispatch> game;
|
|
|
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];
|
|
|
@@ -102,7 +72,8 @@ static std::shared_ptr<engine::game_dispatch> game;
|
|
|
|
|
|
env::detail::resize_screen({{(int)dirtyRect.size.width,
|
|
|
(int)dirtyRect.size.height}});
|
|
|
- if (game) game->render();
|
|
|
+ renderer->clear();
|
|
|
+ game->render();
|
|
|
// glFlush();
|
|
|
// the correct way to do double buffering on Mac is this:
|
|
|
[[self openGLContext] flushBuffer];
|