Describes a Carbon window.
Inheritance: IWindowInfo
Exemple #1
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
            : base(DesktopBackend.OpenGL)//temp
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow  = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
            {
                shareContextRef = ((AglContext)shareContext).Handle.Handle;
            }
            if (shareContext is GraphicsContext)
            {
                ContextHandle shareHandle = shareContext != null ?
                                            (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

                shareContextRef = shareHandle.Handle;
            }

            if (shareContextRef == IntPtr.Zero)
            {
                Debug.Print("No context sharing will take place.");
            }

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");
            Debug.Indent();

            IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);

            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef, true, false);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);

            Debug.Unindent();
            Debug.Print("Created window.");

            mWindows.Add(windowRef, new WeakReference(this));

            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);

            mTitlebarHeight = titleSize.Height;

            Debug.Print("Titlebar size: {0}", titleSize);

            ConnectEvents();

            System.Diagnostics.Debug.Print("Attached window events.");
        }
Exemple #3
0
        internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height)
        {
            CarbonGLNative wind = GetCarbonWindow(info);

            Debug.Print("Switching to full screen {0}x{1} on context {2}",
                        wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle);

            CG.DisplayCapture(GetQuartzDevice(info));
            Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0);
            MakeCurrent(info);

            width  = wind.TargetDisplayDevice.Width;
            height = wind.TargetDisplayDevice.Height;

            // This is a weird hack to workaround a bug where the first time a context
            // is made fullscreen, we just end up with a blank screen.  So we undo it as fullscreen
            // and redo it as fullscreen.
            if (firstFullScreen == false)
            {
                firstFullScreen = true;
                UnsetFullScreen(info);
                SetFullScreen(info, out width, out height);
            }

            mIsFullscreen = true;
        }
Exemple #4
0
        private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowRef = carbonWindow.WindowRef;

            if (!CarbonGLNative.WindowRefMap.ContainsKey(windowRef))
            {
                return(IntPtr.Zero);
            }
            WeakReference weakReference = CarbonGLNative.WindowRefMap[windowRef];

            if (!weakReference.IsAlive)
            {
                return(IntPtr.Zero);
            }
            CarbonGLNative carbonGlNative = weakReference.Target as CarbonGLNative;

            if (carbonGlNative == null)
            {
                return(IntPtr.Zero);
            }
            else
            {
                return(QuartzDisplayDeviceDriver.HandleTo(carbonGlNative.TargetDisplayDevice));
            }
        }
