public bool NeedPresentThread => FrameFactory.getcurrentfunc == null && Xwt.Toolkit.CurrentEngine.Type != ToolkitType.Wpf;//only mac and wpf have auto present for gtk public FrameFactory(Func <IntPtr> getcurrentfunc) { try { var options = new ToolkitOptions() { EnableHighResolution = true }; options.Backend = PlatformBackend.PreferNative; this.toolkit = global::OpenTK.Toolkit.Init(options); if (getcurrentfunc != null) { FrameFactory._getcurrentfunc = getcurrentfunc; FrameFactory.getcurrentfunc = new GraphicsContext.GetCurrentContextDelegate(() => new ContextHandle(getcurrentfunc())); typeof(GraphicsContext).SetFieldValuePrivateStatic("GetCurrentContext", FrameFactory.getcurrentfunc); } } catch (Exception e) { // Log.LogException(e); throw; } }
public OpenGLESRenderContext(Window window, OpenGLPlatformContextInfo platformContext) { ResourceFactory = new OpenGLESResourceFactory(); RenderCapabilities = new RenderCapabilities(false, false); _swapBufferFunc = platformContext.SwapBuffer; GraphicsContext.GetAddressDelegate getAddressFunc = s => platformContext.GetProcAddress(s); GraphicsContext.GetCurrentContextDelegate getCurrentContextFunc = () => new ContextHandle(platformContext.GetCurrentContext()); _openGLGraphicsContext = new GraphicsContext(new ContextHandle(platformContext.ContextHandle), getAddressFunc, getCurrentContextFunc); _openGLGraphicsContext.LoadAll(); _defaultFramebuffer = new OpenGLESDefaultFramebuffer(window.Width, window.Height); OnWindowResized(window.Width, window.Height); _textureSamplerManager = new OpenGLESTextureSamplerManager(); _maxConstantBufferSlots = GL.GetInteger(GetPName.MaxUniformBufferBindings); Utilities.CheckLastGLES3Error(); _constantBuffersBySlot = new OpenGLESConstantBuffer[_maxConstantBufferSlots]; _newConstantBuffersBySlot = new OpenGLESConstantBuffer[_maxConstantBufferSlots]; SetInitialStates(); PostContextCreated(); }
public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) { lock (GraphicsContext.SyncRoot) { bool local_0 = false; if (mode == null && window == null) { local_0 = true; } else { if (mode == null) { throw new ArgumentNullException("mode", "Must be a valid GraphicsMode."); } if (window == null) { throw new ArgumentNullException("window", "Must point to a valid window."); } } if (major <= 0) { major = 1; } if (minor < 0) { minor = 0; } IGraphicsContext local_1_1 = GraphicsContext.FindSharedContext(); if (local_0) { this.implementation = (IGraphicsContext) new DummyGLContext(); } else { IPlatformFactory local_2 = (IPlatformFactory)null; switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) { case false: local_2 = Factory.Default; break; case true: local_2 = Factory.Embedded; break; } this.implementation = local_2.CreateGLContext(mode, window, local_1_1, GraphicsContext.direct_rendering, major, minor, flags); if (GraphicsContext.GetCurrentContext == null) { GraphicsContext.GetCurrentContextDelegate local_3 = local_2.CreateGetCurrentGraphicsContext(); if (local_3 != null) { GraphicsContext.GetCurrentContext = local_3; } } } GraphicsContext.available_contexts.Add(this.Context, new WeakReference((object)this)); } }
public OpenGLRenderContext(Window window, OpenGLPlatformContextInfo platformContext) { _resourceFactory = new OpenGLResourceFactory(); RenderCapabilities = new RenderCapabilities(true, true); _swapBufferFunc = platformContext.SwapBuffer; GraphicsContext.GetAddressDelegate getAddressFunc = s => platformContext.GetProcAddress(s); GraphicsContext.GetCurrentContextDelegate getCurrentContextFunc = () => new ContextHandle(platformContext.GetCurrentContext()); _openGLGraphicsContext = new GraphicsContext(new ContextHandle(platformContext.ContextHandle), getAddressFunc, getCurrentContextFunc); _openGLGraphicsContext.LoadAll(); // NOTE: I am binding a single VAO globally. _vertexArrayID = GL.GenVertexArray(); GL.BindVertexArray(_vertexArrayID); _defaultFramebuffer = new OpenGLDefaultFramebuffer(window.Width, window.Height); OnWindowResized(window.Width, window.Height); SetInitialStates(); PostContextCreated(); int extensionCount = GL.GetInteger(GetPName.NumExtensions); HashSet <string> extensions = new HashSet <string>(); for (int i = 0; i < extensionCount; i++) { extensions.Add(GL.GetString(StringNameIndexed.Extensions, i)); } _extensions = new OpenGLExtensions(extensions); _textureSamplerManager = new OpenGLTextureSamplerManager(_extensions); _maxConstantBufferSlots = GL.GetInteger(GetPName.MaxUniformBufferBindings); _constantBuffersBySlot = new OpenGLConstantBuffer[_maxConstantBufferSlots]; _newConstantBuffersBySlot = new OpenGLConstantBuffer[_maxConstantBufferSlots]; _maxTextureUnits = GL.GetInteger(GetPName.MaxTextureImageUnits); _maxVertexAttributeSlots = GL.GetInteger(GetPName.MaxVertexAttribs); _vertexAttribDivisors = new int[_maxVertexAttributeSlots]; }
public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) { lock (GraphicsContext.SyncRoot) { bool local_0 = false; if (mode == null && window == null) { local_0 = true; } else { if (mode == null) throw new ArgumentNullException("mode", "Must be a valid GraphicsMode."); if (window == null) throw new ArgumentNullException("window", "Must point to a valid window."); } if (major <= 0) major = 1; if (minor < 0) minor = 0; IGraphicsContext local_1_1 = GraphicsContext.FindSharedContext(); if (local_0) { this.implementation = (IGraphicsContext) new DummyGLContext(); } else { IPlatformFactory local_2 = (IPlatformFactory) null; switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) { case false: local_2 = Factory.Default; break; case true: local_2 = Factory.Embedded; break; } this.implementation = local_2.CreateGLContext(mode, window, local_1_1, GraphicsContext.direct_rendering, major, minor, flags); if (GraphicsContext.GetCurrentContext == null) { GraphicsContext.GetCurrentContextDelegate local_3 = local_2.CreateGetCurrentGraphicsContext(); if (local_3 != null) GraphicsContext.GetCurrentContext = local_3; } } GraphicsContext.available_contexts.Add(this.Context, new WeakReference((object) this)); } }