public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr pixelformat; do { pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo, true, Device); Agl.AglError err = Agl.GetError(); if (pixelformat == IntPtr.Zero || err == Agl.AglError.BadPixelFormat) { Debug.Print("Failed to create full screen pixel format."); Debug.Print("Trying again to create a non-fullscreen pixel format."); pixelformat = SelectPixelFormat( color, depth, stencil, samples, accum, buffers, stereo, false, IntPtr.Zero); } if (pixelformat == IntPtr.Zero) { if (!Utilities.RelaxGraphicsMode( ref color, ref depth, ref stencil, ref samples, ref accum, ref buffers, ref stereo)) { throw new GraphicsModeException("Requested GraphicsMode not available."); } } }while (pixelformat == IntPtr.Zero); return(GetGraphicsModeFromPixelFormat(pixelformat)); }
private void MyAGLReportError(string function) { Agl.AglError error = Agl.GetError(); if (error != Agl.AglError.NoError) { throw new MacOSException((OSStatus)error, string.Format("AGL Error from function {0}: {1} {2}", (object)function, (object)error, (object)Agl.ErrorString(error))); } }
internal static void aglSetFullScreen(IntPtr ctx, int width, int height, int freq, int device) { if ((int)Agl._aglSetFullScreen(ctx, width, height, freq, device) != 0) { return; } Agl.AglError error = Agl.GetError(); throw new MacOSException(error, Agl.ErrorString(error)); }
internal static void aglSetDrawable(IntPtr ctx, IntPtr draw) { if ((int)Agl._aglSetDrawable(ctx, draw) != 0) { return; } Agl.AglError error = Agl.GetError(); throw new MacOSException(error, Agl.ErrorString(error)); }
void MyAGLReportError(string function) { Agl.AglError err = Agl.GetError(); if (err != Agl.AglError.NoError) { throw new Exception(String.Format( "AGL Error from function {0}: {1} {2}", function, err, Agl.ErrorString(err))); } }
internal MacOSException(Agl.AglError errorCode, string message) : base(message) { this.errorCode = (OSStatus)errorCode; }
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 = QuartzDisplayDeviceDriver.MainDisplay; } 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); }
internal static string ErrorString(Agl.AglError code) { return(Marshal.PtrToStringAnsi(Agl._aglErrorString(code))); }
private static IntPtr _aglErrorString(Agl.AglError code);
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); }
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. 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 = ModeSelector.SelectPixelFormat( mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, true, gdevice); Agl.AglError err = Agl.GetError(); if (myAGLPixelFormat == IntPtr.Zero || 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 = ModeSelector.SelectPixelFormat( mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, false, IntPtr.Zero); 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"); Mode = ModeSelector.GetGraphicsModeFromPixelFormat(myAGLPixelFormat); // 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); }