Exemple #5
0
        void SetBufferRect(CarbonWindowInfo carbonWindow)
        {
            if (carbonWindow.IsControl == false)
            {
                return;
            }
            System.Windows.Forms.Control ctrl = Control.FromHandle(carbonWindow.WindowRef);
            if (ctrl.TopLevelControl == null)
            {
                return;
            }
            Rect rect = API.GetControlBounds(carbonWindow.WindowRef);

            System.Windows.Forms.Form frm = (System.Windows.Forms.Form)ctrl.TopLevelControl;
            System.Drawing.Point      loc =
                frm.PointToClient(ctrl.PointToScreen(System.Drawing.Point.Empty));
            rect.X = (short)loc.X;
            rect.Y = (short)loc.Y;
            Debug.Print("Setting buffer_rect for control.");
            Debug.Print("MacOS Coordinate Rect:   {0}", rect);
            rect.Y = (short)(ctrl.TopLevelControl.ClientSize.Height - rect.Y - rect.Height);
            Debug.Print("  AGL Coordinate Rect:   {0}", rect);
            int[] glrect = new int[4];
            glrect[0] = rect.X;
            glrect[1] = rect.Y;
            glrect[2] = rect.Width;
            glrect[3] = rect.Height;
            Agl.aglSetInteger(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
            MyAGLReportError("aglSetInteger");
            Agl.aglEnable(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT);
            MyAGLReportError("aglEnable");
        }
Exemple #6
0
 private void SetBufferRect(CarbonWindowInfo carbonWindow)
 {
     if (carbonWindow.IsControl)
     {
         throw new NotImplementedException();
     }
 }
Exemple #7
0
        public override void Update(IWindowInfo window)
        {
            CarbonWindowInfo carbonWindow1 = (CarbonWindowInfo)window;

            if (carbonWindow1.GoFullScreenHack)
            {
                carbonWindow1.GoFullScreenHack = false;
                CarbonGLNative carbonWindow2 = this.GetCarbonWindow(carbonWindow1);
                if (carbonWindow2 == null)
                {
                    return;
                }
                carbonWindow2.SetFullscreen(this);
            }
            else
            {
                if (carbonWindow1.GoWindowedHack)
                {
                    carbonWindow1.GoWindowedHack = false;
                    CarbonGLNative carbonWindow2 = this.GetCarbonWindow(carbonWindow1);
                    if (carbonWindow2 != null)
                    {
                        carbonWindow2.UnsetFullscreen(this);
                    }
                }
                if (this.mIsFullscreen)
                {
                    return;
                }
                this.SetDrawable(carbonWindow1);
                this.SetBufferRect(carbonWindow1);
                int num = (int)Agl.aglUpdateContext(this.Handle.Handle);
            }
        }
Exemple #8
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
                shareContextRef = ((AglContext)shareContext).Handle.Handle;
			if (shareContext is GraphicsContext)
			{
				ContextHandle shareHandle = shareContext != null ?
					(shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

				shareContextRef = shareHandle.Handle;
			}

			if (shareContextRef == IntPtr.Zero)
			{
				Debug.Print("No context sharing will take place.");
			}

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
Exemple #9
0
        private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowRef = carbonWindow.WindowRef;

            if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false)
            {
                return(IntPtr.Zero);
            }

            WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef];

            if (nativeRef.IsAlive == false)
            {
                return(IntPtr.Zero);
            }

            CarbonGLNative window = nativeRef.Target as CarbonGLNative;

            if (window == null)
            {
                return(IntPtr.Zero);
            }

            return(QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice));
        }
Exemple #10
0
        protected virtual void Dispose(bool disposing)
        {
            if (mIsDisposed)
            {
                return;
            }

            Debug.Print("Disposing of CarbonGLNative window.");

            CursorVisible = true;
            API.DisposeWindow(window.Handle);
            mIsDisposed = true;
            mExists     = false;

            CG.SetLocalEventsSuppressionInterval(0.25);

            if (disposing)
            {
                mWindows.Remove(window.Handle);

                window.Dispose();
                window = null;
            }

            DisposeUPP();

            Disposed(this, EventArgs.Empty);
        }
Exemple #11
0
        void SetDrawable(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);

            Agl.aglSetDrawable(Handle.Handle, windowPort);

            MyAGLReportError("aglSetDrawable");
        }
        public AglContext(GraphicsMode mode, IWindowInfo window)
        {
            Debug.Print("Window info: {0}", window);

            Mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            CreateContext(mode, carbonWindow, true);
        }
Exemple #13
0
        void SetDrawable(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);

            //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);

            Agl.aglSetDrawable(Handle.Handle, windowPort);
            MyAGLReportError("aglSetDrawable");
        }
Exemple #14
0
        internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
        {
            Agl.aglSetDrawable(this.Handle.Handle, IntPtr.Zero);
            int num1 = (int)Agl.aglUpdateContext(this.Handle.Handle);
            int num2 = (int)CG.DisplayRelease(this.GetQuartzDevice(windowInfo));

            this.SetDrawable(windowInfo);
            this.mIsFullscreen = false;
        }
        void SetDrawable(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort = API.GetWindowPort(carbonWindow.WindowRef);
            //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);

            byte code = Agl.aglSetDrawable(ContextHandle, windowPort);

            Agl.CheckReturnValue(code, "aglSetDrawable");
        }
        public AglContext(GraphicsMode mode, IWindowInfo window)
        {
            Debug.Print("Window info: {0}", window);

            Mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            CreateContext(mode, carbonWindow, true);
        }
