Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region License |
| 2 | // |
||
| 3 | // The Open Toolkit Library License |
||
| 4 | // |
||
| 5 | // Copyright (c) 2006 - 2009 the Open Toolkit library. |
||
| 6 | // |
||
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | // of this software and associated documentation files (the "Software"), to deal |
||
| 9 | // in the Software without restriction, including without limitation the rights to |
||
| 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||
| 11 | // the Software, and to permit persons to whom the Software is furnished to do |
||
| 12 | // so, subject to the following conditions: |
||
| 13 | // |
||
| 14 | // The above copyright notice and this permission notice shall be included in all |
||
| 15 | // copies or substantial portions of the Software. |
||
| 16 | // |
||
| 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
| 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
| 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
| 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
| 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
| 24 | // OTHER DEALINGS IN THE SOFTWARE. |
||
| 25 | // |
||
| 26 | #endregion |
||
| 27 | |||
| 28 | using System; |
||
| 29 | using System.Collections.Generic; |
||
| 30 | using System.Text; |
||
| 31 | |||
| 32 | namespace OpenTK.Platform |
||
| 33 | { |
||
| 34 | using Graphics; |
||
| 35 | |||
| 36 | sealed class Factory : IPlatformFactory |
||
| 37 | { |
||
| 38 | #region Fields |
||
| 39 | |||
| 40 | static IPlatformFactory default_implementation, embedded_implementation; |
||
| 41 | |||
| 42 | #endregion |
||
| 43 | |||
| 44 | #region Constructors |
||
| 45 | |||
| 46 | static Factory() |
||
| 47 | { |
||
| 48 | if (Configuration.RunningOnWindows) Default = new Windows.WinFactory(); |
||
| 49 | else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory(); |
||
| 50 | else if (Configuration.RunningOnX11) Default = new X11.X11Factory(); |
||
| 51 | else Default = new UnsupportedPlatform(); |
||
| 52 | |||
| 53 | if (Egl.Egl.IsSupported) |
||
| 54 | { |
||
| 55 | if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory(); |
||
| 56 | else if (Configuration.RunningOnMacOS) Embedded = new Egl.EglMacPlatformFactory(); |
||
| 57 | else if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory(); |
||
| 58 | else Embedded = new UnsupportedPlatform(); |
||
| 59 | } |
||
| 60 | else Embedded = new UnsupportedPlatform(); |
||
| 61 | |||
| 62 | if (Default is UnsupportedPlatform && !(Embedded is UnsupportedPlatform)) |
||
| 63 | Default = Embedded; |
||
| 64 | } |
||
| 65 | |||
| 66 | #endregion |
||
| 67 | |||
| 68 | #region Public Members |
||
| 69 | |||
| 70 | public static IPlatformFactory Default |
||
| 71 | { |
||
| 72 | get { return default_implementation; } |
||
| 73 | private set { default_implementation = value; } |
||
| 74 | } |
||
| 75 | |||
| 76 | public static IPlatformFactory Embedded |
||
| 77 | { |
||
| 78 | get { return embedded_implementation; } |
||
| 79 | private set { embedded_implementation = value; } |
||
| 80 | } |
||
| 81 | |||
| 82 | #endregion |
||
| 83 | |||
| 84 | #region IPlatformFactory Members |
||
| 85 | |||
| 86 | public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, |
||
| 87 | GraphicsMode mode, GameWindowFlags options, DisplayDevice device) |
||
| 88 | { |
||
| 89 | return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); |
||
| 90 | } |
||
| 91 | |||
| 92 | public IDisplayDeviceDriver CreateDisplayDeviceDriver() |
||
| 93 | { |
||
| 94 | return default_implementation.CreateDisplayDeviceDriver(); |
||
| 95 | } |
||
| 96 | |||
| 97 | public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) |
||
| 98 | { |
||
| 99 | return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags); |
||
| 100 | } |
||
| 101 | |||
| 102 | public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) |
||
| 103 | { |
||
| 104 | return default_implementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags); |
||
| 105 | } |
||
| 106 | |||
| 107 | public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() |
||
| 108 | { |
||
| 109 | return default_implementation.CreateGetCurrentGraphicsContext(); |
||
| 110 | } |
||
| 111 | |||
| 112 | public IGraphicsMode CreateGraphicsMode() |
||
| 113 | { |
||
| 114 | return default_implementation.CreateGraphicsMode(); |
||
| 115 | } |
||
| 116 | |||
| 117 | public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() |
||
| 118 | { |
||
| 119 | return default_implementation.CreateKeyboardDriver(); |
||
| 120 | } |
||
| 121 | |||
| 122 | class UnsupportedPlatform : IPlatformFactory |
||
| 123 | { |
||
| 124 | #region Fields |
||
| 125 | |||
| 126 | static readonly string error_string = "Please, refer to http://www.opentk.com for more information."; |
||
| 127 | |||
| 128 | #endregion |
||
| 129 | |||
| 130 | #region IPlatformFactory Members |
||
| 131 | |||
| 132 | public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) |
||
| 133 | { |
||
| 134 | throw new PlatformNotSupportedException(error_string); |
||
| 135 | } |
||
| 136 | |||
| 137 | public IDisplayDeviceDriver CreateDisplayDeviceDriver() |
||
| 138 | { |
||
| 139 | throw new PlatformNotSupportedException(error_string); |
||
| 140 | } |
||
| 141 | |||
| 142 | public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) |
||
| 143 | { |
||
| 144 | throw new PlatformNotSupportedException(error_string); |
||
| 145 | } |
||
| 146 | |||
| 147 | public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) |
||
| 148 | { |
||
| 149 | throw new PlatformNotSupportedException(error_string); |
||
| 150 | } |
||
| 151 | |||
| 152 | public IGraphicsContext CreateESContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags) |
||
| 153 | { |
||
| 154 | throw new PlatformNotSupportedException(error_string); |
||
| 155 | } |
||
| 156 | |||
| 157 | public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() |
||
| 158 | { |
||
| 159 | throw new PlatformNotSupportedException(error_string); |
||
| 160 | } |
||
| 161 | |||
| 162 | public IGraphicsMode CreateGraphicsMode() |
||
| 163 | { |
||
| 164 | throw new PlatformNotSupportedException(error_string); |
||
| 165 | } |
||
| 166 | |||
| 167 | public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() |
||
| 168 | { |
||
| 169 | throw new PlatformNotSupportedException(error_string); |
||
| 170 | } |
||
| 171 | |||
| 172 | #endregion |
||
| 173 | } |
||
| 174 | |||
| 175 | #endregion |
||
| 176 | } |
||
| 177 | } |