From 7b795a02e108ad272138a355557865238f0d2b26 Mon Sep 17 00:00:00 2001 From: Jonas Boesch Date: Tue, 21 Apr 2015 16:08:20 +0200 Subject: [PATCH 1/7] Bugfix: Non-null shared contexts for Egl threw Exception The shared context parameter can be either the EglContext directly, or the facade, and we cast to see what it is. --- src/OpenTK/Platform/Egl/EglContext.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/OpenTK/Platform/Egl/EglContext.cs b/src/OpenTK/Platform/Egl/EglContext.cs index b6cca8f9..2844686d 100644 --- a/src/OpenTK/Platform/Egl/EglContext.cs +++ b/src/OpenTK/Platform/Egl/EglContext.cs @@ -53,6 +53,8 @@ namespace OpenTK.Platform.Egl if (window == null) throw new ArgumentNullException("window"); + EglContext shared = GetSharedEglContext(sharedContext); + WindowInfo = window; // Select an EGLConfig that matches the desired mode. We cannot use the 'mode' @@ -216,6 +218,21 @@ namespace OpenTK.Platform.Egl } } + private EglContext GetSharedEglContext(IGraphicsContext sharedContext) + { + if (sharedContext == null) + { + return null; + } + + var internalContext = sharedContext as IGraphicsContextInternal; + if (internalContext != null) + { + return (EglContext) internalContext.Implementation; + } + return (EglContext) sharedContext; + } + #endregion } } From df66598182e4a24e4d9f68a6218dcd95e070d605 Mon Sep 17 00:00:00 2001 From: Jonas Boesch Date: Tue, 21 Apr 2015 16:08:50 +0200 Subject: [PATCH 2/7] Added Angle-related enums and definitions + GraphicsContextFlags now has Angle and Offscreen flags. + Egl now has PLATFORM_ANGLE related const ints. + Added eglGetPlatformDisplayEXT p/invoke definition + Added eglQuerySurfacePointerANGLE p/invoke definition + EglWindowInfo.CreatePbufferSurface was commented out. Enabled and fixed it. + GraphicsContextFlags.Offscreen will make the context create a PbufferSurface instead of a WindowSurface in EglContext + SurfaceType enum to select surface type for SelectGraphicsMode --- Source/OpenTK/Platform/Egl/EglAngle.cs | 42 ++++++++++++++ src/OpenTK/Graphics/GraphicsContext.cs | 12 ++++ src/OpenTK/Graphics/GraphicsContextFlags.cs | 26 ++++++++- src/OpenTK/OpenTK.csproj | 1 + src/OpenTK/Platform/Egl/Egl.cs | 11 ++++ src/OpenTK/Platform/Egl/EglContext.cs | 41 +++++++++++--- src/OpenTK/Platform/Egl/EglGraphicsMode.cs | 17 +++++- src/OpenTK/Platform/Egl/EglWindowInfo.cs | 62 ++++++++++++++++++--- 8 files changed, 192 insertions(+), 20 deletions(-) create mode 100644 Source/OpenTK/Platform/Egl/EglAngle.cs diff --git a/Source/OpenTK/Platform/Egl/EglAngle.cs b/Source/OpenTK/Platform/Egl/EglAngle.cs new file mode 100644 index 00000000..9cf708e8 --- /dev/null +++ b/Source/OpenTK/Platform/Egl/EglAngle.cs @@ -0,0 +1,42 @@ +using System; +using System.Runtime.InteropServices; + +namespace OpenTK.Platform.Egl +{ + using EGLDisplay = IntPtr; + using EGLNativeDisplayType = IntPtr; + using EGLSurface = IntPtr; + using ShareHandle = IntPtr; + + static partial class Egl + { + // See + // - ANGLE_platform_angle + // - ANGLE_platform_angle_d3d + // - ANGLE_platform_angle_opengl + public const int PLATFORM_ANGLE = 0x3202; + public const int PLATFORM_ANGLE_TYPE = 0x3203; + public const int PLATFORM_ANGLE_MAX_VERSION_MAJOR = 0x3204; + public const int PLATFORM_ANGLE_MAX_VERSION_MINOR = 0x3205; + public const int PLATFORM_ANGLE_TYPE_DEFAULT = 0x3206; + public const int PLATFORM_ANGLE_TYPE_D3D9 = 0x3207; + public const int PLATFORM_ANGLE_TYPE_D3D11 = 0x3208; + public const int PLATFORM_ANGLE_DEVICE_TYPE = 0x3209; + public const int PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE = 0x320A; + public const int PLATFORM_ANGLE_DEVICE_TYPE_WARP = 0x320B; + public const int PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE = 0x320C; + public const int PLATFORM_ANGLE_TYPE_OPENGL = 0x320D; + public const int PLATFORM_ANGLE_TYPE_OPENGLES = 0x320E; + // See EGL_ANGLE_surface_d3d_texture_2d_share_handle + public const int EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200; + + [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")] + public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType display_id, + int[] attrib_list); + + [DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")] + public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, + int attribute, out IntPtr value); + + } +} \ No newline at end of file diff --git a/src/OpenTK/Graphics/GraphicsContext.cs b/src/OpenTK/Graphics/GraphicsContext.cs index d12e360f..35a5d354 100644 --- a/src/OpenTK/Graphics/GraphicsContext.cs +++ b/src/OpenTK/Graphics/GraphicsContext.cs @@ -112,6 +112,18 @@ namespace OpenTK.Graphics if (minor < 0) minor = 0; + // Angle needs an embedded context + var use_angle_flag = GraphicsContextFlags.Angle + | GraphicsContextFlags.AngleD3D9 + | GraphicsContextFlags.AngleD3D11 + | GraphicsContextFlags.AngleOpenGL; + var use_angle = false; + if ((flags & use_angle_flag) != 0) + { + flags |= GraphicsContextFlags.Embedded; + use_angle = true; + } + Debug.Print("Creating GraphicsContext."); try { diff --git a/src/OpenTK/Graphics/GraphicsContextFlags.cs b/src/OpenTK/Graphics/GraphicsContextFlags.cs index a7ee2f59..a7df6e16 100644 --- a/src/OpenTK/Graphics/GraphicsContextFlags.cs +++ b/src/OpenTK/Graphics/GraphicsContextFlags.cs @@ -56,6 +56,30 @@ namespace OpenTK.Graphics /// /// Indicates that this GraphicsContext is targeting OpenGL|ES. /// - Embedded = 0x0004 + Embedded = 0x0004, + /// + /// Indicates that this GraphicsContext is intended for offscreen rendering. + /// + Offscreen = 0x0008, + /// + /// Indicates that this GraphicsContext is targeting OpenGL|ES via Angle + /// and that angle-specific extensions are available. + /// + Angle = 0x0010, + /// + /// Indicates that this GraphicsContext is targeting OpenGL|ES via Angle + /// and uses Direct3D9 as rendering backend. + /// + AngleD3D9 = 0x0020, + /// + /// Indicates that this GraphicsContext is targeting OpenGL|ES via Angle + /// and uses Direct3D11 as rendering backend. + /// + AngleD3D11 = 0x0040, + /// + /// Indicates that this GraphicsContext is targeting OpenGL|ES via Angle + /// and uses OpenGL as rendering backend. + /// + AngleOpenGL = 0x0080, } } diff --git a/src/OpenTK/OpenTK.csproj b/src/OpenTK/OpenTK.csproj index aaa09898..14760545 100644 --- a/src/OpenTK/OpenTK.csproj +++ b/src/OpenTK/OpenTK.csproj @@ -134,6 +134,7 @@ + diff --git a/src/OpenTK/Platform/Egl/Egl.cs b/src/OpenTK/Platform/Egl/Egl.cs index 118054d1..df395812 100644 --- a/src/OpenTK/Platform/Egl/Egl.cs +++ b/src/OpenTK/Platform/Egl/Egl.cs @@ -78,6 +78,17 @@ namespace OpenTK.Platform.Egl CONTEXT_LOST = 12302, } + enum SurfaceType + { + PBUFFER_BIT = 0x0001, + PIXMAP_BIT = 0x0002, + WINDOW_BIT = 0x0004, + VG_COLORSPACE_LINEAR_BIT = 0x0020, + VG_ALPHA_FORMAT_PRE_BIT = 0x0040, + MULTISAMPLE_RESOLVE_BOX_BIT = 0x0200, + SWAP_BEHAVIOR_PRESERVED_BIT = 0x0400, + } + static partial class Egl { public const int VERSION_1_0 = 1; diff --git a/src/OpenTK/Platform/Egl/EglContext.cs b/src/OpenTK/Platform/Egl/EglContext.cs index 2844686d..76992c92 100644 --- a/src/OpenTK/Platform/Egl/EglContext.cs +++ b/src/OpenTK/Platform/Egl/EglContext.cs @@ -28,6 +28,7 @@ using System; using System.Diagnostics; using OpenTK.Graphics; +using OpenTK.Graphics.ES20; namespace OpenTK.Platform.Egl { @@ -36,9 +37,11 @@ namespace OpenTK.Platform.Egl #region Fields protected readonly RenderableFlags Renderable; - protected EglWindowInfo WindowInfo; + internal EglWindowInfo WindowInfo; - IntPtr HandleAsEGLContext { get { return Handle.Handle; } set { Handle = new ContextHandle(value); } } + internal GraphicsContextFlags GraphicsContextFlags { get; set; } + + internal IntPtr HandleAsEGLContext { get { return Handle.Handle; } set { Handle = new ContextHandle(value); } } int swap_interval = 1; // Default interval is defined as 1 in EGL. #endregion @@ -85,19 +88,38 @@ namespace OpenTK.Platform.Egl Debug.Print("[EGL] Failed to bind rendering API. Error: {0}", Egl.GetError()); } - Mode = new EglGraphicsMode().SelectGraphicsMode(window, - mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, - mode.AccumulatorFormat, mode.Buffers, mode.Stereo, - Renderable); + bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0; + + SurfaceType surface_type = offscreen + ? SurfaceType.PBUFFER_BIT + : SurfaceType.WINDOW_BIT; + + Mode = new EglGraphicsMode().SelectGraphicsMode(surface_type, + window.Display, mode.ColorFormat, mode.Depth, mode.Stencil, + mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, + Renderable); + if (!Mode.Index.HasValue) throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); IntPtr config = Mode.Index.Value; if (window.Surface == IntPtr.Zero) - window.CreateWindowSurface(config); + { + if (!offscreen) + { + window.CreateWindowSurface(config); + } + else + { + window.CreatePbufferSurface(config); + } + } int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; - HandleAsEGLContext = Egl.CreateContext(window.Display, config, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, attrib_list); + var share_context = shared != null ? shared.HandleAsEGLContext : IntPtr.Zero; + HandleAsEGLContext = Egl.CreateContext(window.Display, config, share_context, attrib_list); + + GraphicsContextFlags = flags; } public EglContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext, @@ -133,6 +155,9 @@ namespace OpenTK.Platform.Egl { if (window is EglWindowInfo) WindowInfo = (EglWindowInfo) window; + else if (window is IAngleWindowInfoInternal) + WindowInfo = ((IAngleWindowInfoInternal) window).EglWindowInfo; + if (!Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext)) { throw new GraphicsContextException(string.Format("Failed to make context {0} current. Error: {1}", Handle, Egl.GetError())); diff --git a/src/OpenTK/Platform/Egl/EglGraphicsMode.cs b/src/OpenTK/Platform/Egl/EglGraphicsMode.cs index 779e8ff2..682caf3e 100644 --- a/src/OpenTK/Platform/Egl/EglGraphicsMode.cs +++ b/src/OpenTK/Platform/Egl/EglGraphicsMode.cs @@ -47,11 +47,23 @@ namespace OpenTK.Platform.Egl ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderable_flags) + { + return SelectGraphicsMode( + SurfaceType.WINDOW_BIT, + window.Display, + color, depth, stencil, samples, accum, buffers, stereo, renderable_flags + ); + } + + public GraphicsMode SelectGraphicsMode(SurfaceType surface_type, + IntPtr display, ColorFormat color, int depth, int stencil, + int samples, ColorFormat accum, int buffers, bool stereo, + RenderableFlags renderable_flags) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { - Egl.SURFACE_TYPE, Egl.WINDOW_BIT, + Egl.SURFACE_TYPE, (int) surface_type, Egl.RENDERABLE_TYPE, (int)renderable_flags, Egl.RED_SIZE, color.Red, @@ -68,8 +80,6 @@ namespace OpenTK.Platform.Egl Egl.NONE, }; - IntPtr display = window.Display; - int num_configs; if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs) || num_configs == 0) { @@ -92,5 +102,6 @@ namespace OpenTK.Platform.Egl return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false); } + } } diff --git a/src/OpenTK/Platform/Egl/EglWindowInfo.cs b/src/OpenTK/Platform/Egl/EglWindowInfo.cs index 10f495be..db73aa3d 100644 --- a/src/OpenTK/Platform/Egl/EglWindowInfo.cs +++ b/src/OpenTK/Platform/Egl/EglWindowInfo.cs @@ -98,20 +98,66 @@ namespace OpenTK.Platform.Egl public void CreatePbufferSurface(IntPtr config) { - Surface = Egl.CreatePbufferSurface(Display, config, null); + int[] attribs = new int[]{Egl.NONE}; + Surface = Egl.CreatePbufferSurface(Display, config, attribs); + if (Surface == IntPtr.Zero) + { + throw new GraphicsContextException(String.Format( + "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); + } + } + + public void CreatePbufferSurface(IntPtr config, int width, int height) + { + if (surface != IntPtr.Zero) + { + DestroySurface(); + } + CreatePbufferSurface(config, width, height, out surface); + } + + public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr surface_) + { + int[] attribs = new int[] + { + Egl.WIDTH, width, + Egl.HEIGHT, height, + Egl.TEXTURE_TARGET, Egl.TEXTURE_2D, + Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA, + Egl.NONE + }; + surface_ = Egl.CreatePbufferSurface(Display, config, attribs); + if (surface_ == IntPtr.Zero) + { + throw new GraphicsContextException(String.Format( + "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); + } + } public void DestroySurface() { - if (Surface != IntPtr.Zero) - { - if (Egl.GetCurrentSurface(Egl.DRAW) == Surface) - Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + DestroySurface(ref surface); + } - if (!Egl.DestroySurface(Display, Surface)) - Debug.Print("[Warning] Failed to destroy {0}:{1}.", Surface.GetType().Name, Surface); - Surface = IntPtr.Zero; + public void DestroySurface(ref IntPtr surface_) + { + if (surface_ == IntPtr.Zero) + { + return; } + + if (Egl.GetCurrentSurface(Egl.DRAW) == Surface) + Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + + if (Egl.DestroySurface(Display, surface_)) + { + surface_ = IntPtr.Zero; + return; + } + + Debug.Print("[Warning] Failed to destroy {0}:{1}.", Surface.GetType().Name, Surface); + Surface = IntPtr.Zero; } public void TerminateDisplay() From 9d29c8c19bbfa6cc5231c7f82f1333f36b2724c9 Mon Sep 17 00:00:00 2001 From: Jonas Boesch Date: Tue, 21 Apr 2015 16:09:29 +0200 Subject: [PATCH 3/7] Added AngleWindowInfo and AnglePlatformFactory Both WindowInfo and PlatformFactory wrap the actual platform-specific WindowInfo and PlatformFactory. For offscreen rendering, AngleWindowInfo can be used with a DummyWindowInfo. The API to add additional surfaces was added to IAngleWindowInfo, since all those calls need the Display parameter that is only available on EglWindowInfo (which is not exposed to users). --- Source/OpenTK/Platform/Egl/AngleWindowInfo.cs | 183 ++++++++++++++++++ .../Platform/Egl/EglAnglePlatformFactory.cs | 172 ++++++++++++++++ src/OpenTK/Graphics/GraphicsContext.cs | 8 +- src/OpenTK/OpenTK.csproj | 2 + src/OpenTK/Platform/Factory.cs | 11 +- src/OpenTK/Platform/Utilities.cs | 17 ++ 6 files changed, 390 insertions(+), 3 deletions(-) create mode 100644 Source/OpenTK/Platform/Egl/AngleWindowInfo.cs create mode 100644 Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs diff --git a/Source/OpenTK/Platform/Egl/AngleWindowInfo.cs b/Source/OpenTK/Platform/Egl/AngleWindowInfo.cs new file mode 100644 index 00000000..f062a2d4 --- /dev/null +++ b/Source/OpenTK/Platform/Egl/AngleWindowInfo.cs @@ -0,0 +1,183 @@ +using System; +using OpenTK.Graphics; +using OpenTK.Platform.Windows; + +namespace OpenTK.Platform.Egl +{ + using EGLSurface = IntPtr; + /// + /// A window info for angle. + /// + public interface IAngleWindowInfo : IWindowInfo + { + /// + /// Query the underlying platform pointer / handle for this window's + /// default surface or IntPtr.Zero + /// + IntPtr QuerySurfacePointer(); + /// + /// Create an additional rendering surface that shares the display + /// of this window. + /// + /// width in pixels + /// height in pixels + /// A reference to the new surface + EGLSurface CreateSurface(int width, int height); + /// + /// Destroy a surface created with CreateSurface and clears the passed reference. + /// + /// Reference to the surface. + void DestroySurface(ref EGLSurface surface); + /// + /// MakeCurrent the custom surface created with CreateSurface. + /// + /// Reference to the surface. + void MakeCurrent(EGLSurface surface); + /// + /// Query the underlying platform pointer / handle for an EGLSurface + /// created with CreateSurface. + /// + /// + IntPtr QuerySurfacePointer(EGLSurface surface); + } + + internal interface IAngleWindowInfoInternal : IAngleWindowInfo + { + IWindowInfo PlatformWindow { get; } + IntPtr Display { get; } + IntPtr Surface { get; } + EglContext EglContext { get; set; } + EglWindowInfo EglWindowInfo { get; set; } + IntPtr DeviceContext { get; } + } + + internal class AngleWindowInfo : IAngleWindowInfoInternal + { + private readonly IWindowInfo _platform_window; + private bool _disposed; + + public AngleWindowInfo(IWindowInfo platform_window) + { + _platform_window = platform_window; + } + + public IWindowInfo PlatformWindow + { + get { return _platform_window; } + } + + public IWindowInfo WindowInfo + { + get { return EglWindowInfo; } + } + + public IntPtr DeviceContext + { + get + { + var win_win = _platform_window as WinWindowInfo; + if (win_win != null) + { + return win_win.DeviceContext; + } + return IntPtr.Zero; + } + } + + public EglContext EglContext { get; set; } + public EglWindowInfo EglWindowInfo { get; set; } + + public IntPtr Display + { + get { return EglWindowInfo.Display; } + } + + public IntPtr Surface + { + get { return EglWindowInfo.Surface; } + } + + public void Dispose() + { + Dispose(false); + } + + public IntPtr Handle + { + get { return _platform_window.Handle; } + } + + ~AngleWindowInfo() + { + Dispose(true); + } + + private void Dispose(bool called_from_finalizer) + { + if (_disposed) + { + return; + } + if (!called_from_finalizer) + { + _platform_window.Dispose(); + } + // dispose unmanaged + + _disposed = true; + GC.SuppressFinalize(this); + } + + public IntPtr QuerySurfacePointer() + { + return QuerySurfacePointer(Surface); + } + + public EGLSurface CreateSurface(int width, int height) + { + IntPtr surface; + EglWindowInfo.CreatePbufferSurface( + EglContext.GraphicsMode.Index.Value, + width, height, + out surface); + return surface; + } + + public void DestroySurface(ref EGLSurface surface) + { + EglWindowInfo.DestroySurface(ref surface); + } + + public void MakeCurrent(EGLSurface surface) + { + Egl.MakeCurrent(Display, surface, surface, EglContext.HandleAsEGLContext); + } + + public IntPtr QuerySurfacePointer(IntPtr surface) + { + if (UsesDirect3DBackend()) + { + return QuerySurfacePointer(surface, + Egl.EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE); + } + return IntPtr.Zero; + } + + private IntPtr QuerySurfacePointer(IntPtr surface, int attrib) + { + IntPtr surface_pointer; + if (Egl.QuerySurfacePointerANGLE( + Display, surface, attrib, out surface_pointer)) + { + return surface_pointer; + } + return IntPtr.Zero; + } + + private bool UsesDirect3DBackend() + { + var d3d_flags = GraphicsContextFlags.AngleD3D9 | GraphicsContextFlags.AngleD3D11; + return ((EglContext.GraphicsContextFlags & d3d_flags) != 0); + } + } +} \ No newline at end of file diff --git a/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs b/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs new file mode 100644 index 00000000..6d5f694d --- /dev/null +++ b/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs @@ -0,0 +1,172 @@ +#region License + +// +// The Open Toolkit Library License +// +// Copyright (c) 2006 - 2015 the Open Toolkit library. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do +// so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +#endregion + +using System; +using OpenTK.Graphics; +using OpenTK.Input; + +namespace OpenTK.Platform.Egl +{ + internal class EglAnglePlatformFactory : PlatformFactoryBase + { + private readonly IPlatformFactory _platform_factory; + #region Public Members + + public EglAnglePlatformFactory(IPlatformFactory platform_factory) + { + _platform_factory = platform_factory; + } + + public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, + GameWindowFlags options, DisplayDevice device) + { + return _platform_factory.CreateNativeWindow(x, y, width, height, title, + mode, options, device); + } + + public override IDisplayDeviceDriver CreateDisplayDeviceDriver() + { + return _platform_factory.CreateDisplayDeviceDriver(); + } + + public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, + IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) + { + var angle_window = (IAngleWindowInfoInternal) window; + var egl_window = CreateWindowInfo(angle_window, major, flags); + var egl_context = new EglWinContext(mode, egl_window, shareContext, major, minor, flags); + angle_window.EglContext = egl_context; + return egl_context; + } + + public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, + IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) + { + var angle_window = (IAngleWindowInfoInternal) window; + var egl_window = CreateWindowInfo(angle_window, major, flags); + var egl_context = new EglWinContext(handle, egl_window, shareContext, major, minor, flags); + angle_window.EglContext = egl_context; + return egl_context; + } + + public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() + { + return (GraphicsContext.GetCurrentContextDelegate)delegate + { + return new ContextHandle(Platform.Egl.Egl.GetCurrentContext()); + }; + } + + public override IKeyboardDriver2 CreateKeyboardDriver() + { + return _platform_factory.CreateKeyboardDriver(); + } + + public override IMouseDriver2 CreateMouseDriver() + { + return _platform_factory.CreateMouseDriver(); + } + + public override IJoystickDriver2 CreateJoystickDriver() + { + return _platform_factory.CreateJoystickDriver(); + } + + #endregion + + #region Private Members + + private static bool FlagEnabled(GraphicsContextFlags flags, GraphicsContextFlags flag) + { + return (flags & flag) != 0; + } + + private EglWindowInfo CreateWindowInfo(IAngleWindowInfoInternal window_info, + int major, GraphicsContextFlags flags) + { + var egl_display = GetAngleDisplay(window_info.DeviceContext, flags, major); + var egl_window = new EglWindowInfo(window_info.Handle, egl_display); + window_info.EglWindowInfo = egl_window; + return egl_window; + } + + private IntPtr GetAngleDisplay(IntPtr dc, GraphicsContextFlags flags, int major) + { + // default to D3D9 for ES2, but use D3D11 for ES3 as required by Angle. + var platform_type = major == 2 + ? Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9 + : Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11; + if (FlagEnabled(flags, GraphicsContextFlags.AngleD3D11)) + { + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11; + } + else if (FlagEnabled(flags, GraphicsContextFlags.AngleD3D9)) + { + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9; + } + else if (FlagEnabled(flags, GraphicsContextFlags.AngleOpenGL)) + { + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL; + } + else + { + // make sure the correct flag is set. + switch (platform_type) + { + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9: + flags |= GraphicsContextFlags.AngleD3D9; + break; + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11: + flags |= GraphicsContextFlags.AngleD3D11; + break; + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL: + flags |= GraphicsContextFlags.AngleOpenGL; + break; + } + } + + var attribs = new[] + { + Platform.Egl.Egl.PLATFORM_ANGLE_TYPE, platform_type, + Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MAJOR, Platform.Egl.Egl.DONT_CARE, + Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MINOR, Platform.Egl.Egl.DONT_CARE, + Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE, Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE, + Platform.Egl.Egl.NONE + }; + + return Platform.Egl.Egl.GetPlatformDisplay( + Platform.Egl.Egl.PLATFORM_ANGLE, + dc, + attribs + ); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/OpenTK/Graphics/GraphicsContext.cs b/src/OpenTK/Graphics/GraphicsContext.cs index 35a5d354..da3c9f6a 100644 --- a/src/OpenTK/Graphics/GraphicsContext.cs +++ b/src/OpenTK/Graphics/GraphicsContext.cs @@ -145,8 +145,12 @@ namespace OpenTK.Graphics IPlatformFactory factory = null; switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) { - case false: factory = Factory.Default; break; - case true: factory = Factory.Embedded; break; + case false: + factory = Factory.Default; + break; + case true: + factory = use_angle ? Factory.Angle : Factory.Embedded; + break; } // Note: this approach does not allow us to mix native and EGL contexts in the same process. diff --git a/src/OpenTK/OpenTK.csproj b/src/OpenTK/OpenTK.csproj index 14760545..758e53a8 100644 --- a/src/OpenTK/OpenTK.csproj +++ b/src/OpenTK/OpenTK.csproj @@ -133,10 +133,12 @@ + + diff --git a/src/OpenTK/Platform/Factory.cs b/src/OpenTK/Platform/Factory.cs index 9e5eb668..35839e08 100644 --- a/src/OpenTK/Platform/Factory.cs +++ b/src/OpenTK/Platform/Factory.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; +using OpenTK.Platform.Egl; namespace OpenTK.Platform { @@ -40,7 +41,7 @@ namespace OpenTK.Platform #region Fields bool disposed; - static IPlatformFactory default_implementation, embedded_implementation; + static IPlatformFactory default_implementation, embedded_implementation, angle_implementation; #endregion @@ -102,11 +103,13 @@ namespace OpenTK.Platform else if (Configuration.RunningOnAndroid) Embedded = new Android.AndroidFactory(); #endif else Embedded = new UnsupportedPlatform(); + Angle = new EglAnglePlatformFactory(Embedded); } #endif else { Embedded = new UnsupportedPlatform(); + Angle = Embedded; } if (Default is UnsupportedPlatform && !(Embedded is UnsupportedPlatform)) @@ -129,6 +132,12 @@ namespace OpenTK.Platform private set { embedded_implementation = value; } } + public static IPlatformFactory Angle + { + get { return angle_implementation; } + private set { angle_implementation = value; } + } + #endregion #region IPlatformFactory Members diff --git a/src/OpenTK/Platform/Utilities.cs b/src/OpenTK/Platform/Utilities.cs index 2a531f62..6746b395 100644 --- a/src/OpenTK/Platform/Utilities.cs +++ b/src/OpenTK/Platform/Utilities.cs @@ -13,6 +13,7 @@ using System.Runtime.InteropServices; using System.Reflection; using System.Diagnostics; using OpenTK.Graphics; +using OpenTK.Platform.Egl; #endregion @@ -393,6 +394,22 @@ namespace OpenTK.Platform #endregion + #region + + /// + /// Creates an IWindowInfo instance for Angle rendering, based on + /// supplied platform window (e.g. a window created with + /// CreateWindowsWindowInfo, or CreateDummyWindowInfo). + /// + /// + /// + public static IAngleWindowInfo CreateAngleWindowInfo(IWindowInfo platform_window) + { + return new AngleWindowInfo(platform_window); + } + + #endregion + #endregion #region RelaxGraphicsMode From 84a210bda5e0eec8e52e0581d547789dcb5f0c7c Mon Sep 17 00:00:00 2001 From: Jonas Boesch Date: Tue, 21 Apr 2015 16:09:48 +0200 Subject: [PATCH 4/7] Bugfix: Creating a second GraphicsContext forced context sharing. This fix will keep existing behavior (forced sharing) in the default case, but adds a new constructor that allows explicitly specifying the shared context. A user can now explicitly specify null for the shared context to get a new non-shared context. --- src/OpenTK/Graphics/GraphicsContext.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/OpenTK/Graphics/GraphicsContext.cs b/src/OpenTK/Graphics/GraphicsContext.cs index da3c9f6a..62613c73 100644 --- a/src/OpenTK/Graphics/GraphicsContext.cs +++ b/src/OpenTK/Graphics/GraphicsContext.cs @@ -97,6 +97,23 @@ namespace OpenTK.Graphics /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored. /// public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) + : this(mode, window, FindSharedContext(), major, minor, flags) + { + } + + /// + /// Constructs a new GraphicsContext with the specified GraphicsMode, version and flags, and attaches it to the specified window. + /// + /// The OpenTK.Graphics.GraphicsMode of the GraphicsContext. + /// The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to. + /// The GraphicsContext to share resources with, or null for explicit non-sharing. + /// The major version of the new GraphicsContext. + /// The minor version of the new GraphicsContext. + /// The GraphicsContextFlags for the GraphicsContext. + /// + /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored. + /// + public GraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags) { lock (SyncRoot) { @@ -133,8 +150,6 @@ namespace OpenTK.Graphics Debug.Print("GraphicsContextFlags: {0}", flags); Debug.Print("Requested version: {0}.{1}", major, minor); - IGraphicsContext shareContext = FindSharedContext(); - // Todo: Add a DummyFactory implementing IPlatformFactory. if (designMode) { From fc332466001b40ff6e6aaf5137aaf5bb6b8295e6 Mon Sep 17 00:00:00 2001 From: Jonas Boesch Date: Wed, 6 Jan 2016 15:29:34 +0100 Subject: [PATCH 5/7] Use existing ANGLE definitions --- Source/OpenTK/Platform/Egl/EglAngle.cs | 42 ------------------- .../Platform/Egl/EglAnglePlatformFactory.cs | 26 ++++++------ src/OpenTK/OpenTK.csproj | 1 - src/OpenTK/Platform/Egl/Egl.cs | 7 ++++ 4 files changed, 20 insertions(+), 56 deletions(-) delete mode 100644 Source/OpenTK/Platform/Egl/EglAngle.cs diff --git a/Source/OpenTK/Platform/Egl/EglAngle.cs b/Source/OpenTK/Platform/Egl/EglAngle.cs deleted file mode 100644 index 9cf708e8..00000000 --- a/Source/OpenTK/Platform/Egl/EglAngle.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace OpenTK.Platform.Egl -{ - using EGLDisplay = IntPtr; - using EGLNativeDisplayType = IntPtr; - using EGLSurface = IntPtr; - using ShareHandle = IntPtr; - - static partial class Egl - { - // See - // - ANGLE_platform_angle - // - ANGLE_platform_angle_d3d - // - ANGLE_platform_angle_opengl - public const int PLATFORM_ANGLE = 0x3202; - public const int PLATFORM_ANGLE_TYPE = 0x3203; - public const int PLATFORM_ANGLE_MAX_VERSION_MAJOR = 0x3204; - public const int PLATFORM_ANGLE_MAX_VERSION_MINOR = 0x3205; - public const int PLATFORM_ANGLE_TYPE_DEFAULT = 0x3206; - public const int PLATFORM_ANGLE_TYPE_D3D9 = 0x3207; - public const int PLATFORM_ANGLE_TYPE_D3D11 = 0x3208; - public const int PLATFORM_ANGLE_DEVICE_TYPE = 0x3209; - public const int PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE = 0x320A; - public const int PLATFORM_ANGLE_DEVICE_TYPE_WARP = 0x320B; - public const int PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE = 0x320C; - public const int PLATFORM_ANGLE_TYPE_OPENGL = 0x320D; - public const int PLATFORM_ANGLE_TYPE_OPENGLES = 0x320E; - // See EGL_ANGLE_surface_d3d_texture_2d_share_handle - public const int EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200; - - [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")] - public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType display_id, - int[] attrib_list); - - [DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")] - public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, - int attribute, out IntPtr value); - - } -} \ No newline at end of file diff --git a/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs b/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs index 6d5f694d..914e09c0 100644 --- a/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs +++ b/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs @@ -120,32 +120,32 @@ namespace OpenTK.Platform.Egl { // default to D3D9 for ES2, but use D3D11 for ES3 as required by Angle. var platform_type = major == 2 - ? Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9 - : Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11; + ? Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE + : Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11_ANGLE; if (FlagEnabled(flags, GraphicsContextFlags.AngleD3D11)) { - platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11; + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11_ANGLE; } else if (FlagEnabled(flags, GraphicsContextFlags.AngleD3D9)) { - platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9; + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE; } else if (FlagEnabled(flags, GraphicsContextFlags.AngleOpenGL)) { - platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL; + platform_type = Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL_ANGLE; } else { // make sure the correct flag is set. switch (platform_type) { - case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9: + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE: flags |= GraphicsContextFlags.AngleD3D9; break; - case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11: + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_D3D11_ANGLE: flags |= GraphicsContextFlags.AngleD3D11; break; - case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL: + case Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_OPENGL_ANGLE: flags |= GraphicsContextFlags.AngleOpenGL; break; } @@ -153,15 +153,15 @@ namespace OpenTK.Platform.Egl var attribs = new[] { - Platform.Egl.Egl.PLATFORM_ANGLE_TYPE, platform_type, - Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MAJOR, Platform.Egl.Egl.DONT_CARE, - Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MINOR, Platform.Egl.Egl.DONT_CARE, - Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE, Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE, + Platform.Egl.Egl.PLATFORM_ANGLE_TYPE_ANGLE, platform_type, + Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, Platform.Egl.Egl.DONT_CARE, + Platform.Egl.Egl.PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, Platform.Egl.Egl.DONT_CARE, + Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, Platform.Egl.Egl.PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE, Platform.Egl.Egl.NONE }; return Platform.Egl.Egl.GetPlatformDisplay( - Platform.Egl.Egl.PLATFORM_ANGLE, + Platform.Egl.Egl.PLATFORM_ANGLE_ANGLE, dc, attribs ); diff --git a/src/OpenTK/OpenTK.csproj b/src/OpenTK/OpenTK.csproj index 758e53a8..eed8fbfe 100644 --- a/src/OpenTK/OpenTK.csproj +++ b/src/OpenTK/OpenTK.csproj @@ -135,7 +135,6 @@ - diff --git a/src/OpenTK/Platform/Egl/Egl.cs b/src/OpenTK/Platform/Egl/Egl.cs index df395812..86b799c2 100644 --- a/src/OpenTK/Platform/Egl/Egl.cs +++ b/src/OpenTK/Platform/Egl/Egl.cs @@ -210,6 +210,11 @@ namespace OpenTK.Platform.Egl // EGL_ANGLE_query_surface_pointer [DllImport("libEGL.dll", EntryPoint = "eglQuerySurfacePointerANGLE")] public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value); + + [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")] + public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType display_id, + int[] attrib_list); + // EGL_ANGLE_software_display public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1); // EGL_ANGLE_direct3d_display @@ -235,6 +240,8 @@ namespace OpenTK.Platform.Egl // EGL_ANGLE_platform_angle_opengl public const int PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D; public const int PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E; + // See EGL_ANGLE_surface_d3d_texture_2d_share_handle + public const int EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE = 0x3200; [DllImportAttribute("libEGL.dll", EntryPoint = "eglGetError")] public static extern ErrorCode GetError(); From 8ffe3bc504a42eddbc748f8b816d0c2b9d050d1c Mon Sep 17 00:00:00 2001 From: Manuel Zanin Date: Tue, 29 Nov 2016 11:34:16 +0100 Subject: [PATCH 6/7] Moved AngleWindowInfo and EglAnglePlatformFactory under src --- {Source => src}/OpenTK/Platform/Egl/AngleWindowInfo.cs | 0 {Source => src}/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {Source => src}/OpenTK/Platform/Egl/AngleWindowInfo.cs (100%) rename {Source => src}/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs (100%) diff --git a/Source/OpenTK/Platform/Egl/AngleWindowInfo.cs b/src/OpenTK/Platform/Egl/AngleWindowInfo.cs similarity index 100% rename from Source/OpenTK/Platform/Egl/AngleWindowInfo.cs rename to src/OpenTK/Platform/Egl/AngleWindowInfo.cs diff --git a/Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs b/src/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs similarity index 100% rename from Source/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs rename to src/OpenTK/Platform/Egl/EglAnglePlatformFactory.cs From 70ac147b5cf467c53d99cc646f7c3a1c213746a8 Mon Sep 17 00:00:00 2001 From: Manuel Zanin Date: Tue, 21 Mar 2017 10:21:22 +0100 Subject: [PATCH 7/7] Addressed comments --- src/OpenTK/Graphics/GraphicsContext.cs | 16 ++++----- src/OpenTK/Platform/Egl/Egl.cs | 3 +- src/OpenTK/Platform/Egl/EglContext.cs | 10 +++--- src/OpenTK/Platform/Egl/EglGraphicsMode.cs | 42 ++++++++++------------ src/OpenTK/Platform/Egl/EglWindowInfo.cs | 24 ++++++------- src/OpenTK/Platform/Factory.cs | 42 +++++++++++----------- src/OpenTK/Platform/Utilities.cs | 6 ++-- 7 files changed, 69 insertions(+), 74 deletions(-) diff --git a/src/OpenTK/Graphics/GraphicsContext.cs b/src/OpenTK/Graphics/GraphicsContext.cs index 62613c73..a2104e36 100644 --- a/src/OpenTK/Graphics/GraphicsContext.cs +++ b/src/OpenTK/Graphics/GraphicsContext.cs @@ -130,15 +130,15 @@ namespace OpenTK.Graphics minor = 0; // Angle needs an embedded context - var use_angle_flag = GraphicsContextFlags.Angle - | GraphicsContextFlags.AngleD3D9 - | GraphicsContextFlags.AngleD3D11 - | GraphicsContextFlags.AngleOpenGL; - var use_angle = false; - if ((flags & use_angle_flag) != 0) + const GraphicsContextFlags useAngleFlag = GraphicsContextFlags.Angle + | GraphicsContextFlags.AngleD3D9 + | GraphicsContextFlags.AngleD3D11 + | GraphicsContextFlags.AngleOpenGL; + var useAngle = false; + if ((flags & useAngleFlag) != 0) { flags |= GraphicsContextFlags.Embedded; - use_angle = true; + useAngle = true; } Debug.Print("Creating GraphicsContext."); @@ -164,7 +164,7 @@ namespace OpenTK.Graphics factory = Factory.Default; break; case true: - factory = use_angle ? Factory.Angle : Factory.Embedded; + factory = useAngle ? Factory.Angle : Factory.Embedded; break; } diff --git a/src/OpenTK/Platform/Egl/Egl.cs b/src/OpenTK/Platform/Egl/Egl.cs index 86b799c2..8a23a006 100644 --- a/src/OpenTK/Platform/Egl/Egl.cs +++ b/src/OpenTK/Platform/Egl/Egl.cs @@ -212,8 +212,7 @@ namespace OpenTK.Platform.Egl public static extern bool QuerySurfacePointerANGLE(EGLDisplay display, EGLSurface surface, int attribute, out IntPtr value); [DllImport("libEGL.dll", EntryPoint = "eglGetPlatformDisplayEXT")] - public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType display_id, - int[] attrib_list); + public static extern EGLDisplay GetPlatformDisplay(int platform, EGLNativeDisplayType displayId, int[] attribList); // EGL_ANGLE_software_display public static readonly EGLNativeDisplayType SOFTWARE_DISPLAY_ANGLE = new EGLNativeDisplayType(-1); diff --git a/src/OpenTK/Platform/Egl/EglContext.cs b/src/OpenTK/Platform/Egl/EglContext.cs index 76992c92..1967f2dd 100644 --- a/src/OpenTK/Platform/Egl/EglContext.cs +++ b/src/OpenTK/Platform/Egl/EglContext.cs @@ -90,11 +90,11 @@ namespace OpenTK.Platform.Egl bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0; - SurfaceType surface_type = offscreen + SurfaceType surfaceType = offscreen ? SurfaceType.PBUFFER_BIT : SurfaceType.WINDOW_BIT; - Mode = new EglGraphicsMode().SelectGraphicsMode(surface_type, + Mode = new EglGraphicsMode().SelectGraphicsMode(surfaceType, window.Display, mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, Renderable); @@ -115,9 +115,9 @@ namespace OpenTK.Platform.Egl } } - int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; - var share_context = shared != null ? shared.HandleAsEGLContext : IntPtr.Zero; - HandleAsEGLContext = Egl.CreateContext(window.Display, config, share_context, attrib_list); + int[] attribList = { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; + var shareContext = shared?.HandleAsEGLContext ?? IntPtr.Zero; + HandleAsEGLContext = Egl.CreateContext(window.Display, config, shareContext, attribList); GraphicsContextFlags = flags; } diff --git a/src/OpenTK/Platform/Egl/EglGraphicsMode.cs b/src/OpenTK/Platform/Egl/EglGraphicsMode.cs index 682caf3e..8a5b7ea9 100644 --- a/src/OpenTK/Platform/Egl/EglGraphicsMode.cs +++ b/src/OpenTK/Platform/Egl/EglGraphicsMode.cs @@ -26,8 +26,6 @@ #endregion using System; -using System.Collections.Generic; -using System.Text; using OpenTK.Graphics; namespace OpenTK.Platform.Egl @@ -46,25 +44,24 @@ namespace OpenTK.Platform.Egl public GraphicsMode SelectGraphicsMode(EglWindowInfo window, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, - RenderableFlags renderable_flags) + RenderableFlags renderableFlags) { return SelectGraphicsMode( SurfaceType.WINDOW_BIT, window.Display, - color, depth, stencil, samples, accum, buffers, stereo, renderable_flags - ); + color, depth, stencil, samples, accum, buffers, stereo, renderableFlags); } - public GraphicsMode SelectGraphicsMode(SurfaceType surface_type, + public GraphicsMode SelectGraphicsMode(SurfaceType surfaceType, IntPtr display, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, - RenderableFlags renderable_flags) + RenderableFlags renderableFlags) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { - Egl.SURFACE_TYPE, (int) surface_type, - Egl.RENDERABLE_TYPE, (int)renderable_flags, + Egl.SURFACE_TYPE, (int) surfaceType, + Egl.RENDERABLE_TYPE, (int)renderableFlags, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, @@ -80,28 +77,27 @@ namespace OpenTK.Platform.Egl Egl.NONE, }; - int num_configs; - if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs) || num_configs == 0) + int numConfigs; + if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out numConfigs) || numConfigs == 0) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } // See what we really got - IntPtr active_config = configs[0]; + IntPtr activeConfig = configs[0]; int r, g, b, a; - Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); - Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); - Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); - Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); + Egl.GetConfigAttrib(display, activeConfig, Egl.RED_SIZE, out r); + Egl.GetConfigAttrib(display, activeConfig, Egl.GREEN_SIZE, out g); + Egl.GetConfigAttrib(display, activeConfig, Egl.BLUE_SIZE, out b); + Egl.GetConfigAttrib(display, activeConfig, Egl.ALPHA_SIZE, out a); int d, s; - Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); - Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); - int sample_buffers; - Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); - Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); + Egl.GetConfigAttrib(display, activeConfig, Egl.DEPTH_SIZE, out d); + Egl.GetConfigAttrib(display, activeConfig, Egl.STENCIL_SIZE, out s); + int sampleBuffers; + Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out sampleBuffers); + Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out samples); - return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false); + return new GraphicsMode(activeConfig, new ColorFormat(r, g, b, a), d, s, sampleBuffers > 0 ? samples : 0, 0, 2, false); } - } } diff --git a/src/OpenTK/Platform/Egl/EglWindowInfo.cs b/src/OpenTK/Platform/Egl/EglWindowInfo.cs index db73aa3d..0f14dc74 100644 --- a/src/OpenTK/Platform/Egl/EglWindowInfo.cs +++ b/src/OpenTK/Platform/Egl/EglWindowInfo.cs @@ -64,8 +64,8 @@ namespace OpenTK.Platform.Egl Display = display; - int dummy_major, dummy_minor; - if (!Egl.Initialize(Display, out dummy_major, out dummy_minor)) + int dummyMajor, dummyMinor; + if (!Egl.Initialize(Display, out dummyMajor, out dummyMinor)) { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } @@ -116,7 +116,7 @@ namespace OpenTK.Platform.Egl CreatePbufferSurface(config, width, height, out surface); } - public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr surface_) + public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr bufferSurface) { int[] attribs = new int[] { @@ -126,13 +126,12 @@ namespace OpenTK.Platform.Egl Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA, Egl.NONE }; - surface_ = Egl.CreatePbufferSurface(Display, config, attribs); - if (surface_ == IntPtr.Zero) + bufferSurface = Egl.CreatePbufferSurface(Display, config, attribs); + if (bufferSurface == IntPtr.Zero) { throw new GraphicsContextException(String.Format( "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); } - } public void DestroySurface() @@ -140,19 +139,20 @@ namespace OpenTK.Platform.Egl DestroySurface(ref surface); } - public void DestroySurface(ref IntPtr surface_) + public void DestroySurface(ref IntPtr bufferSurface) { - if (surface_ == IntPtr.Zero) + if (bufferSurface == IntPtr.Zero) { return; } if (Egl.GetCurrentSurface(Egl.DRAW) == Surface) - Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - - if (Egl.DestroySurface(Display, surface_)) { - surface_ = IntPtr.Zero; + Egl.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + } + if (Egl.DestroySurface(Display, bufferSurface)) + { + bufferSurface = IntPtr.Zero; return; } diff --git a/src/OpenTK/Platform/Factory.cs b/src/OpenTK/Platform/Factory.cs index 35839e08..0117e6c8 100644 --- a/src/OpenTK/Platform/Factory.cs +++ b/src/OpenTK/Platform/Factory.cs @@ -26,9 +26,7 @@ #endregion using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Text; using OpenTK.Platform.Egl; namespace OpenTK.Platform @@ -40,8 +38,10 @@ namespace OpenTK.Platform { #region Fields - bool disposed; - static IPlatformFactory default_implementation, embedded_implementation, angle_implementation; + private bool disposed; + private static IPlatformFactory defaultImplementation; + private static IPlatformFactory embeddedImplementation; + private static IPlatformFactory angleImplementation; #endregion @@ -122,20 +122,20 @@ namespace OpenTK.Platform public static IPlatformFactory Default { - get { return default_implementation; } - private set { default_implementation = value; } + get { return defaultImplementation; } + private set { defaultImplementation = value; } } public static IPlatformFactory Embedded { - get { return embedded_implementation; } - private set { embedded_implementation = value; } + get { return embeddedImplementation; } + private set { embeddedImplementation = value; } } public static IPlatformFactory Angle { - get { return angle_implementation; } - private set { angle_implementation = value; } + get { return angleImplementation; } + private set { angleImplementation = value; } } #endregion @@ -145,60 +145,60 @@ namespace OpenTK.Platform public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { - return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); + return defaultImplementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); } public IDisplayDeviceDriver CreateDisplayDeviceDriver() { - return default_implementation.CreateDisplayDeviceDriver(); + return defaultImplementation.CreateDisplayDeviceDriver(); } public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { - return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); + return defaultImplementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); } public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { - return default_implementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags); + return defaultImplementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags); } public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() { - return default_implementation.CreateGetCurrentGraphicsContext(); + return defaultImplementation.CreateGetCurrentGraphicsContext(); } public IKeyboardDriver2 CreateKeyboardDriver() { - return default_implementation.CreateKeyboardDriver(); + return defaultImplementation.CreateKeyboardDriver(); } public IMouseDriver2 CreateMouseDriver() { - return default_implementation.CreateMouseDriver(); + return defaultImplementation.CreateMouseDriver(); } public IGamePadDriver CreateGamePadDriver() { - return default_implementation.CreateGamePadDriver(); + return defaultImplementation.CreateGamePadDriver(); } public IJoystickDriver2 CreateJoystickDriver() { - return default_implementation.CreateJoystickDriver(); + return defaultImplementation.CreateJoystickDriver(); } [Obsolete] public IJoystickDriver CreateLegacyJoystickDriver() { #pragma warning disable 612,618 - return default_implementation.CreateLegacyJoystickDriver(); + return defaultImplementation.CreateLegacyJoystickDriver(); #pragma warning restore 612,618 } public void RegisterResource(IDisposable resource) { - default_implementation.RegisterResource(resource); + defaultImplementation.RegisterResource(resource); } class UnsupportedPlatform : PlatformFactoryBase diff --git a/src/OpenTK/Platform/Utilities.cs b/src/OpenTK/Platform/Utilities.cs index 6746b395..a0c262a3 100644 --- a/src/OpenTK/Platform/Utilities.cs +++ b/src/OpenTK/Platform/Utilities.cs @@ -401,11 +401,11 @@ namespace OpenTK.Platform /// supplied platform window (e.g. a window created with /// CreateWindowsWindowInfo, or CreateDummyWindowInfo). /// - /// + /// /// - public static IAngleWindowInfo CreateAngleWindowInfo(IWindowInfo platform_window) + public static IAngleWindowInfo CreateAngleWindowInfo(IWindowInfo platformWindow) { - return new AngleWindowInfo(platform_window); + return new AngleWindowInfo(platformWindow); } #endregion