Exemple #17
0
 public AglContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext)
 {
     if (handle == ContextHandle.Zero)
     throw new ArgumentException("handle");
       if (window == null)
     throw new ArgumentNullException("window");
       this.Handle = handle;
       this.carbonWindow = (CarbonWindowInfo) window;
 }
Exemple #18
0
        public override void Update(IWindowInfo window)
        {
            CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);

            Agl.aglUpdateContext(Handle.Handle);
        }
Exemple #19
0
 public AglContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext)
     : base(DesktopBackend.OpenGL)
 {
     if (handle == ContextHandle.Zero)
         throw new ArgumentException("handle");
     if (window == null)
         throw new ArgumentNullException("window");
     Handle = handle;
     carbonWindow = (CarbonWindowInfo)window;
 }
Exemple #20
0
 internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
 {
     Debug.Print("Unsetting AGL fullscreen.");
     Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
     Agl.aglUpdateContext(Handle.Handle);
     CG.DisplayRelease(GetQuartzDevice(windowInfo));
     Debug.Print("Resetting drawable.");
     SetDrawable(windowInfo);
     mIsFullscreen = false;
 }
Exemple #21
0
 public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
 {
     this.graphics_mode = mode;
       this.carbonWindow = (CarbonWindowInfo) window;
       if (shareContext is AglContext)
     this.shareContextRef = ((GraphicsContextBase) shareContext).Handle.Handle;
       if (shareContext is GraphicsContext)
     this.shareContextRef = (shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle) IntPtr.Zero).Handle;
       int num = this.shareContextRef == IntPtr.Zero ? 1 : 0;
       this.CreateContext(mode, this.carbonWindow, this.shareContextRef, true);
 }
Exemple #22
0
 public AglContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext)
 {
     if (handle == ContextHandle.Zero)
     {
         throw new ArgumentException("handle");
     }
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     this.Handle       = handle;
     this.carbonWindow = (CarbonWindowInfo)window;
 }
Exemple #23
0
        private void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            IntPtr newWindow = API.CreateNewWindow(@class, attrib, r);

            API.SetWindowTitle(newWindow, this.title);
            this.window = new CarbonWindowInfo(newWindow, true, false);
            this.SetLocation(r.X, r.Y);
            this.SetSize(r.Width, r.Height);
            CarbonGLNative.mWindows.Add(newWindow, new WeakReference((object)this));
            this.LoadSize();
            this.mTitlebarHeight = (int)API.GetWindowBounds(this.window.WindowRef, WindowRegionCode.TitleBarRegion).Height;
            this.ConnectEvents();
        }
Exemple #24
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
                shareContextRef = ((AglContext)shareContext).Handle.Handle;

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
Exemple #25
0
        private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow)
        {
            WeakReference r = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef];

            if (r.IsAlive)
            {
                return((CarbonGLNative)r.Target);
            }
            else
            {
                return(null);
            }
        }
Exemple #26
0
        internal void SetFullScreen(CarbonWindowInfo info)
        {
            Agl.aglSetFullScreen(Handle.Handle, 0, 0, 0, 0);

            // This is a weird hack to workaround a bug where the first time a context
            // is made fullscreen, we just end up with a blank screen.  So we undo it as fullscreen
            // and redo it as fullscreen.
            if (firstFullScreen == false)
            {
                firstFullScreen = true;
                UnsetFullScreen(info);
                SetFullScreen(info);
            }
        }
Exemple #27
0
 public AglContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext)
     : base(DesktopBackend.OpenGL)
 {
     if (handle == ContextHandle.Zero)
     {
         throw new ArgumentException("handle");
     }
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     Handle       = handle;
     carbonWindow = (CarbonWindowInfo)window;
 }
