File: TestSDKExternalWindowCOCOA.mm

package info (click to toggle)
f3d 3.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,668 kB
  • sloc: cpp: 99,109; python: 811; sh: 342; xml: 238; java: 101; javascript: 95; makefile: 25
file content (63 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "engine.h"

#include "TestSDKHelpers.h"

#import <Cocoa/Cocoa.h>
#import <OpenGL/gl3.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (strong) NSWindow *window;
@property (strong) NSOpenGLContext *openGLContext;
@property std::string dataPath;
@property std::string outPath;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  NSRect frame = NSMakeRect(100, 100, 300, 300);
  self.window = [[NSWindow alloc] initWithContentRect:frame
                                              styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable)
                                                backing:NSBackingStoreBuffered
                                                  defer:NO];
  [self.window setTitle:@"F3D COCOA Window Test"];
  
  NSOpenGLPixelFormatAttribute attrs[] = {
      NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core,
      NSOpenGLPFAColorSize, 24,
      NSOpenGLPFAAlphaSize, 8,
      NSOpenGLPFADepthSize, 32,
      0
  };
  
  NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
  self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
  [self.openGLContext makeCurrentContext];

  f3d::engine engine = f3d::engine::createExternal(nullptr);
  engine.getWindow().setSize(300, 300);
  engine.getScene().add(_dataPath + "/data/cow.vtp");

  if (!TestSDKHelpers::RenderTest(engine.getWindow(), _dataPath + "baselines/", _outPath, "TestSDKExternalWindowCOCOA"))
  {
    exit(1);
  }

  [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.1];
}

@end

int TestSDKExternalWindowCOCOA(int argc, char* argv[])
{
  @autoreleasepool {
    NSApplication *app = [NSApplication sharedApplication];
    AppDelegate *delegate = [[AppDelegate alloc] init];
    delegate.dataPath = argv[1];
    delegate.outPath = argv[2];
    app.delegate = delegate;

    [app run];
  }
  return 0;
}