Example #1
0
 public MyOpenGLView(NSRect frameRect, NSOpenGLContext context)
     : base(MyOpenGLViewClass.SendMessage<IntPtr>("alloc"))
 {
     this.NativePointer = this.SendMessage<IntPtr>("initWithFrame:shareContext:", frameRect, context);
 }
Example #2
0
        public Id InitWithFrameShareContext(NSRect frameRect, NSOpenGLContext context)
        {
            Object[] attribs = new Object[] { NSOpenGLPixelFormatAttribute.NSOpenGLPFAAccelerated, NSOpenGLPixelFormatAttribute.NSOpenGLPFANoRecovery, NSOpenGLPixelFormatAttribute.NSOpenGLPFADoubleBuffer, NSOpenGLPixelFormatAttribute.NSOpenGLPFAColorSize, 24, NSOpenGLPixelFormatAttribute.NSOpenGLPFADepthSize, 16, 0 };

            this.pixelFormat = new NSOpenGLPixelFormat (attribs);

            // NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead
            this.openGLContext = new NSOpenGLContext (this.pixelFormat, context);

            this.SendMessageSuper<IntPtr> (MyOpenGLViewClass, "initWithFrame:", frameRect);

            this.openGLContext.MakeCurrentContext ();

            // Synchronize buffer swaps with vertical refresh rate
            this.OpenGLContext.SetValuesForParameter (new[] { 1 }, NSOpenGLContextParameter.NSOpenGLCPSwapInterval);

            this.SetupDisplayLink ();

            // Look for changes in view size
            // Note, -reshape will not be called automatically on size changes because NSView does not export it to override
            NSNotificationCenter.DefaultCenter.AddObserverSelectorNameObject (this, ObjectiveCRuntime.Selector ("reshape"), NSView.NSViewGlobalFrameDidChangeNotification, this);

            return this;
        }