Exemple #28
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            Debug.Print("AGL pixel format attributes:");

            AGLPixelFormat myAGLPixelFormat;

            // Choose a pixel format with the attributes we specified.
            IntPtr gdevice;
            IntPtr cgdevice = GetQuartzDevice(carbonWindow);

            if (cgdevice == IntPtr.Zero)
            {
                cgdevice = (IntPtr)DisplayDevice.Default.Id;
            }

            OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);

            if (status != OSStatus.NoError)
            {
                throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
            }

            IGraphicsMode selector = new MacOSGraphicsMode(gdevice);

            Mode = selector.SelectGraphicsMode(
                mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
            MyAGLReportError("aglChoosePixelFormat");

            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            myAGLPixelFormat = Mode.Index.Value;

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");

            Debug.Print("IsControl: {0}", carbonWindow.IsControl);

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);
            Debug.Print("context: {0}", Handle.Handle);
        }
        internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
        {
            Debug.Print("Unsetting AGL fullscreen.");
            byte code = Agl.aglSetDrawable(ContextHandle, IntPtr.Zero);

            Agl.CheckReturnValue(code, "aglSetDrawable");
            code = Agl.aglUpdateContext(ContextHandle);
            Agl.CheckReturnValue(code, "aglUpdateContext");

            CG.CGDisplayRelease(GetQuartzDevice(windowInfo));
            Debug.Print("Resetting drawable.");
            SetDrawable(windowInfo);

            mIsFullscreen = false;
        }
Exemple #30
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow  = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
            {
                shareContextRef = ((AglContext)shareContext).Handle.Handle;
            }

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
Exemple #31
0
        private static IntPtr GetWindowPortForWindowInfo(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort;

            if (carbonWindow.IsControl)
            {
                IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
                windowPort = API.GetWindowPort(controlOwner);
            }
            else
            {
                windowPort = API.GetWindowPort(carbonWindow.WindowRef);
            }
            return(windowPort);
        }
Exemple #32
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            this.graphics_mode = mode;
            this.carbonWindow  = (CarbonWindowInfo)window;
            if (shareContext is AglContext)
            {
                this.shareContextRef = ((GraphicsContextBase)shareContext).Handle.Handle;
            }
            if (shareContext is GraphicsContext)
            {
                this.shareContextRef = (shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero).Handle;
            }
            int num = this.shareContextRef == IntPtr.Zero ? 1 : 0;

            this.CreateContext(mode, this.carbonWindow, this.shareContextRef, true);
        }
Exemple #33
0
        public override void Update(IWindowInfo window)
        {
            CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;

            if (carbonWindow.GoFullScreenHack)
            {
                carbonWindow.GoFullScreenHack = false;
                CarbonGLNative wind = GetCarbonWindow(carbonWindow);

                if (wind != null)
                {
                    wind.SetFullscreen(this);
                }
                else
                {
                    Debug.Print("Could not find window!");
                }

                return;
            }

            else if (carbonWindow.GoWindowedHack)
            {
                carbonWindow.GoWindowedHack = false;
                CarbonGLNative wind = GetCarbonWindow(carbonWindow);

                if (wind != null)
                {
                    wind.UnsetFullscreen(this);
                }
                else
                {
                    Debug.Print("Could not find window!");
                }
            }

            if (mIsFullscreen)
            {
                return;
            }

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);

            Agl.aglUpdateContext(Handle.Handle);
        }
Exemple #34
0
        internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height)
        {
            CarbonGLNative carbonWindow = this.GetCarbonWindow(info);
            int            num          = (int)CG.DisplayCapture(this.GetQuartzDevice(info));

            Agl.aglSetFullScreen(this.Handle.Handle, carbonWindow.TargetDisplayDevice.Width, carbonWindow.TargetDisplayDevice.Height, 0, 0);
            this.MakeCurrent((IWindowInfo)info);
            width  = carbonWindow.TargetDisplayDevice.Width;
            height = carbonWindow.TargetDisplayDevice.Height;
            if (!this.firstFullScreen)
            {
                this.firstFullScreen = true;
                this.UnsetFullScreen(info);
                this.SetFullScreen(info, out width, out height);
            }
            this.mIsFullscreen = true;
        }
