private aglChoosePixelFormat ( AGLDevice &gdevs, int ndev, int attribs ) : AGLPixelFormat | ||
gdevs | AGLDevice | |
ndev | int | |
attribs | int | |
return | AGLPixelFormat |
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); }
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); }
private IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { List <int> list = new List <int>(); if (color.BitsPerPixel > 0) { if (!color.IsIndexed) { list.Add(4); } list.Add(8); list.Add(color.Red); list.Add(9); list.Add(color.Green); list.Add(10); list.Add(color.Blue); list.Add(11); list.Add(color.Alpha); } if (depth > 0) { list.Add(12); list.Add(depth); } if (buffers > 1) { list.Add(5); } if (stencil > 1) { list.Add(13); list.Add(stencil); } if (accum.BitsPerPixel > 0) { list.Add(17); list.Add(accum.Alpha); list.Add(16); list.Add(accum.Blue); list.Add(15); list.Add(accum.Green); list.Add(14); list.Add(accum.Red); } if (samples > 0) { list.Add(55); list.Add(1); list.Add(56); list.Add(samples); } if (stereo) { list.Add(6); } list.Add(0); list.Add(0); IntPtr num = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, list.ToArray()); if (num == IntPtr.Zero) { throw new GraphicsModeException(string.Format("[Error] Failed to select GraphicsMode, error {0}.", (object)Agl.GetError())); } else { return(num); } }
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); }
private IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { var attribs = new List <int>(); Debug.Print("Bits per pixel: {0}", color.BitsPerPixel); if (color.BitsPerPixel > 0) { if (!color.IsIndexed) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_RGBA); } attribs.Add((int)Agl.PixelFormatAttribute.AGL_RED_SIZE); attribs.Add(color.Red); attribs.Add((int)Agl.PixelFormatAttribute.AGL_GREEN_SIZE); attribs.Add(color.Green); attribs.Add((int)Agl.PixelFormatAttribute.AGL_BLUE_SIZE); attribs.Add(color.Blue); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ALPHA_SIZE); attribs.Add(color.Alpha); } Debug.Print("Depth: {0}", depth); if (depth > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_DEPTH_SIZE); attribs.Add(depth); } if (buffers > 1) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER); } if (stencil > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_STENCIL_SIZE); attribs.Add(stencil); } if (accum.BitsPerPixel > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE); attribs.Add(accum.Alpha); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE); attribs.Add(accum.Blue); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE); attribs.Add(accum.Green); attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE); attribs.Add(accum.Red); } if (samples > 0) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB); attribs.Add(1); attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLES_ARB); attribs.Add(samples); } if (stereo) { attribs.Add((int)Agl.PixelFormatAttribute.AGL_STEREO); } attribs.Add(0); attribs.Add(0); var pixelformat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray()); return(pixelformat); }
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); }