From d217e379d4a0f77b12bc64c0de1c5b355ac5b7e2 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Thu, 3 Oct 2013 11:17:21 +0200 Subject: [PATCH] Added support for OpenGL ES through SDL2 If SDL2 is supported, the PlatformFactory will now use it for creating the OpenGL ES context. Previously, it would revert to the native drivers when GraphicsContextFlag.Embedded was specified. --- Source/OpenTK/OpenTK.csproj | 1 + .../Platform/Egl/EglSdl2PlatformFactory.cs | 46 +++++++++++++++++++ Source/OpenTK/Platform/Factory.cs | 11 ++++- Source/OpenTK/Platform/SDL2/Sdl2Factory.cs | 2 +- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 Source/OpenTK/Platform/Egl/EglSdl2PlatformFactory.cs diff --git a/Source/OpenTK/OpenTK.csproj b/Source/OpenTK/OpenTK.csproj index f9e3270c..fb5ce9f0 100644 --- a/Source/OpenTK/OpenTK.csproj +++ b/Source/OpenTK/OpenTK.csproj @@ -799,6 +799,7 @@ + diff --git a/Source/OpenTK/Platform/Egl/EglSdl2PlatformFactory.cs b/Source/OpenTK/Platform/Egl/EglSdl2PlatformFactory.cs new file mode 100644 index 00000000..32aaec52 --- /dev/null +++ b/Source/OpenTK/Platform/Egl/EglSdl2PlatformFactory.cs @@ -0,0 +1,46 @@ +#region License +// +// The Open Toolkit Library License +// +// Copyright (c) 2006 - 2013 Stefanos Apostolopoulos +// +// 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.Platform.SDL2; + +namespace OpenTK.Platform.Egl +{ + + class EglSdl2PlatformFactory : Sdl2Factory + { + public override OpenTK.Graphics.IGraphicsContext CreateGLContext( + GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, + int major, int minor, GraphicsContextFlags flags) + { + flags |= GraphicsContextFlags.Embedded; + return base.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); + } + } +} + diff --git a/Source/OpenTK/Platform/Factory.cs b/Source/OpenTK/Platform/Factory.cs index 2fe318db..ff0414b0 100644 --- a/Source/OpenTK/Platform/Factory.cs +++ b/Source/OpenTK/Platform/Factory.cs @@ -53,14 +53,21 @@ namespace OpenTK.Platform else if (Configuration.RunningOnX11) Default = new X11.X11Factory(); else Default = new UnsupportedPlatform(); - if (Egl.Egl.IsSupported) + if (Configuration.Sdl2Supported) + { + Embedded = new Egl.EglSdl2PlatformFactory(); + } + else if (Egl.Egl.IsSupported) { if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory(); else if (Configuration.RunningOnMacOS) Embedded = new Egl.EglMacPlatformFactory(); else if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory(); else Embedded = new UnsupportedPlatform(); } - else Embedded = new UnsupportedPlatform(); + else + { + Embedded = new UnsupportedPlatform(); + } if (Default is UnsupportedPlatform && !(Embedded is UnsupportedPlatform)) Default = Embedded; diff --git a/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs b/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs index 18d62ac8..4992f243 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2Factory.cs @@ -53,7 +53,7 @@ namespace OpenTK.Platform.SDL2 return new Sdl2DisplayDeviceDriver(); } - public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) + virtual public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { return new Sdl2GraphicsContext(mode, window, shareContext, major, minor, flags); }