Exemple #35
0
        protected virtual void Dispose(bool disposing)
        {
            if (mIsDisposed)
            {
                return;
            }
            Debug.Print("Disposing of CarbonGLNative window.");
            API.DisposeWindow(window.WindowRef);
            mIsDisposed = true;
            mExists     = false;
            if (disposing)
            {
                mWindows.Remove(window.WindowRef);
                window.Dispose();
                window = null;
            }

            DisposeUPP();
        }
Exemple #36
0
        protected virtual void Dispose(bool disposing)
        {
            if (this.mIsDisposed)
            {
                return;
            }
            this.CursorVisible = true;
            API.DisposeWindow(this.window.WindowRef);
            this.mIsDisposed = true;
            this.mExists     = false;
            int num = (int)CG.SetLocalEventsSuppressionInterval(0.25);

            if (disposing)
            {
                CarbonGLNative.mWindows.Remove(this.window.WindowRef);
                this.window.Dispose();
                this.window = (CarbonWindowInfo)null;
            }
            this.DisposeUPP();
            this.Disposed((object)this, EventArgs.Empty);
        }
Exemple #37
0
 internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
 {
     Debug.Print("Unsetting AGL fullscreen.");
     Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
     Agl.aglUpdateContext(Handle.Handle);
     
     CG.DisplayRelease(GetQuartzDevice(windowInfo));
     Debug.Print("Resetting drawable.");
     SetDrawable(windowInfo);
     
     mIsFullscreen = false;
 }
Exemple #38
0
 private void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
 {
   IntPtr newWindow = API.CreateNewWindow(@class, attrib, r);
   API.SetWindowTitle(newWindow, this.title);
   this.window = new CarbonWindowInfo(newWindow, true, false);
   this.SetLocation(r.X, r.Y);
   this.SetSize(r.Width, r.Height);
   CarbonGLNative.mWindows.Add(newWindow, new WeakReference((object) this));
   this.LoadSize();
   this.mTitlebarHeight = (int) API.GetWindowBounds(this.window.WindowRef, WindowRegionCode.TitleBarRegion).Height;
   this.ConnectEvents();
 }
Exemple #39
0
 private void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
 {
     List<int> aglAttributes = new List<int>();
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);
       if (mode.Depth > 0)
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
       if (mode.Stencil > 0)
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
       if (mode.AccumulatorFormat.BitsPerPixel > 0)
       {
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
       }
       if (mode.Samples > 1)
       {
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
       }
       if (fullscreen)
     this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
       this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
       int num = 0;
       while (num < aglAttributes.Count)
     ++num;
       IntPtr pix;
       if (fullscreen)
       {
     IntPtr displayID = this.GetQuartzDevice(carbonWindow);
     if (displayID == IntPtr.Zero)
       displayID = (IntPtr) DisplayDevice.Default.Id;
     IntPtr displayDevice;
     OSStatus gdeviceByDisplayId = API.DMGetGDeviceByDisplayID(displayID, out displayDevice, false);
     if (gdeviceByDisplayId != OSStatus.NoError)
       throw new MacOSException(gdeviceByDisplayId, "DMGetGDeviceByDisplayID failed.");
     pix = Agl.aglChoosePixelFormat(ref displayDevice, 1, aglAttributes.ToArray());
     if (Agl.GetError() == Agl.AglError.BadPixelFormat)
     {
       this.CreateContext(mode, carbonWindow, shareContextRef, false);
       return;
     }
       }
       else
       {
     pix = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
     this.MyAGLReportError("aglChoosePixelFormat");
       }
       this.Handle = new ContextHandle(Agl.aglCreateContext(pix, shareContextRef));
       this.MyAGLReportError("aglCreateContext");
       Agl.aglDestroyPixelFormat(pix);
       this.MyAGLReportError("aglDestroyPixelFormat");
       this.SetDrawable(carbonWindow);
       this.SetBufferRect(carbonWindow);
       this.Update((IWindowInfo) carbonWindow);
       this.MakeCurrent((IWindowInfo) carbonWindow);
 }
