Exemplo n.º 1
0
        internal void SetFullScreen(CarbonWindow wind, out int width, out int height)
        {
            int displayWidth  = wind.Display.Bounds.Width;
            int displayHeight = wind.Display.Bounds.Height;

            Debug.Print("Switching to full screen {0}x{1} on context {2}",
                        displayWidth, displayHeight, ContextHandle);

            CG.CGDisplayCapture(CG.CGMainDisplayID());
            byte code = Agl.aglSetFullScreen(ContextHandle, displayWidth, displayHeight, 0, 0);

            Agl.CheckReturnValue(code, "aglSetFullScreen");
            MakeCurrent(wind);

            width  = displayWidth;
            height = displayHeight;

            // 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)
            {
                firstFullScreen = true;
                UnsetFullScreen(wind);
                SetFullScreen(wind, out width, out height);
            }
            mIsFullscreen = true;
        }
Exemplo n.º 2
0
        void SetDrawable(CarbonWindow window)
        {
            IntPtr windowPort = API.GetWindowPort(window.WinHandle);
            //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);

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

            Agl.CheckReturnValue(code, "aglSetDrawable");
        }
Exemplo n.º 3
0
        void CreateContext(GraphicsMode mode, CarbonWindow wind, bool fullscreen)
        {
            int[]  attribs = GetAttribs(mode, fullscreen);
            IntPtr pixelFormat;

            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr   gdevice;
                IntPtr   display = CG.CGMainDisplayID();
                OSStatus status  = API.DMGetGDeviceByDisplayID(display, out gdevice, false);

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

                pixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, attribs);
                int err = Agl.aglGetError();

                if (err == Agl.AGL_BAD_PIXEL_FORMAT)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");

                    CreateContext(mode, wind, false);
                    return;
                }
            }
            else
            {
                pixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs);
                Agl.CheckReturnValue(0, "aglChoosePixelFormat");
            }

            Debug.Print("Creating AGL context.");

            // create the context and share it with the share reference.
            ContextHandle = Agl.aglCreateContext(pixelFormat, IntPtr.Zero);
            Agl.CheckReturnValue(0, "aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(pixelFormat);
            Agl.CheckReturnValue(0, "aglDestroyPixelFormat");

            SetDrawable(wind);
            Update(wind);
            MakeCurrent(wind);

            Debug.Print("context: {0}", ContextHandle);
        }
Exemplo n.º 4
0
        internal void UnsetFullScreen(CarbonWindow window)
        {
            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(CG.CGMainDisplayID());
            Debug.Print("Resetting drawable.");
            SetDrawable(window);

            mIsFullscreen = false;
        }
Exemplo n.º 5
0
        public override void Update(INativeWindow window)
        {
            CarbonWindow wind = (CarbonWindow)window;

            if (wind.goFullScreenHack)
            {
                wind.goFullScreenHack = false;
                wind.SetFullscreen(this);
                return;
            }
            else if (wind.goWindowedHack)
            {
                wind.goWindowedHack = false;
                wind.UnsetFullscreen(this);
            }

            if (mIsFullscreen)
            {
                return;
            }
            SetDrawable(wind);
            Agl.aglUpdateContext(ContextHandle);
        }
Exemplo n.º 6
0
 public AglContext(GraphicsMode mode, CarbonWindow window)
 {
     Debug.Print("Window info: {0}", window);
     CreateContext(mode, window, true);
     MakeCurrent(window);
 }
Exemplo n.º 7
0
 IntPtr GetQuartzDevice(CarbonWindow window)
 {
     return(CG.CGMainDisplayID());
 }