public GLWidget(FramebufferFormat framebufferFormat, int major, int minor, OpenGLContextFlags flags = OpenGLContextFlags.Default, bool directRendering = true, OpenGLContextBase sharedContext = null) { FramebufferFormat = framebufferFormat; GLVersionMajor = major; GLVersionMinor = minor; ContextFlags = flags; DirectRendering = directRendering; SharedContext = sharedContext; }
public OpenGLContextBase(FramebufferFormat framebufferFormat, int major, int minor, OpenGLContextFlags flags, bool directRendering, OpenGLContextBase shareContext) { FramebufferFormat = framebufferFormat; Major = major; Minor = minor; Flags = flags; DirectRendering = directRendering; ShareContext = shareContext; }
public static OpenGLContextBase CreateOpenGLContext(FramebufferFormat framebufferFormat, int major, int minor, OpenGLContextFlags flags = OpenGLContextFlags.Default, bool directRendering = true, OpenGLContextBase shareContext = null) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { // TODO: detect X11/Wayland/DRI if (shareContext != null && !(shareContext is GLXOpenGLContext)) { throw new ContextException($"shared context must be of type {typeof(GLXOpenGLContext).Name}."); } return(new GLXOpenGLContext(framebufferFormat, major, minor, flags, directRendering, (GLXOpenGLContext)shareContext)); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (shareContext != null && !(shareContext is GLXOpenGLContext)) { throw new ContextException($"shared context must be of type {typeof(GLXOpenGLContext).Name}."); } return(new WGLOpenGLContext(framebufferFormat, major, minor, flags, directRendering, (WGLOpenGLContext)shareContext)); } throw new NotImplementedException(); }
public WGLOpenGLContext(FramebufferFormat framebufferFormat, int major, int minor, OpenGLContextFlags flags = OpenGLContextFlags.Default, bool directRendering = true, WGLOpenGLContext shareContext = null) : base(framebufferFormat, major, minor, flags, directRendering, shareContext) { _deviceContext = IntPtr.Zero; _window = null; }
public static IntPtr CreateContext(ref IntPtr windowHandle, FramebufferFormat framebufferFormat, int major, int minor, OpenGLContextFlags flags, bool directRendering, IntPtr shareContext) { EnsureInit(); bool hasTempWindow = windowHandle == IntPtr.Zero; if (hasTempWindow) { windowHandle = Win32Helper.CreateNativeWindow(WindowStylesEx.WS_EX_OVERLAPPEDWINDOW, WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN, "SPB intermediary context", 0, 0, 1, 1); } IntPtr dcHandle = GetDC(windowHandle); int pixelFormat = FindClosestFormat(dcHandle, framebufferFormat); if (pixelFormat == -1) { throw new PlatformException("Cannot find a valid pixel format"); } PixelFormatDescriptor pfd = PixelFormatDescriptor.Create(); int res = DescribePixelFormat(dcHandle, pixelFormat, Marshal.SizeOf <PixelFormatDescriptor>(), ref pfd); if (res == 0) { throw new PlatformException($"DescribePixelFormat failed: {Marshal.GetLastWin32Error()}"); } res = SetPixelFormat(dcHandle, pixelFormat, ref pfd); if (res == 0) { throw new PlatformException($"DescribePixelFormat failed: {Marshal.GetLastWin32Error()}"); } List <int> contextAttributes = GetContextCreationARBAttribute(major, minor, flags); IntPtr context = CreateContextAttribsArb(dcHandle, shareContext, contextAttributes.ToArray()); if (hasTempWindow) { DestroyWindow(windowHandle); } return(context); }
private static List <int> GetContextCreationARBAttribute(int major, int minor, OpenGLContextFlags flags) { List <int> result = new List <int>(); result.Add((int)WGL.ARB.CreateContext.MAJOR_VERSION); result.Add(major); result.Add((int)WGL.ARB.CreateContext.MINOR_VERSION); result.Add(minor); if (flags != 0) { if (flags.HasFlag(OpenGLContextFlags.Debug)) { result.Add((int)WGL.ARB.CreateContext.FLAGS); result.Add((int)WGL.ARB.ContextFlags.DEBUG_BIT); } result.Add((int)WGL.ARB.CreateContext.PROFILE_MASK); if (flags.HasFlag(OpenGLContextFlags.Compat)) { result.Add((int)WGL.ARB.ContextProfileFlags.COMPATIBILITY_PROFILE); } else { result.Add((int)WGL.ARB.ContextProfileFlags.CORE_PROFILE); } } // NOTE: Format is key: value, nothing in the spec specify if the end marker follow or not this format. // BODY: As such, we add an extra 0 just to be sure we don't break anything. result.Add(0); result.Add(0); return(result); }