private aglCreateContext ( AGLPixelFormat pix, AGLContext share ) : AGLContext | ||
pix | AGLPixelFormat | |
share | AGLContext | |
return | AGLContext |
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) { 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); }
private void CreateContext(GraphicsMode mode, IWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen) { Debug.Print("AGL pixel format attributes:"); // Choose a pixel format with the attributes we specified. AGLPixelFormat pixelformat; AglGraphicsMode selector = new AglGraphicsMode(); Mode = selector.SelectGraphicsMode( mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, out pixelformat); MyAGLReportError("aglChoosePixelFormat"); Debug.Print("Creating AGL context. Sharing with {0}", shareContextRef); // create the context and share it with the share reference. Context = new ContextHandle(Agl.aglCreateContext(pixelformat, shareContextRef)); MyAGLReportError("aglCreateContext"); // Free the pixel format from memory. Agl.aglDestroyPixelFormat(pixelformat); MyAGLReportError("aglDestroyPixelFormat"); SetDrawable(carbonWindow); SetBufferRect(carbonWindow); Update(carbonWindow); MakeCurrent(carbonWindow); Debug.Print("context: {0}", Context.Handle); dummyContext = new GraphicsContext(Context, GetAddress, delegate { return(new ContextHandle(Agl.aglGetCurrentContext())); }); }
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 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); }
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); }