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 static SPBOpenGLContext CreateBackgroundContext(OpenGLContextBase sharedContext) { OpenGLContextBase context = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, 3, 3, OpenGLContextFlags.Compat, true, sharedContext); NativeWindowBase window = PlatformHelper.CreateWindow(FramebufferFormat.Default, 0, 0, 100, 100); context.Initialize(window); context.MakeCurrent(window); GL.LoadBindings(new OpenToolkitBindingsContext(context)); context.MakeCurrent(null); return(new SPBOpenGLContext(context, window)); }
protected override void CreateWindow() { var flags = OpenGLContextFlags.Compat; if (DebugLevel != GraphicsDebugLevel.None) { flags |= OpenGLContextFlags.Debug; } _gameBackgroundWindow = PlatformHelper.CreateOpenGLWindow(FramebufferFormat.Default, 0, 0, 100, 100); _gameBackgroundWindow.Hide(); GameContext = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, Major, Minor, flags, shareContext: PrimaryContext); GameContext.Initialize(_gameBackgroundWindow); }
private void IntializeOpenGL() { _nativeWindow = RetrieveNativeWindow(); Window.EnsureNative(); _openGLContext = PlatformHelper.CreateOpenGLContext(GetGraphicsMode(), 3, 3, _glLogLevel == GraphicsDebugLevel.None ? OpenGLContextFlags.Compat : OpenGLContextFlags.Compat | OpenGLContextFlags.Debug); _openGLContext.Initialize(_nativeWindow); _openGLContext.MakeCurrent(_nativeWindow); // Release the GL exclusivity that SPB gave us as we aren't going to use it in GTK Thread. _openGLContext.MakeCurrent(null); WaitEvent.Set(); _initializedOpenGL = true; }
public static List <int> GetContextCreationARBAttribute(OpenGLContextBase context) { List <int> result = new List <int>(); result.Add((int)GLX.ARB.CreateContext.MAJOR_VERSION); result.Add(context.Major); result.Add((int)GLX.ARB.CreateContext.MINOR_VERSION); result.Add(context.Minor); if (context.Flags != 0) { if (context.Flags.HasFlag(OpenGLContextFlags.Debug)) { result.Add((int)GLX.ARB.CreateContext.FLAGS); result.Add((int)GLX.ARB.ContextFlags.DEBUG_BIT); } result.Add((int)GLX.ARB.CreateContext.PROFILE_MASK); if (context.Flags.HasFlag(OpenGLContextFlags.Compat)) { result.Add((int)GLX.ARB.ContextProfileFlags.COMPATIBILITY_PROFILE); } else { result.Add((int)GLX.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); }
static void Main(string[] args) { NativeWindowBase window = PlatformHelper.CreateWindow(FramebufferFormat.Default, 0, 0, 250, 250); OpenGLContextBase context = PlatformHelper.CreateOpenGLContext(FramebufferFormat.Default, 3, 3, OpenGLContextFlags.Compat); context.Initialize(window); context.MakeCurrent(window); GL.LoadBindings(new OpenToolkitBindingsContext(context)); window.Show(); GL.ClearColor(1.0f, 0.5f, 1.0f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit); window.SwapBuffers(); Console.WriteLine($"OpenGL vendor: {GL.GetString(StringName.Vendor)}"); Console.WriteLine($"OpenGL version: {GL.GetString(StringName.Version)}"); Console.WriteLine($"OpenGL renderer: {GL.GetString(StringName.Renderer)}"); Console.WriteLine($"OpenGL context profile mask: {GL.GetInteger((GetPName)All.ContextProfileMask)}"); Console.WriteLine($"OpenGL context flags: {GL.GetInteger((GetPName)All.ContextFlags)}"); Thread.Sleep(2000); window.Dispose(); Console.WriteLine($"Dispose OpenGL context!"); context.Dispose(); string vendor2 = GL.GetString(StringName.Vendor); Console.WriteLine($"OpenGL vendor: {vendor2}"); window.Dispose(); }
private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window) { _context = context; _window = window; }
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(); }