static void SetGLAttributes(GraphicsMode mode, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags) { ContextProfileFlags cpflags = 0; ClearGLAttributes(); if (mode.AccumulatorFormat.BitsPerPixel > 0) { SDL.GL.SetAttribute(ContextAttribute.ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); SDL.GL.SetAttribute(ContextAttribute.ACCUM_RED_SIZE, mode.AccumulatorFormat.Red); SDL.GL.SetAttribute(ContextAttribute.ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green); SDL.GL.SetAttribute(ContextAttribute.ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue); } if (mode.Buffers > 0) { SDL.GL.SetAttribute(ContextAttribute.DOUBLEBUFFER, mode.Buffers > 1 ? 1 : 0); } if (mode.ColorFormat > 0) { SDL.GL.SetAttribute(ContextAttribute.ALPHA_SIZE, mode.ColorFormat.Alpha); SDL.GL.SetAttribute(ContextAttribute.RED_SIZE, mode.ColorFormat.Red); SDL.GL.SetAttribute(ContextAttribute.GREEN_SIZE, mode.ColorFormat.Green); SDL.GL.SetAttribute(ContextAttribute.BLUE_SIZE, mode.ColorFormat.Blue); } if (mode.Depth > 0) { SDL.GL.SetAttribute(ContextAttribute.DEPTH_SIZE, mode.Depth); } if (mode.Samples > 0) { SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLEBUFFERS, 1); SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLESAMPLES, mode.Samples); } if (mode.Stencil > 0) { SDL.GL.SetAttribute(ContextAttribute.STENCIL_SIZE, mode.Stereo ? 1 : 0); } if (mode.Stereo) { SDL.GL.SetAttribute(ContextAttribute.STEREO, 1); } if (major > 0) { // Workaround for https://github.com/opentk/opentk/issues/44 // Mac OS X desktop OpenGL 3.x/4.x contexts require require // ContextProfileFlags.Core, otherwise they will fail to construct. if (Configuration.RunningOnMacOS && major >= 3 && (flags & GraphicsContextFlags.Embedded) == 0) { cpflags |= ContextProfileFlags.CORE; // According to https://developer.apple.com/graphicsimaging/opengl/capabilities/GLInfo_1075_Core.html // Mac OS X supports 3.2+. Indeed, requesting 3.0 or 3.1 results in failure. if (major == 3 && minor < 2) { minor = 2; } } SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MAJOR_VERSION, major); SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MINOR_VERSION, minor); } if ((flags & GraphicsContextFlags.Debug) != 0) { SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.DEBUG); } /* * if ((flags & GraphicsContextFlags.Robust) != 0) * { * SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.ROBUST_ACCESS_FLAG); * } * * if ((flags & GraphicsContextFlags.ResetIsolation) != 0) * { * SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.RESET_ISOLATION_FLAG); * } */ { if ((flags & GraphicsContextFlags.Embedded) != 0) { cpflags |= ContextProfileFlags.ES; SDL.GL.SetAttribute(ContextAttribute.CONTEXT_EGL, 1); } if ((flags & GraphicsContextFlags.ForwardCompatible) != 0) { cpflags |= ContextProfileFlags.CORE; } if (cpflags != 0) { SDL.GL.SetAttribute(ContextAttribute.CONTEXT_PROFILE_MASK, cpflags); } } if (shareContext != null) { if (shareContext.IsCurrent) { SDL.GL.SetAttribute(ContextAttribute.SHARE_WITH_CURRENT_CONTEXT, 1); } else { Trace.WriteLine("Warning: SDL2 requires a shared context to be current before sharing. Sharing failed."); } } }
static void SetGLAttributes(GraphicsMode mode, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags) { if (mode.AccumulatorFormat.BitsPerPixel > 0) { SDL.GL.SetAttribute(ContextAttribute.ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); SDL.GL.SetAttribute(ContextAttribute.ACCUM_RED_SIZE, mode.AccumulatorFormat.Red); SDL.GL.SetAttribute(ContextAttribute.ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green); SDL.GL.SetAttribute(ContextAttribute.ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue); } if (mode.Buffers > 0) { SDL.GL.SetAttribute(ContextAttribute.DOUBLEBUFFER, mode.Buffers > 1 ? 1 : 0); } if (mode.ColorFormat > 0) { SDL.GL.SetAttribute(ContextAttribute.ALPHA_SIZE, mode.ColorFormat.Alpha); SDL.GL.SetAttribute(ContextAttribute.RED_SIZE, mode.ColorFormat.Red); SDL.GL.SetAttribute(ContextAttribute.GREEN_SIZE, mode.ColorFormat.Green); SDL.GL.SetAttribute(ContextAttribute.BLUE_SIZE, mode.ColorFormat.Blue); } if (mode.Depth > 0) { SDL.GL.SetAttribute(ContextAttribute.DEPTH_SIZE, mode.Depth); } if (mode.Samples > 0) { SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLEBUFFERS, 1); SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLESAMPLES, mode.Samples); } if (mode.Stencil > 0) { SDL.GL.SetAttribute(ContextAttribute.STENCIL_SIZE, mode.Stereo ? 1 : 0); } if (mode.Stereo) { SDL.GL.SetAttribute(ContextAttribute.STEREO, 1); } if (major > 0) { SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MAJOR_VERSION, major); SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MINOR_VERSION, minor); } if ((flags & GraphicsContextFlags.Debug) != 0) { SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.DEBUG); } /* * if ((flags & GraphicsContextFlags.Robust) != 0) * { * SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.ROBUST_ACCESS_FLAG); * } * * if ((flags & GraphicsContextFlags.ResetIsolation) != 0) * { * SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.RESET_ISOLATION_FLAG); * } */ { ContextProfileFlags cpflags = 0; if ((flags & GraphicsContextFlags.Embedded) != 0) { cpflags |= ContextProfileFlags.ES; SDL.GL.SetAttribute(ContextAttribute.CONTEXT_EGL, 1); } if ((flags & GraphicsContextFlags.ForwardCompatible) != 0) { cpflags |= ContextProfileFlags.CORE; } if (cpflags != 0) { SDL.GL.SetAttribute(ContextAttribute.CONTEXT_PROFILE_MASK, cpflags); } } if (shareContext != null) { if (shareContext.IsCurrent) { SDL.GL.SetAttribute(ContextAttribute.SHARE_WITH_CURRENT_CONTEXT, 1); } else { Trace.WriteLine("Warning: SDL2 requires a shared context to be current before sharing. Sharing failed."); } } }
public static int SetAttribute(ContextAttribute attr, ContextProfileFlags value) { return SetAttribute(attr, (int)value); }
public static int SetAttribute(ContextAttribute attr, ContextProfileFlags value) { return(SetAttribute(attr, (int)value)); }