Exemple #40
0
 private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
 {
     IntPtr windowRef = carbonWindow.WindowRef;
       if (!CarbonGLNative.WindowRefMap.ContainsKey(windowRef))
     return IntPtr.Zero;
       WeakReference weakReference = CarbonGLNative.WindowRefMap[windowRef];
       if (!weakReference.IsAlive)
     return IntPtr.Zero;
       CarbonGLNative carbonGlNative = weakReference.Target as CarbonGLNative;
       if (carbonGlNative == null)
     return IntPtr.Zero;
       else
     return QuartzDisplayDeviceDriver.HandleTo(carbonGlNative.TargetDisplayDevice);
 }
Exemple #41
0
 private void SetDrawable(CarbonWindowInfo carbonWindow)
 {
     Agl.aglSetDrawable(this.Handle.Handle, AglContext.GetWindowPortForWindowInfo(carbonWindow));
       this.MyAGLReportError("aglSetDrawable");
 }
Exemple #42
0
 internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
 {
     Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
     SetDrawable(windowInfo);
 }
Exemple #43
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            List<int> aglAttributes = new List<int>();
            
            Debug.Print("AGL pixel format attributes:");
            Debug.Indent();
            
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);
            
            if (mode.Depth > 0)
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            
            if (mode.Stencil > 0)
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            
            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }
            
            if (mode.Samples > 1)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }
            
            if (fullscreen)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
            
            Debug.Unindent();
            
            Debug.Write("Attribute array:  ");
            for (int i = 0; i < aglAttributes.Count; i++)
                Debug.Write(aglAttributes[i].ToString() + "  ");
            Debug.WriteLine("");
            
            AGLPixelFormat myAGLPixelFormat;
            
            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);
                
                if (cgdevice == IntPtr.Zero)
                    cgdevice = (IntPtr)DisplayDevice.Default.Id;
                
                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
                
                if (status != OSStatus.NoError)
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                
                myAGLPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, aglAttributes.ToArray());
                
                Agl.AglError err = Agl.GetError();
                
                if (err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");
                    
                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }

            else
            {
                myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
                
                MyAGLReportError("aglChoosePixelFormat");
            }
            
            
            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            
            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");
            
            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");
            
            Debug.Print("IsControl: {0}", carbonWindow.IsControl);
            
            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);
            
            MakeCurrent(carbonWindow);
            
            Debug.Print("context: {0}", Handle.Handle);
        }
Exemple #44
0
        void SetBufferRect(CarbonWindowInfo carbonWindow)
        {
            if (carbonWindow.IsControl == false)
                return;

            Rect rect = API.GetControlBounds(carbonWindow.WindowHandle);
            
            Debug.Print("Setting buffer_rect for control.");
            Debug.Print("MacOS Coordinate Rect:   {0}", rect);
            int[] glrect = new int[4];

            if (carbonWindow.XOffset != null)
                glrect[0] = rect.X + carbonWindow.XOffset();
            else
                glrect[0] = rect.X;
            if (carbonWindow.YOffset != null)
                glrect[1] = rect.Y + carbonWindow.YOffset();
            else
                glrect[1] = rect.Y;
            glrect[2] = rect.Width;
            glrect[3] = rect.Height;
            
            Agl.aglSetInteger(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
            MyAGLReportError("aglSetInteger");
            
            Agl.aglEnable(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT);
            MyAGLReportError("aglEnable");
        }
Exemple #45
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            Debug.Print("AGL pixel format attributes:");
            
            AGLPixelFormat myAGLPixelFormat;
            
            // Choose a pixel format with the attributes we specified.
            IntPtr gdevice;
            IntPtr cgdevice = GetQuartzDevice(carbonWindow);
                
            if (cgdevice == IntPtr.Zero)
                cgdevice = (IntPtr)DisplayDevice.Default.Id;
                
            OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
                
            if (status != OSStatus.NoError)
                throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");

            IGraphicsMode selector = new MacOSGraphicsMode(gdevice);
            Mode = selector.SelectGraphicsMode(
                mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
            MyAGLReportError("aglChoosePixelFormat");

            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            myAGLPixelFormat = Mode.Index.Value;

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");
            
            Debug.Print("IsControl: {0}", carbonWindow.IsControl);
            
            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);
            
            MakeCurrent(carbonWindow);
            Debug.Print("context: {0}", Handle.Handle);
        }
