Exemple #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;
        }
Exemple #2
0
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed || ContextHandle == IntPtr.Zero)
            {
                return;
            }

            Debug.Print("Disposing of AGL context.");
            Agl.aglSetCurrentContext(IntPtr.Zero);

            //Debug.Print("Setting drawable to null for context {0}.", Handle.Handle);
            //Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);

            // I do not know MacOS allows us to destroy a context from a separate thread,
            // like the finalizer thread.  It's untested, but worst case is probably
            // an exception on application exit, which would be logged to the console.
            Debug.Print("Destroying context");
            byte code = Agl.aglDestroyContext(ContextHandle);

            try {
                Agl.CheckReturnValue(code, "aglDestroyContext");
                ContextHandle = IntPtr.Zero;
                Debug.Print("Context destruction completed successfully.");
            } catch (MacOSException) {
                Debug.Print("Failed to destroy context.");
                if (disposing)
                {
                    throw;
                }
            }
            IsDisposed = true;
        }
        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, ContextHandle);

            CG.CGDisplayCapture(GetQuartzDevice(info));
            byte code = Agl.aglSetFullScreen(ContextHandle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0);

            Agl.CheckReturnValue(code, "aglSetFullScreen");
            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)
            {
                firstFullScreen = true;
                UnsetFullScreen(info);
                SetFullScreen(info, out width, out height);
            }

            mIsFullscreen = true;
        }
Exemple #4
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");
        }
Exemple #5
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);
        }
Exemple #6
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;
        }
Exemple #7
0
        void MakeCurrent(INativeWindow window)
        {
            byte code = Agl.aglSetCurrentContext(ContextHandle);

            Agl.CheckReturnValue(code, "aglSetCurrentContext");
        }
Exemple #8
0
 public override void SwapBuffers()
 {
     Agl.aglSwapBuffers(ContextHandle);
     Agl.CheckReturnValue(0, "aglSwapBuffers");
 }
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, bool fullscreen)
        {
            List <int> attribs = new List <int>();

            attribs.Add((int)Agl.PixelFormatAttribute.AGL_RGBA);
            attribs.Add((int)Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);

            if (mode.Depth > 0)
            {
                AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(attribs, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            }

            if (fullscreen)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            attribs.Add((int)Agl.PixelFormatAttribute.AGL_NONE);

            Debug.Print("AGL Attribute array:  ");
            for (int i = 0; i < attribs.Count; i++)
            {
                Debug.Print(attribs[i].ToString() + "  ");
            }
            Debug.Print("");

            AGLPixelFormat aglPixelFormat;

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

                if (cgdevice == IntPtr.Zero)
                {
                    cgdevice = QuartzDisplayDevice.MainDisplay;
                }

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

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

                aglPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, attribs.ToArray());
                Agl.AglError err = Agl.aglGetError();

                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, false);
                    return;
                }
            }
            else
            {
                aglPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray());
                Agl.CheckReturnValue(0, "aglChoosePixelFormat");
            }


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

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

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

            SetDrawable(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);

            Debug.Print("context: {0}", ContextHandle);
        }
        public override void MakeCurrent(IWindowInfo window)
        {
            byte code = Agl.aglSetCurrentContext(ContextHandle);

            Agl.CheckReturnValue(code, "aglSetCurrentContext");
        }