00001 #region License
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #endregion
00027
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031
00032 namespace OpenTK.Platform
00033 {
00034 using Graphics;
00035
00036 sealed class Factory : IPlatformFactory
00037 {
00038 #region Fields
00039
00040 static IPlatformFactory default_implementation, embedded_implementation;
00041
00042 #endregion
00043
00044 #region Constructors
00045
00046 static Factory()
00047 {
00048 if (Configuration.RunningOnWindows) Default = new Windows.WinFactory();
00049 else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory();
00050 else if (Configuration.RunningOnX11) Default = new X11.X11Factory();
00051 else Default = new UnsupportedPlatform();
00052
00053 if (Egl.Egl.IsSupported)
00054 {
00055 if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory();
00056 else if (Configuration.RunningOnMacOS) Embedded = new Egl.EglMacPlatformFactory();
00057 else if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory();
00058 else Embedded = new UnsupportedPlatform();
00059 }
00060 else Embedded = new UnsupportedPlatform();
00061
00062 if (Default is UnsupportedPlatform && !(Embedded is UnsupportedPlatform))
00063 Default = Embedded;
00064 }
00065
00066 #endregion
00067
00068 #region Public Members
00069
00070 public static IPlatformFactory Default
00071 {
00072 get { return default_implementation; }
00073 private set { default_implementation = value; }
00074 }
00075
00076 public static IPlatformFactory Embedded
00077 {
00078 get { return embedded_implementation; }
00079 private set { embedded_implementation = value; }
00080 }
00081
00082 #endregion
00083
00084 #region IPlatformFactory Members
00085
00086 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title,
00087 GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
00088 {
00089 return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device);
00090 }
00091
00092 public IDisplayDeviceDriver CreateDisplayDeviceDriver()
00093 {
00094 return default_implementation.CreateDisplayDeviceDriver();
00095 }
00096
00097 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
00098 {
00099 return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags);
00100 }
00101
00102 public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
00103 {
00104 return default_implementation.CreateGLContext(handle, window, shareContext, directRendering, major, minor, flags);
00105 }
00106
00107 public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
00108 {
00109 return default_implementation.CreateGetCurrentGraphicsContext();
00110 }
00111
00112 public IGraphicsMode CreateGraphicsMode()
00113 {
00114 return default_implementation.CreateGraphicsMode();
00115 }
00116
00117 public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver()
00118 {
00119 return default_implementation.CreateKeyboardDriver();
00120 }
00121
00122 class UnsupportedPlatform : IPlatformFactory
00123 {
00124 #region Fields
00125
00126 static readonly string error_string = "Please, refer to http://www.opentk.com for more information.";
00127
00128 #endregion
00129
00130 #region IPlatformFactory Members
00131
00132 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
00133 {
00134 throw new PlatformNotSupportedException(error_string);
00135 }
00136
00137 public IDisplayDeviceDriver CreateDisplayDeviceDriver()
00138 {
00139 throw new PlatformNotSupportedException(error_string);
00140 }
00141
00142 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
00143 {
00144 throw new PlatformNotSupportedException(error_string);
00145 }
00146
00147 public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
00148 {
00149 throw new PlatformNotSupportedException(error_string);
00150 }
00151
00152 public IGraphicsContext CreateESContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
00153 {
00154 throw new PlatformNotSupportedException(error_string);
00155 }
00156
00157 public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
00158 {
00159 throw new PlatformNotSupportedException(error_string);
00160 }
00161
00162 public IGraphicsMode CreateGraphicsMode()
00163 {
00164 throw new PlatformNotSupportedException(error_string);
00165 }
00166
00167 public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver()
00168 {
00169 throw new PlatformNotSupportedException(error_string);
00170 }
00171
00172 #endregion
00173 }
00174
00175 #endregion
00176 }
00177 }