Exemple #46
0
        protected virtual void Dispose(bool disposing)
        {
            if (mIsDisposed)
                return;

            Debug.Print("Disposing of CarbonGLNative window.");

            CursorVisible = true;
            API.DisposeWindow(window.WindowRef);
            mIsDisposed = true;
            mExists = false;

            CG.SetLocalEventsSuppressionInterval(0.25);

            if (disposing)
            {
                mWindows.Remove(window.WindowRef);
                
                window.Dispose();
                window = null;
            }

            DisposeUPP();

            Disposed(this, EventArgs.Empty);
        }
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");

            IntPtr windowRef;
            OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
            API.CheckReturn( err );
            Debug.Print( "Created window " + windowRef );
            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef);
            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);
            mWindows.Add(windowRef, new WeakReference(this));
            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);
            mTitlebarHeight = titleSize.Height;
            Debug.Print("Titlebar size: {0}", titleSize);
            ConnectEvents();
            Debug.Print("Attached window events.");
        }
Exemple #48
0
        protected virtual void Dispose(bool disposing)
        {
            if (mIsDisposed)
                return;

            Debug.Print("Disposing of CarbonGLNative window.");

            mIsDisposed = true;

            if (disposing)
            {
                mWindows.Remove(window.WindowRef);

                window.Dispose();
                window = null;
            }

            DisposeUPP();
        }
Exemple #49
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");
            Debug.Indent();

            IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);
            API.SetWindowTitle(windowRef, title);

            window = new CarbonWindowInfo(windowRef, true, false);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);

            Debug.Unindent();
            Debug.Print("Created window.");

            mWindows.Add(windowRef, new WeakReference(this));

            LoadSize();

            Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);
            mTitlebarHeight = titleSize.Height;

            Debug.Print("Titlebar size: {0}", titleSize);

            ConnectEvents();

            System.Diagnostics.Debug.Print("Attached window events.");
        }
Exemple #50
0
 private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
 {
     IntPtr windowRef = carbonWindow.WindowRef;
     
     if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false)
         return IntPtr.Zero;
     
     WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef];
     if (nativeRef.IsAlive == false)
         return IntPtr.Zero;
     
     CarbonGLNative window = nativeRef.Target as CarbonGLNative;
     
     if (window == null)
         return IntPtr.Zero;
     
     return QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice);
     
 }
Exemple #51
0
        void SetDrawable(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);

            Agl.aglSetDrawable(Handle.Handle, windowPort);

            MyAGLReportError("aglSetDrawable");
        }
