From 245f45c7ebdae32f8fe6bfefb66c1f96489b526b Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Thu, 13 Aug 2009 11:52:51 +0000 Subject: [PATCH] Added support for IPlatformFactory implementations for embedded devices that use EGL. The embedded implementation can be used side-by-side with the normal implementations (useful for platforms that support both desktop GL and EGL). --- Source/OpenTK/Graphics/GraphicsContext.cs | 8 ++++- Source/OpenTK/Platform/Factory.cs | 44 ++++++++++++++++------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs index 7f6e25e5..90ed76d6 100644 --- a/Source/OpenTK/Graphics/GraphicsContext.cs +++ b/Source/OpenTK/Graphics/GraphicsContext.cs @@ -97,6 +97,8 @@ namespace OpenTK.Graphics Debug.Indent(); Debug.Print("GraphicsMode: {0}", mode); Debug.Print("IWindowInfo: {0}", window); + Debug.Print("GraphicsContextFlags: {0}", flags); + Debug.Print("Requested version: {0}.{1}", major, minor); IGraphicsContext shareContext = null; if (GraphicsContext.ShareContexts) @@ -116,7 +118,11 @@ namespace OpenTK.Graphics if (designMode) implementation = new Platform.Dummy.DummyGLContext(); else - implementation = Factory.Default.CreateGLContext(mode, window, shareContext, DirectRendering, major, minor, flags); + switch ((int)(flags & GraphicsContextFlags.Embedded)) + { + case 0: implementation = Factory.Default.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); break; + case 1: implementation = Factory.Embedded.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); break; + } lock (context_lock) { diff --git a/Source/OpenTK/Platform/Factory.cs b/Source/OpenTK/Platform/Factory.cs index f4fcfb22..9e33c3f8 100644 --- a/Source/OpenTK/Platform/Factory.cs +++ b/Source/OpenTK/Platform/Factory.cs @@ -37,7 +37,7 @@ namespace OpenTK.Platform { #region Fields - static IPlatformFactory implementation; + static IPlatformFactory default_implementation, embedded_implementation; #endregion @@ -45,10 +45,21 @@ namespace OpenTK.Platform static Factory() { - if (Configuration.RunningOnWindows) implementation = new Windows.WinFactory(); - else if (Configuration.RunningOnX11) implementation = new X11.X11Factory(); - else if (Configuration.RunningOnMacOS) implementation = new MacOS.MacOSFactory(); - else implementation = new UnsupportedPlatform(); + if (Configuration.RunningOnWindows) Default = new Windows.WinFactory(); + else if (Configuration.RunningOnX11) Default = new X11.X11Factory(); + else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory(); + else Default = new UnsupportedPlatform(); + + if (Egl.Egl.IsSupported) + { + if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory(); + else if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory(); + else if (Configuration.RunningOnMacOS) Embedded = new Egl.EglMacPlatformFactory(); + else Embedded = new UnsupportedPlatform(); + } + + if (Default is UnsupportedPlatform && !(Embedded is UnsupportedPlatform)) + Default = Embedded; } #endregion @@ -57,7 +68,14 @@ namespace OpenTK.Platform public static IPlatformFactory Default { - get { return implementation; } + get { return default_implementation; } + private set { default_implementation = value; } + } + + public static IPlatformFactory Embedded + { + get { return embedded_implementation; } + private set { embedded_implementation = value; } } #endregion @@ -67,37 +85,37 @@ namespace OpenTK.Platform public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { - return implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); + return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); } public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner) { - return implementation.CreateGLControl(mode, owner); + return default_implementation.CreateGLControl(mode, owner); } public IDisplayDeviceDriver CreateDisplayDeviceDriver() { - return implementation.CreateDisplayDeviceDriver(); + return default_implementation.CreateDisplayDeviceDriver(); } public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { - return implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); + return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); } public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() { - return implementation.CreateGetCurrentGraphicsContext(); + return default_implementation.CreateGetCurrentGraphicsContext(); } public IGraphicsMode CreateGraphicsMode() { - return implementation.CreateGraphicsMode(); + return default_implementation.CreateGraphicsMode(); } public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() { - return implementation.CreateKeyboardDriver(); + return default_implementation.CreateKeyboardDriver(); } class UnsupportedPlatform : IPlatformFactory