Exemple #52
0
        void SetBufferRect(CarbonWindowInfo carbonWindow)
        {
            if (carbonWindow.IsControl == false)
                return;

            // Todo: See if there is a way around using WinForms.
            throw new NotImplementedException();
#if false
            System.Windows.Forms.Control ctrl = Control.FromHandle(carbonWindow.WindowRef);
            
            if (ctrl.TopLevelControl == null)
                return;
            
            Rect rect = API.GetControlBounds(carbonWindow.WindowRef);
            System.Windows.Forms.Form frm = (System.Windows.Forms.Form)ctrl.TopLevelControl;
            
            System.Drawing.Point loc = frm.PointToClient(ctrl.PointToScreen(System.Drawing.Point.Empty));
            
            rect.X = (short)loc.X;
            rect.Y = (short)loc.Y;
            
            Debug.Print("Setting buffer_rect for control.");
            Debug.Print("MacOS Coordinate Rect:   {0}", rect);
            
            rect.Y = (short)(ctrl.TopLevelControl.ClientSize.Height - rect.Y - rect.Height);
            Debug.Print("  AGL Coordinate Rect:   {0}", rect);
            
            int[] glrect = new int[4];
            
            glrect[0] = rect.X;
            glrect[1] = rect.Y;
            glrect[2] = rect.Width;
            glrect[3] = rect.Height;
            
            Agl.aglSetInteger(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
            MyAGLReportError("aglSetInteger");
            
            Agl.aglEnable(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT);
            MyAGLReportError("aglEnable");
#endif
        }
Exemple #53
0
        internal void SetFullScreen(CarbonWindowInfo info)
        {
            Agl.aglSetFullScreen(Handle.Handle, 0, 0, 0, 0);

            // This is a weird hack to workaround a bug where the first time a context
            // is made fullscreen, we just end up with a blank screen.  So we undo it as fullscreen
            // and redo it as fullscreen.
            if (firstFullScreen == false)
            {
                firstFullScreen = true;
                UnsetFullScreen(info);
                SetFullScreen(info);
            }
        }
Exemple #54
0
 void SetDrawable(CarbonWindowInfo carbonWindow)
 {
     IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);
     //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);
     
     Agl.aglSetDrawable(Handle.Handle, windowPort);
     
     MyAGLReportError("aglSetDrawable");
     
 }
Exemple #55
0
 private void SetBufferRect(CarbonWindowInfo carbonWindow)
 {
     if (carbonWindow.IsControl)
     throw new NotImplementedException();
 }
Exemple #56
0
        private static IntPtr GetWindowPortForWindowInfo(CarbonWindowInfo carbonWindow)
        {
            IntPtr windowPort;
            if (carbonWindow.IsControl)
            {
                IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
                
                windowPort = API.GetWindowPort(controlOwner);
            }

            else
                windowPort = API.GetWindowPort(carbonWindow.WindowRef);
            
            return windowPort;
        }
Exemple #57
0
 private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow)
 {
     WeakReference weakReference = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef];
       if (weakReference.IsAlive)
     return (CarbonGLNative) weakReference.Target;
       else
     return (CarbonGLNative) null;
 }
Exemple #58
0
        private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow)
        {
            WeakReference r = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef];
            
            if (r.IsAlive)
            {
                return (CarbonGLNative)r.Target;
            }

            else
                return null;
        }
Exemple #59
0
 internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height)
 {
     CarbonGLNative wind = GetCarbonWindow(info);
     
     Debug.Print("Switching to full screen {0}x{1} on context {2}", wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle);
     
     CG.DisplayCapture(GetQuartzDevice(info));
     Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0);
     MakeCurrent(info);
     
     width = wind.TargetDisplayDevice.Width;
     height = wind.TargetDisplayDevice.Height;
     
     // This is a weird hack to workaround a bug where the first time a context
     // is made fullscreen, we just end up with a blank screen.  So we undo it as fullscreen
     // and redo it as fullscreen.  
     if (firstFullScreen == false)
     {
         firstFullScreen = true;
         UnsetFullScreen(info);
         SetFullScreen(info, out width, out height);
     }
     
     mIsFullscreen = true;
 }
Exemple #60
0
 protected virtual void Dispose(bool disposing)
 {
   if (this.mIsDisposed)
     return;
   this.CursorVisible = true;
   API.DisposeWindow(this.window.WindowRef);
   this.mIsDisposed = true;
   this.mExists = false;
   int num = (int) CG.SetLocalEventsSuppressionInterval(0.25);
   if (disposing)
   {
     CarbonGLNative.mWindows.Remove(this.window.WindowRef);
     this.window.Dispose();
     this.window = (CarbonWindowInfo) null;
   }
   this.DisposeUPP();
   this.Disposed((object) this, EventArgs.Empty);
 }