mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-04 05:21:07 +00:00
Updated to use new IWindowInfo interface.
Updated to use GraphicsFormat instead of DisplayMode. Updated to use ColorDepth instead of ColorMode. Improved GameWindow Exit handling, and handling of failed context creation. Improved WinGLContext creation code, to allow for FSAA support in the future. Fixed several shutdown bugs in WinGLContext and GraphicsContext. Context creation no longer relies on IGLContextCreationHack. X11GLContext is not working at the moment.
This commit is contained in:
parent
e9b2fe6106
commit
83afd98314
|
@ -23,8 +23,8 @@ namespace OpenTK
|
|||
public partial class GLControl : UserControl
|
||||
{
|
||||
IGraphicsContext context;
|
||||
IPlatformIdle idle;
|
||||
DisplayMode display_mode;
|
||||
GraphicsFormat format;
|
||||
IGLControlHelper helper;
|
||||
|
||||
#region --- Constructor ---
|
||||
|
||||
|
@ -32,15 +32,18 @@ namespace OpenTK
|
|||
/// Constructs a new GLControl.
|
||||
/// </summary>
|
||||
public GLControl()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
: this(GraphicsFormat.Default)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl with the specified DisplayMode.
|
||||
/// </summary>
|
||||
/// <param name="mode"></param>
|
||||
public GLControl(DisplayMode mode)
|
||||
: this(mode.ToGraphicsFormat())
|
||||
{ }
|
||||
|
||||
public GLControl(GraphicsFormat format)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -49,18 +52,25 @@ namespace OpenTK
|
|||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
DoubleBuffered = false;
|
||||
|
||||
this.display_mode = mode;
|
||||
this.format = format;
|
||||
|
||||
this.CreateControl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Context Setup ---
|
||||
#region --- Protected Methods ---
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
if (Configuration.RunningOnWindows)
|
||||
helper = new Platform.Windows.WinGLControlHelper(this);
|
||||
else if (Configuration.RunningOnX11)
|
||||
throw new NotImplementedException();
|
||||
//helper = new Platform.X11.X11GLControlHelper(this);
|
||||
else if (Configuration.RunningOnOSX)
|
||||
throw new NotImplementedException();
|
||||
this.CreateContext();
|
||||
}
|
||||
|
||||
|
@ -72,7 +82,70 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Public Properties ---
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public void SwapBuffers()
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the front and back buffers, presenting the rendered scene to the screen.
|
||||
/// </summary>
|
||||
public void SwapBuffers()
|
||||
{
|
||||
Context.SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void MakeCurrent()
|
||||
|
||||
/// <summary>
|
||||
/// Makes the underlying this GLControl current in the calling thread.
|
||||
/// All OpenGL commands issued are hereafter interpreted by this GLControl.
|
||||
/// </summary>
|
||||
public void MakeCurrent()
|
||||
{
|
||||
Context.MakeCurrent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
/// <summary>
|
||||
/// Creates a GraphicsContext and attaches it to this GLControl.
|
||||
/// </summary>
|
||||
public void CreateContext()
|
||||
{
|
||||
if (context != null)
|
||||
throw new InvalidOperationException("GLControl already contains an OpenGL context.");
|
||||
if (format == null)
|
||||
format = GraphicsFormat.Default;
|
||||
|
||||
if (!this.DesignMode)
|
||||
{
|
||||
// Note: Mono's implementation of Windows.Forms on X11 does not allow the context to
|
||||
// have a different colordepth from the parent window.
|
||||
context = new GraphicsContext(format, helper.WindowInfo);
|
||||
}
|
||||
else
|
||||
context = new DummyGLContext(format);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void DestroyContext()
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the GraphicsContext attached to this GLControl.
|
||||
/// </summary>
|
||||
/// <exception cref="NullReferenceException">Occurs when no GraphicsContext is attached.</exception>
|
||||
public void DestroyContext()
|
||||
{
|
||||
Context.Dispose();
|
||||
Context = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool IsIdle
|
||||
|
||||
|
@ -82,7 +155,7 @@ namespace OpenTK
|
|||
[Browsable(false)]
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return idle.IsIdle; }
|
||||
get { return helper.IsIdle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -140,91 +213,17 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region public DisplayMode Mode
|
||||
|
||||
// TODO: Remove for 0.3.15
|
||||
#region public GraphicsFormat GraphicsFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DisplayMode of the GraphicsContext attached to this GLControl.
|
||||
/// Gets the GraphicsFormat of the GraphicsContext attached to this GLControl.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You cannot change the DisplayMode of an existing GraphicsContext.
|
||||
/// To change the GraphicsFormat, you must destroy and recreate the GLControl.
|
||||
/// </remarks>
|
||||
public DisplayMode Mode
|
||||
public GraphicsFormat GraphicsFormat
|
||||
{
|
||||
get { return (Context as IGLContextInternal).Mode; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public void SwapBuffers()
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the front and back buffers, presenting the rendered scene to the screen.
|
||||
/// </summary>
|
||||
public void SwapBuffers()
|
||||
{
|
||||
Context.SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void MakeCurrent()
|
||||
|
||||
/// <summary>
|
||||
/// Makes the underlying this GLControl current in the calling thread.
|
||||
/// All OpenGL commands issued are hereafter interpreted by this GLControl.
|
||||
/// </summary>
|
||||
public void MakeCurrent()
|
||||
{
|
||||
Context.MakeCurrent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
/// <summary>
|
||||
/// Creates a GraphicsContext and attaches it to this GLControl.
|
||||
/// </summary>
|
||||
public void CreateContext()
|
||||
{
|
||||
if (display_mode == null)
|
||||
display_mode = new DisplayMode();
|
||||
WindowInfo info = new WindowInfo(this);
|
||||
|
||||
if (!this.DesignMode)
|
||||
{
|
||||
// Mono's implementation of Windows.Forms on X11 does not allow the context to
|
||||
// have a different colordepth from the parent. To combat this, we do not set a
|
||||
// specific depth for the DisplayMode - we let the driver select one instead.
|
||||
//display_mode.ColorFormat = new ColorMode(0);
|
||||
context = new GraphicsContext(display_mode, info);
|
||||
idle = new PlatformIdle(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
context = new DummyGLContext(display_mode);
|
||||
idle = new DummyPlatformIdle();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void DestroyContext()
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the GraphicsContext attached to this GLControl.
|
||||
/// </summary>
|
||||
/// <exception cref="NullReferenceException">Occurs when no GraphicsContext is attached.</exception>
|
||||
public void DestroyContext()
|
||||
{
|
||||
Context.Dispose();
|
||||
Context = null;
|
||||
get { return (Context as IGLContextInternal).GraphicsFormat; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -233,39 +232,12 @@ namespace OpenTK
|
|||
}
|
||||
|
||||
#region internal interface IPlatformIdle
|
||||
|
||||
#if false
|
||||
internal interface IPlatformIdle
|
||||
{
|
||||
bool IsIdle { get; }
|
||||
}
|
||||
|
||||
internal class WinPlatformIdle : IPlatformIdle
|
||||
{
|
||||
OpenTK.Platform.Windows.MSG msg = new OpenTK.Platform.Windows.MSG();
|
||||
object get_lock = new object();
|
||||
//IntPtr handle;
|
||||
|
||||
public WinPlatformIdle(WindowInfo info)
|
||||
{
|
||||
//handle = info.Handle;
|
||||
}
|
||||
|
||||
#region IPlatformIdle Members
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (get_lock)
|
||||
{
|
||||
return !OpenTK.Platform.Windows.Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class X11PlatformIdle : IPlatformIdle
|
||||
{
|
||||
object get_lock = new object();
|
||||
|
@ -291,52 +263,16 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
|
||||
internal class PlatformIdle : IPlatformIdle
|
||||
#endregion
|
||||
|
||||
#region internal interface IGLControlHelper
|
||||
|
||||
internal interface IGLControlHelper
|
||||
{
|
||||
IPlatformIdle implementation;
|
||||
|
||||
public PlatformIdle(WindowInfo info)
|
||||
{
|
||||
switch (System.Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
case (PlatformID)128:
|
||||
implementation = new X11PlatformIdle(info);
|
||||
break;
|
||||
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
implementation = new WinPlatformIdle(info);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
#region IPlatformIdle Members
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return implementation.IsIdle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class DummyPlatformIdle : IPlatformIdle
|
||||
{
|
||||
#region IPlatformIdle Members
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
IWindowInfo WindowInfo { get; }
|
||||
bool IsIdle { get; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace OpenTK
|
|||
ResizeEventArgs resizeEventArgs = new ResizeEventArgs();
|
||||
|
||||
bool isExiting;
|
||||
bool hasMainLoop;
|
||||
bool disposed;
|
||||
|
||||
double update_period, render_period;
|
||||
|
@ -80,13 +81,19 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Internal Properties ---
|
||||
#region --- Private Methods ---
|
||||
|
||||
bool MustResize
|
||||
{
|
||||
get { return glWindow.Width != this.Width || glWindow.Height != this.Height; }
|
||||
}
|
||||
|
||||
bool HasMainLoop
|
||||
{
|
||||
get { return hasMainLoop; }
|
||||
set { hasMainLoop = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Contructors ---
|
||||
|
@ -109,29 +116,27 @@ namespace OpenTK
|
|||
|
||||
GameWindow(string title, int width, int height, DisplayResolution resolution, GraphicsFormat format)
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
glWindow = new OpenTK.Platform.Windows.WinGLNative();
|
||||
break;
|
||||
|
||||
case PlatformID.Unix:
|
||||
case (PlatformID)128:
|
||||
glWindow = new OpenTK.Platform.X11.X11GLNative();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new PlatformNotSupportedException(
|
||||
"Your platform is not supported currently. Please, refer to http://www.opentk.com for more information.");
|
||||
}
|
||||
if (Configuration.RunningOnWindows)
|
||||
glWindow = new OpenTK.Platform.Windows.WinGLNative();
|
||||
else if (Configuration.RunningOnX11)
|
||||
glWindow = new OpenTK.Platform.X11.X11GLNative();
|
||||
else
|
||||
throw new PlatformNotSupportedException(
|
||||
"Your platform is not supported currently. Please, refer to http://www.opentk.com for more information.");
|
||||
|
||||
glWindow.Destroy += glWindow_Destroy;
|
||||
|
||||
// TODO: GraphicsContext is created inside this call.
|
||||
glWindow.CreateWindow(width, height, format, out glContext);
|
||||
glWindow.CreateWindow(width, height);//, format, out glContext);
|
||||
try
|
||||
{
|
||||
this.glContext = new GraphicsContext(format, this.WindowInfo);
|
||||
}
|
||||
catch (GraphicsContextException e)
|
||||
{
|
||||
glWindow.DestroyWindow();
|
||||
throw;
|
||||
}
|
||||
this.Title = title;
|
||||
|
||||
if (resolution != null)
|
||||
|
@ -161,7 +166,7 @@ namespace OpenTK
|
|||
/// <param name="title">The Title of the GameWindow.</param>
|
||||
[Obsolete]
|
||||
public GameWindow(DisplayMode mode, string title)
|
||||
: this(title, mode.Width, mode.Height, new GraphicsFormat(mode.Color, mode.DepthBits, mode.StencilBits, mode.AuxBits))
|
||||
: this(title, mode.Width, mode.Height, mode.ToGraphicsFormat())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -178,7 +183,7 @@ namespace OpenTK
|
|||
#region public virtual void Exit()
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully exits the GameWindow. May be called from any thread.
|
||||
/// Gracefully exits the GameWindow. May only be called from the thread where the GameWindow was created.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Override if you want to provide yor own exit sequence.</para>
|
||||
|
@ -187,20 +192,44 @@ namespace OpenTK
|
|||
/// </remarks>
|
||||
public virtual void Exit()
|
||||
{
|
||||
isExiting = true;
|
||||
//glWindow.DestroyWindow();
|
||||
//while (glWindow.Exists)
|
||||
// glWindow.ProcessEvents();
|
||||
if (HasMainLoop)
|
||||
ExitAsync();
|
||||
else
|
||||
ExitInternal();
|
||||
//isExiting = true;
|
||||
//UpdateFrame += CallExitInternal;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public virtual void ExitAsync()
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully exits the GameWindow. May be called from any thread.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Override if you want to provide yor own exit sequence.</para>
|
||||
/// <para>If you override this method, place a call to base.ExitAsync(), to ensure
|
||||
/// proper OpenTK shutdown.</para>
|
||||
/// </remarks>
|
||||
public virtual void ExitAsync()
|
||||
{
|
||||
//isExiting = true;
|
||||
UpdateFrame += CallExitInternal;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region void ExitInternal()
|
||||
|
||||
/// <summary>
|
||||
/// Stops the main loop.
|
||||
/// </summary>
|
||||
/// <internal />
|
||||
/// <summary>Stops the main loop.</summary>
|
||||
void ExitInternal()
|
||||
{
|
||||
Debug.Print("Firing GameWindowExitException");
|
||||
//Debug.Print("Firing GameWindowExitException");
|
||||
throw new GameWindowExitException();
|
||||
}
|
||||
|
||||
|
@ -419,7 +448,7 @@ namespace OpenTK
|
|||
|
||||
//try
|
||||
//{
|
||||
OnLoadInternal(EventArgs.Empty);
|
||||
OnLoadInternal(EventArgs.Empty);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
|
@ -431,6 +460,7 @@ namespace OpenTK
|
|||
//Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
|
||||
|
||||
Debug.Print("Entering main loop.");
|
||||
hasMainLoop = true;
|
||||
while (!isExiting)
|
||||
{
|
||||
ProcessEvents();
|
||||
|
|
|
@ -132,25 +132,6 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public DisplayResolution[] AvailableResolutions
|
||||
|
||||
/// <summary>
|
||||
/// Gets an array of OpenTK.DisplayResolution objects, which describe all available resolutions
|
||||
/// for this device.
|
||||
/// </summary>
|
||||
public DisplayResolution[] AvailableResolutions
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (display_lock)
|
||||
{
|
||||
return available_resolutions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public DisplayResolution SelectResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
||||
|
||||
/// <summary>
|
||||
|
@ -179,6 +160,25 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public DisplayResolution[] AvailableResolutions
|
||||
|
||||
/// <summary>
|
||||
/// Gets an array of OpenTK.DisplayResolution objects, which describe all available resolutions
|
||||
/// for this device.
|
||||
/// </summary>
|
||||
public DisplayResolution[] AvailableResolutions
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (display_lock)
|
||||
{
|
||||
return available_resolutions.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void ChangeResolution(DisplayResolution resolution)
|
||||
|
||||
/// <summary>Changes the resolution of the DisplayDevice.</summary>
|
||||
|
|
|
@ -22,6 +22,16 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region --- Constructors ---
|
||||
|
||||
#region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new DisplayResolution object for the primary DisplayDevice.
|
||||
/// </summary>
|
||||
/// <param name="width">The requested width in pixels.</param>
|
||||
/// <param name="height">The requested height in pixels.</param>
|
||||
/// <param name="bitsPerPixel">The requested bits per pixel in bits.</param>
|
||||
/// <param name="refreshRate">The requested refresh rate in Herz.</param>
|
||||
/// <remarks>OpenTK will select the closest match between all available resolutions on the primary DisplayDevice.</remarks>
|
||||
internal DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate)
|
||||
{
|
||||
// Refresh rate may be zero, since this information may not be available on some platforms.
|
||||
|
@ -38,6 +48,40 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
|
||||
|
||||
#if false
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new DisplayResolution object for the specified DisplayDevice.
|
||||
/// </summary>
|
||||
/// <param name="width">The requested width in pixels.</param>
|
||||
/// <param name="height">The requested height in pixels.</param>
|
||||
/// <param name="bitsPerPixel">The requested bits per pixel in bits.</param>
|
||||
/// <param name="refreshRate">The requested refresh rate in Herz.</param>
|
||||
/// <remarks>OpenTK will select the closest match between all available resolutions on the specified DisplayDevice.</remarks>
|
||||
///
|
||||
public DisplayResolution(int width, int height, int bitsPerPixel, float refreshRate, DisplayDevice device)
|
||||
{
|
||||
// Refresh rate may be zero, since this information may not be available on some platforms.
|
||||
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
|
||||
if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
|
||||
if (bitsPerPixel <= 0) throw new ArgumentOutOfRangeException("bitsPerPixel", "Must be greater than zero.");
|
||||
if (refreshRate < 0) throw new ArgumentOutOfRangeException("refreshRate", "Must be greater than, or equal to zero.");
|
||||
if (device == null) throw new ArgumentNullException("DisplayDevice", "Must be a valid DisplayDevice");
|
||||
|
||||
DisplayResolution res = device.SelectResolution(width, height, bitsPerPixel, refreshRate);
|
||||
|
||||
this.width = res.width;
|
||||
this.height = res.height;
|
||||
this.bits_per_pixel = res.bits_per_pixel;
|
||||
this.refresh_rate = res.refresh_rate;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public int Width
|
||||
|
@ -97,7 +141,8 @@ namespace OpenTK.Graphics
|
|||
/// <returns>True if the System.Object is an equal DisplayResolution; false otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is DisplayResolution)
|
||||
if (obj == null) return false;
|
||||
if (this.GetType() == obj.GetType())
|
||||
{
|
||||
DisplayResolution res = (DisplayResolution)obj;
|
||||
return
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing detailed licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
@ -34,30 +36,14 @@ namespace OpenTK.Graphics
|
|||
/// <param name="mode"></param>
|
||||
/// <param name="window"></param>
|
||||
public GraphicsContext(DisplayMode mode, IWindowInfo window)
|
||||
: this(mode.ToGraphicsFormat(), window)
|
||||
{ }
|
||||
|
||||
public GraphicsContext(GraphicsFormat format, IWindowInfo window)
|
||||
{
|
||||
//if (available_contexts.Count == 0)
|
||||
// available_contexts.Add(IntPtr.Zero, new WeakReference(null));
|
||||
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
case (PlatformID)128:
|
||||
implementation = new OpenTK.Platform.X11.X11GLContext();
|
||||
break;
|
||||
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
implementation = new OpenTK.Platform.Windows.WinGLContext();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new PlatformNotSupportedException("Your platform is not supported currently. Please, refer to http://www.opentk.com for more information.");
|
||||
}
|
||||
|
||||
(this as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
(this as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
||||
IGraphicsContext share = null;
|
||||
if (GraphicsContext.ShareContexts)
|
||||
{
|
||||
lock (context_lock)
|
||||
|
@ -65,14 +51,18 @@ namespace OpenTK.Graphics
|
|||
// A small hack to create a shared context with the first available context.
|
||||
foreach (WeakReference r in GraphicsContext.available_contexts.Values)
|
||||
{
|
||||
this.CreateContext(true, (GraphicsContext)r.Target);
|
||||
return;
|
||||
share = (IGraphicsContext)r.Target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only reached if a shared context was not created above, or if this is the first
|
||||
// context ever constructed.
|
||||
this.CreateContext(true, null);
|
||||
|
||||
if (Configuration.RunningOnWindows)
|
||||
implementation = new OpenTK.Platform.Windows.WinGLContext(format, window, share);
|
||||
else if (Configuration.RunningOnX11)
|
||||
implementation = new OpenTK.Platform.X11.X11GLContext();
|
||||
else
|
||||
throw new PlatformNotSupportedException("Your platform is not supported currently. Please, refer to http://www.opentk.com for more information.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -185,6 +175,7 @@ namespace OpenTK.Graphics
|
|||
this.Destroy += ContextDestroyed;
|
||||
|
||||
available_contexts.Add((this as IGLContextInternal).Context, new WeakReference(this));
|
||||
//OpenTK.Graphics.OpenGL.GL.Clear(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit);
|
||||
//if (StaticGetCurrentContext == null)
|
||||
// StaticGetCurrentContext = implementation.GetCurrentContext;
|
||||
}
|
||||
|
@ -256,9 +247,9 @@ namespace OpenTK.Graphics
|
|||
/// <summary>
|
||||
/// Gets the DisplayMode of the context.
|
||||
/// </summary>
|
||||
DisplayMode IGLContextInternal.Mode
|
||||
GraphicsFormat IGLContextInternal.GraphicsFormat
|
||||
{
|
||||
get { return (implementation as IGLContextInternal).Mode; }
|
||||
get { return (implementation as IGLContextInternal).GraphicsFormat; }
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
|
@ -348,9 +339,9 @@ namespace OpenTK.Graphics
|
|||
{
|
||||
// TODO: Check if this is safe
|
||||
//if (manual)
|
||||
{
|
||||
implementation.Dispose();
|
||||
}
|
||||
if (implementation != null)
|
||||
implementation.Dispose();
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,19 +15,19 @@ namespace OpenTK.Graphics
|
|||
/// <summary>Defines the format for graphics operations.</summary>
|
||||
public class GraphicsFormat
|
||||
{
|
||||
private ColorMode color_format, auxilliary_color_format;
|
||||
int depth, stencil, buffers;
|
||||
ColorDepth color_format, accumulator_format;
|
||||
int depth, stencil, buffers, samples;
|
||||
bool stereo;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
#region internal GraphicsFormat(GraphicsFormat mode)
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Constructs a new GraphicsFormat from the given GraphicsFormat.</summary>
|
||||
/// <param name="mode"></param>
|
||||
|
||||
#region public GraphicsFormat(GraphicsFormat mode)
|
||||
|
||||
public GraphicsFormat(GraphicsFormat mode)
|
||||
: this(mode.ColorMode, mode.Depth, mode.Stencil, mode.AuxilliaryColorFormat, mode.Buffers, mode.Stereo) { }
|
||||
internal GraphicsFormat(GraphicsFormat mode)
|
||||
: this(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo) { }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -35,82 +35,107 @@ namespace OpenTK.Graphics
|
|||
|
||||
/// <summary>Constructs a new GraphicsFormat with sensible default parameters.</summary>
|
||||
public GraphicsFormat()
|
||||
: this(DisplayDevice.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 2, false)
|
||||
{
|
||||
}
|
||||
: this(Default)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color)
|
||||
#region public GraphicsFormat(ColorFormat color)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
public GraphicsFormat(ColorMode color)
|
||||
: this(color, 16, 0, 0, 2, false) { }
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
public GraphicsFormat(ColorDepth color)
|
||||
: this(color, Default.Depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color, int depth)
|
||||
#region public GraphicsFormat(ColorFormat color, int depth)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
public GraphicsFormat(ColorMode color, int depth)
|
||||
: this(color, depth, 0, 0, 2, false) { }
|
||||
public GraphicsFormat(ColorDepth color, int depth)
|
||||
: this(color, depth, Default.Stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color, int depth, int stencil)
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
public GraphicsFormat(ColorMode color, int depth, int stencil)
|
||||
: this(color, depth, stencil, 0, 2, false) { }
|
||||
public GraphicsFormat(ColorDepth color, int depth, int stencil)
|
||||
: this(color, depth, stencil, Default.Samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux)
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
/// <param name="aux">The ColorMode of the auxilliary buffer.</param>
|
||||
public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux)
|
||||
: this(color, depth, stencil, aux, 2, false) { }
|
||||
/// <param name="samples">The number of samples for FSAA.</param>
|
||||
public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples)
|
||||
: this(color, depth, stencil, samples, Default.AccumulatorFormat, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux, int buffers)
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
/// <param name="aux">The ColorMode of the auxilliary buffer.</param>
|
||||
/// <param name="samples">The number of samples for FSAA.</param>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum)
|
||||
: this(color, depth, stencil, samples, accum, Default.Buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
/// <param name="samples">The number of samples for FSAA.</param>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux, int buffers)
|
||||
: this(color, depth, stencil, aux, buffers, false) { }
|
||||
public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers)
|
||||
: this(color, depth, stencil, samples, accum, buffers, Default.Stereo)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux, int buffers, bool stereo)
|
||||
#region public GraphicsFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||
|
||||
/// <summary>Constructs a new GraphicsFormat with the specified parameters.</summary>
|
||||
/// <param name="color">The ColorMode of the color buffer.</param>
|
||||
/// <param name="color">The ColorFormat of the color buffer.</param>
|
||||
/// <param name="depth">The number of bits in the depth buffer.</param>
|
||||
/// <param name="stencil">The number of bits in the stencil buffer.</param>
|
||||
/// <param name="aux">The ColorMode of the auxilliary buffer.</param>
|
||||
/// <param name="samples">The number of samples for FSAA.</param>
|
||||
/// <param name="accum">The ColorFormat of the accumilliary buffer.</param>
|
||||
/// <param name="stereo">Set to true for a GraphicsFormat with stereographic capabilities.</param>
|
||||
/// <param name="buffers">The number of render buffers. Typical values include one (single-), two (double-) or three (triple-buffering).</param>
|
||||
public GraphicsFormat(ColorMode color, int depth, int stencil, ColorMode aux, int buffers, bool stereo)
|
||||
public GraphicsFormat(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum, int buffers, bool stereo)
|
||||
{
|
||||
this.ColorMode = color;
|
||||
if (depth < 0) throw new ArgumentOutOfRangeException("depth", "Must be greater than, or equal to zero.");
|
||||
if (stencil < 0) throw new ArgumentOutOfRangeException("stencil", "Must be greater than, or equal to zero.");
|
||||
if (buffers <= 0) throw new ArgumentOutOfRangeException("buffers", "Must be greater than zero.");
|
||||
if (samples < 0) throw new ArgumentOutOfRangeException("samples", "Must be greater than, or equal to zero.");
|
||||
|
||||
this.ColorFormat = color;
|
||||
this.Depth = depth;
|
||||
this.Stencil = stencil;
|
||||
this.AuxilliaryColorFormat = aux;
|
||||
this.AccumulatorFormat = accum;
|
||||
this.Buffers = buffers;
|
||||
this.Stereo = stereo;
|
||||
}
|
||||
|
@ -121,12 +146,12 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public int ColorMode
|
||||
#region public int ColorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode.
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the color format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorMode ColorMode
|
||||
public ColorDepth ColorFormat
|
||||
{
|
||||
get { return color_format; }
|
||||
private set { color_format = value; }
|
||||
|
@ -134,15 +159,15 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region public int AuxilliaryColorFormat
|
||||
#region public int AccumulatorFormat
|
||||
|
||||
/// <summary>
|
||||
/// Gets an OpenTK.Graphics.ColorMode that describes the color format of this DisplayMode.
|
||||
/// Gets an OpenTK.Graphics.ColorFormat that describes the accumulator format for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public ColorMode AuxilliaryColorFormat
|
||||
public ColorDepth AccumulatorFormat
|
||||
{
|
||||
get { return auxilliary_color_format; }
|
||||
private set { auxilliary_color_format = value; }
|
||||
get { return accumulator_format; }
|
||||
private set { accumulator_format = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -151,7 +176,7 @@ namespace OpenTK.Graphics
|
|||
|
||||
/// <summary>
|
||||
/// Gets a System.Int32 that contains the bits per pixel for the depth buffer
|
||||
/// of this DisplayMode.
|
||||
/// for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public int Depth
|
||||
{
|
||||
|
@ -165,7 +190,7 @@ namespace OpenTK.Graphics
|
|||
|
||||
/// <summary>
|
||||
/// Gets a System.Int32 that contains the bits per pixel for the stencil buffer
|
||||
/// of this DisplayMode.
|
||||
/// of this GraphicsFormat.
|
||||
/// </summary>
|
||||
public int Stencil
|
||||
{
|
||||
|
@ -175,6 +200,15 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets a System.Int32 that contains the number of FSAA samples per pixel for this GraphicsFormat.
|
||||
/// </summary>
|
||||
public int Samples
|
||||
{
|
||||
get { return samples; }
|
||||
private set { samples = value; }
|
||||
}
|
||||
|
||||
#region public bool Stereo
|
||||
|
||||
/// <summary>
|
||||
|
@ -207,11 +241,23 @@ namespace OpenTK.Graphics
|
|||
/// <summary>Returns an OpenTK.GraphicsFormat compatible with the underlying platform.</summary>
|
||||
public static GraphicsFormat Default
|
||||
{
|
||||
get { return new GraphicsFormat(DisplayDevice.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 2, false); }
|
||||
get { return new GraphicsFormat(DisplayDevice.PrimaryDisplay.BitsPerPixel, 16, 0, 0, 0, 2, false); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
/// <summary>Returns a System.String describing the current GraphicsFormat.</summary>
|
||||
/// <returns>! System.String describing the current GraphicsFormat.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Color: {0}, Depth: {1}, Stencil: {2}, Samples: {3}, Accum: {4}, Buffers: {5}, Stereo: {6}",
|
||||
ColorFormat, Depth, Stereo, Samples, AccumulatorFormat, Buffers, Stereo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing detailed licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
@ -8,7 +10,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides methods for creating and interacting with an OpenGL context.
|
||||
|
@ -74,10 +78,8 @@ namespace OpenTK.Platform
|
|||
/// </summary>
|
||||
IWindowInfo Info { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DisplayMode of the context.
|
||||
/// </summary>
|
||||
DisplayMode Mode { get; }
|
||||
/// <summary>Gets the GraphicsFormat of the context.</summary>
|
||||
GraphicsFormat GraphicsFormat { get; }
|
||||
|
||||
///// <summary>
|
||||
///// Gets a System.IntPtr containing the handle to the OpenGL context which is current in the
|
||||
|
|
|
@ -33,12 +33,12 @@ namespace OpenTK
|
|||
if (Environment.OSVersion.Version.Major > 5 ||
|
||||
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
|
||||
{
|
||||
inputDriver = new OpenTK.Platform.Windows.WinRawInput(parent.WindowInfo);
|
||||
inputDriver = new OpenTK.Platform.Windows.WinRawInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Legacy or unknown windows version:
|
||||
inputDriver = new OpenTK.Platform.Windows.WMInput(parent.WindowInfo);
|
||||
inputDriver = new OpenTK.Platform.Windows.WMInput((OpenTK.Platform.Windows.WinWindowInfo)parent.WindowInfo);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
|
@ -16,21 +17,19 @@ namespace OpenTK.Platform
|
|||
/// </summary>
|
||||
internal sealed class DummyGLContext : IGraphicsContext
|
||||
{
|
||||
WindowInfo info = new WindowInfo();
|
||||
DisplayMode mode;
|
||||
GraphicsFormat format;
|
||||
bool vsync;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
public DummyGLContext(DisplayMode m) { mode = m; }
|
||||
public DummyGLContext(GraphicsFormat format) { this.format = format; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
public IntPtr Context { get { return IntPtr.Zero; } }
|
||||
public IWindowInfo Info { get { return info; } }
|
||||
public DisplayMode Mode { get { return mode; } }
|
||||
public GraphicsFormat GraphicsFormat { get { return format; } }
|
||||
|
||||
public void CreateContext() { }
|
||||
public void CreateContext(bool direct) { }
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides methods to
|
||||
/// </summary>
|
||||
public interface IMutableWindowInfo : IWindowInfoOld
|
||||
{
|
||||
void CopyInfoFrom(IWindowInfoOld info);
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace OpenTK.Platform
|
|||
internal interface INativeGLWindow : IResizable, IDisposable
|
||||
{
|
||||
//void CreateWindow(int width, int height, DisplayMode mode, out IGraphicsContext context);
|
||||
void CreateWindow(int width, int height, GraphicsFormat mode, out IGraphicsContext context);
|
||||
void CreateWindow(int width, int height);//, GraphicsFormat mode, out IGraphicsContext context);
|
||||
void DestroyWindow();
|
||||
void ProcessEvents();
|
||||
void PointToClient(ref System.Drawing.Point p);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a platform independent mechanism to interact with System.Windows.Forms.Control,
|
||||
/// System.Windows.Forms.NativeWindow and OpenTK.GameWindow low-level implementation data.
|
||||
/// </summary>
|
||||
[Obsolete("Use OpenTK.Platform.IWindowInfo instead.")]
|
||||
public interface IWindowInfoOld
|
||||
{
|
||||
IntPtr Handle { get; }
|
||||
IWindowInfoOld Parent { get; }
|
||||
IWindowInfoOld GetInfoFrom(System.Windows.Forms.Control control);
|
||||
IWindowInfoOld GetInfoFrom(System.Windows.Forms.NativeWindow window);
|
||||
IWindowInfoOld GetInfoFrom(OpenTK.GameWindow window);
|
||||
IWindowInfoOld GetInfoFrom(IWindowInfoOld info);
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow.
|
||||
/// </summary>
|
||||
public sealed class WindowInfo : IMutableWindowInfo
|
||||
{
|
||||
IMutableWindowInfo implementation;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
/// <summary>
|
||||
/// Detects the underlying platform and constructs a new WindowInfo class.
|
||||
/// </summary>
|
||||
/// <exception cref="PlatformNotSupportedException">Raised when the underlying platform is not supported.</exception>
|
||||
public WindowInfo()
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
case (PlatformID)128:
|
||||
implementation = new X11.WindowInfo();
|
||||
break;
|
||||
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
implementation = new Windows.WindowInfo();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new PlatformNotSupportedException("Your Operating System is not supported. Please refer to http://opentk.sourceforge.net for more information.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the underlying platform and constructs a new WindowInfo class describing the specified Control.
|
||||
/// </summary>
|
||||
/// <param name="control">The System.Windows.Forms.Control to get info from.</param>
|
||||
public WindowInfo(Control control) : this()
|
||||
{
|
||||
implementation.CopyInfoFrom(implementation.GetInfoFrom(control));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the underlying platform and constructs a new WindowInfo class describing the specified NativeWindow.
|
||||
/// </summary>
|
||||
/// <param name="window">The System.Windows.Forms.NativeWindow to get info from.</param>
|
||||
public WindowInfo(NativeWindow window) : this()
|
||||
{
|
||||
implementation.CopyInfoFrom(implementation.GetInfoFrom(window));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the underlying platform and constructs a new WindowInfo class describing the specified GameWindow.
|
||||
/// </summary>
|
||||
/// <param name="window">The OpenTK.GameWindow to get info from.</param>
|
||||
public WindowInfo(GameWindow window) : this()
|
||||
{
|
||||
implementation.CopyInfoFrom(implementation.GetInfoFrom(window));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IWindowInfo Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Gets the platform specific handle of the window described by the WindowInfo class.
|
||||
/// </summary>
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return implementation.Handle; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the window described by the WindowInfo class.
|
||||
/// </summary>
|
||||
public IWindowInfoOld Parent
|
||||
{
|
||||
get { return implementation.Parent; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the WindowInfo to describe the specified Control.
|
||||
/// </summary>
|
||||
/// <param name="control">The System.Windows.Forms.Control to describe.</param>
|
||||
public IWindowInfoOld GetInfoFrom(Control control)
|
||||
{
|
||||
return implementation.GetInfoFrom(control);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the WindowInfo to describe the specified NativeWindow.
|
||||
/// </summary>
|
||||
/// <param name="window">The System.Windows.Forms.NativeWindow to describe.</param>
|
||||
public IWindowInfoOld GetInfoFrom(NativeWindow window)
|
||||
{
|
||||
return implementation.GetInfoFrom(window);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the WindowInfo to describe the specified GameWindow.
|
||||
/// </summary>
|
||||
/// <param name="window">The OpenTK.GameWindow to describe.</param>
|
||||
public IWindowInfoOld GetInfoFrom(GameWindow window)
|
||||
{
|
||||
return implementation.GetInfoFrom(window);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the WindowInfo using the specified IWindowInfo.
|
||||
/// </summary>
|
||||
/// <param name="window">The OpenTK.Platform.IWindowInfo to get information from.</param>
|
||||
public IWindowInfoOld GetInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
return implementation.GetInfoFrom(info);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
void IMutableWindowInfo.CopyInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
implementation.CopyInfoFrom(info);
|
||||
}
|
||||
|
||||
//public static explicit operator Windows.WindowInfo(WindowInfo info)
|
||||
//{
|
||||
// return (Windows.WindowInfo)info.implementation;
|
||||
//}
|
||||
|
||||
//public static explicit operator X11.WindowInfo(WindowInfo info)
|
||||
//{
|
||||
// return (X11.WindowInfo)info.implementation;
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -28,7 +28,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- Constructor ---
|
||||
|
||||
public WMInput(IWindowInfo parent)
|
||||
public WMInput(WinWindowInfo parent)
|
||||
{
|
||||
Debug.WriteLine("Initalizing WMInput driver.");
|
||||
Debug.Indent();
|
||||
|
|
|
@ -26,65 +26,68 @@ namespace OpenTK.Platform.Windows
|
|||
/// </summary>
|
||||
internal sealed class WinGLContext : IGraphicsContext, IGLContextInternal, IGLContextCreationHack
|
||||
{
|
||||
private IntPtr deviceContext;
|
||||
private ContextHandle renderContext;
|
||||
static private IntPtr opengl32Handle;
|
||||
private const string opengl32Name = "OPENGL32.DLL";
|
||||
private WindowInfo windowInfo = new WindowInfo();
|
||||
IntPtr deviceContext;
|
||||
ContextHandle renderContext;
|
||||
static IntPtr opengl32Handle;
|
||||
const string opengl32Name = "OPENGL32.DLL";
|
||||
WinWindowInfo windowInfo = new WinWindowInfo();
|
||||
|
||||
private DisplayMode mode = null;
|
||||
private bool vsync_supported;
|
||||
GraphicsFormat format;
|
||||
//DisplayMode mode = null;
|
||||
bool vsync_supported;
|
||||
|
||||
private bool disposed;
|
||||
bool disposed;
|
||||
|
||||
#region --- Contructors ---
|
||||
|
||||
static WinGLContext()
|
||||
{
|
||||
// Set the GetCurrentContext implementation.
|
||||
// TODO: Does this belong here?
|
||||
if (GraphicsContext.GetCurrentContext == null)
|
||||
GraphicsContext.GetCurrentContext = WinGLContext.GetCurrentContext;
|
||||
|
||||
// Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
|
||||
if (opengl32Handle == IntPtr.Zero)
|
||||
{
|
||||
opengl32Handle = Functions.LoadLibrary(opengl32Name);
|
||||
if (opengl32Handle == IntPtr.Zero)
|
||||
throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
|
||||
opengl32Name, Marshal.GetLastWin32Error()));
|
||||
Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public WinGLContext()
|
||||
GraphicsFormat SelectFormat(GraphicsFormat format)
|
||||
{
|
||||
using (WinGLNative native = new WinGLNative(16, 16))
|
||||
//using (WinGLContext context = new WinGLContext(format, native.WindowInfo, null))
|
||||
{
|
||||
// Find the best multisampling mode.
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
public void CreateContext()
|
||||
public WinGLContext(GraphicsFormat format, IWindowInfo window, IGraphicsContext sharedContext)
|
||||
{
|
||||
this.CreateContext(true, null);
|
||||
}
|
||||
//format = this.SelectFormat(format);
|
||||
|
||||
#endregion
|
||||
this.windowInfo = (WinWindowInfo)window;
|
||||
Debug.Print("OpenGL will be bound to handle: {0}", this.windowInfo.Handle);
|
||||
if (this.windowInfo.Handle == IntPtr.Zero)
|
||||
throw new ArgumentException("window", "Must be a valid window.");
|
||||
|
||||
#region public void CreateContext(bool direct)
|
||||
|
||||
public void CreateContext(bool direct)
|
||||
{
|
||||
this.CreateContext(direct, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext(bool direct, IGraphicsContext source)
|
||||
|
||||
public void CreateContext(bool direct, IGraphicsContext source)
|
||||
{
|
||||
Debug.WriteLine(String.Format("OpenGL context is bound to handle: {0}", this.windowInfo.Handle));
|
||||
Debug.Print("Setting pixel format...");
|
||||
this.format = this.SetGraphicsFormatPFD(format);
|
||||
|
||||
Debug.Write("Creating render context... ");
|
||||
// Do not rely on OpenTK.Platform.Windows.Wgl - the context is not ready yet,
|
||||
// and Wgl extensions will fail to load.
|
||||
renderContext = new ContextHandle(Wgl.Imports.CreateContext(deviceContext));
|
||||
if (renderContext == IntPtr.Zero)
|
||||
throw new ApplicationException("Could not create OpenGL render context (Wgl.CreateContext() return 0).");
|
||||
|
||||
throw new GraphicsContextException(String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
|
||||
Marshal.GetLastWin32Error()));
|
||||
|
||||
Debug.WriteLine(String.Format("done! (id: {0})", renderContext));
|
||||
|
||||
Wgl.Imports.MakeCurrent(deviceContext, renderContext);
|
||||
|
@ -95,15 +98,46 @@ namespace OpenTK.Platform.Windows
|
|||
vsync_supported = Wgl.Arb.SupportsExtension(this, "WGL_EXT_swap_control") &&
|
||||
Wgl.Load("wglGetSwapIntervalEXT") && Wgl.Load("wglSwapIntervalEXT");
|
||||
|
||||
if (source != null)
|
||||
if (sharedContext != null)
|
||||
{
|
||||
Debug.Print("Sharing state with context {0}", (source as IGLContextInternal).Context);
|
||||
Wgl.Imports.ShareLists(renderContext, (source as IGLContextInternal).Context);
|
||||
Debug.Print("Sharing state with context {0}", sharedContext.ToString());
|
||||
Wgl.Imports.ShareLists(renderContext, (sharedContext as IGLContextInternal).Context);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
public void CreateContext()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
this.CreateContext(true, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext(bool direct)
|
||||
|
||||
public void CreateContext(bool direct)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
this.CreateContext(direct, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext(bool direct, IGraphicsContext source)
|
||||
|
||||
public void CreateContext(bool direct, IGraphicsContext source)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void SwapBuffers()
|
||||
|
||||
public void SwapBuffers()
|
||||
|
@ -168,7 +202,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
#region public IntPtr Context
|
||||
#region ContextHandle IGLContextInternal.Context
|
||||
|
||||
ContextHandle IGLContextInternal.Context
|
||||
{
|
||||
|
@ -177,21 +211,20 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public IWindowInfo Info
|
||||
#region IWindowInfo IGLContextInternal.Info
|
||||
|
||||
IWindowInfo IGLContextInternal.Info
|
||||
{
|
||||
get { return windowInfo; }
|
||||
get { return (IWindowInfo)windowInfo; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public DisplayMode Mode
|
||||
#region GraphicsFormat IGLContextInternal.GraphicsFormat
|
||||
|
||||
[Obsolete]
|
||||
DisplayMode IGLContextInternal.Mode
|
||||
GraphicsFormat IGLContextInternal.GraphicsFormat
|
||||
{
|
||||
get { return new DisplayMode(mode); }
|
||||
get { return format; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -232,6 +265,87 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Methods ---
|
||||
|
||||
#region GraphicsFormat SetGraphicsFormatPFD(GraphicsFormat format)
|
||||
|
||||
GraphicsFormat SetGraphicsFormatPFD(GraphicsFormat format)
|
||||
{
|
||||
deviceContext = Functions.GetDC(this.windowInfo.Handle);
|
||||
Debug.WriteLine(String.Format("Device context: {0}", deviceContext));
|
||||
|
||||
Debug.Write("Setting pixel format... ");
|
||||
PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor();
|
||||
pixelFormat.Size = API.PixelFormatDescriptorSize;
|
||||
pixelFormat.Version = API.PixelFormatDescriptorVersion;
|
||||
pixelFormat.Flags =
|
||||
PixelFormatDescriptorFlags.SUPPORT_OPENGL |
|
||||
PixelFormatDescriptorFlags.DRAW_TO_WINDOW;
|
||||
pixelFormat.ColorBits = (byte)(format.ColorFormat.Red + format.ColorFormat.Green + format.ColorFormat.Blue);
|
||||
|
||||
pixelFormat.PixelType = format.ColorFormat.IsIndexed ? PixelType.INDEXED : PixelType.RGBA;
|
||||
pixelFormat.PixelType = PixelType.RGBA;
|
||||
pixelFormat.RedBits = (byte)format.ColorFormat.Red;
|
||||
pixelFormat.GreenBits = (byte)format.ColorFormat.Green;
|
||||
pixelFormat.BlueBits = (byte)format.ColorFormat.Blue;
|
||||
pixelFormat.AlphaBits = (byte)format.ColorFormat.Alpha;
|
||||
|
||||
if (format.AccumulatorFormat != null)
|
||||
{
|
||||
pixelFormat.AccumBits = (byte)(format.AccumulatorFormat.Red + format.AccumulatorFormat.Green + format.AccumulatorFormat.Blue);
|
||||
pixelFormat.AccumRedBits = (byte)format.AccumulatorFormat.Red;
|
||||
pixelFormat.AccumGreenBits = (byte)format.AccumulatorFormat.Green;
|
||||
pixelFormat.AccumBlueBits = (byte)format.AccumulatorFormat.Blue;
|
||||
pixelFormat.AccumAlphaBits = (byte)format.AccumulatorFormat.Alpha;
|
||||
}
|
||||
|
||||
pixelFormat.DepthBits = (byte)format.Depth;
|
||||
pixelFormat.StencilBits = (byte)format.Stencil;
|
||||
|
||||
if (format.Depth <= 0) pixelFormat.Flags |= PixelFormatDescriptorFlags.DEPTH_DONTCARE;
|
||||
if (format.Stereo) pixelFormat.Flags |= PixelFormatDescriptorFlags.STEREO;
|
||||
if (format.Buffers > 1) pixelFormat.Flags |= PixelFormatDescriptorFlags.DOUBLEBUFFER;
|
||||
|
||||
int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat);
|
||||
if (pixel == 0)
|
||||
throw new GraphicsModeException(String.Format("The requested format is not available: {0}.", format));
|
||||
|
||||
// Find out what we really got as a format:
|
||||
PixelFormatDescriptor pfd = new PixelFormatDescriptor();
|
||||
pixelFormat.Size = API.PixelFormatDescriptorSize;
|
||||
pixelFormat.Version = API.PixelFormatDescriptorVersion;
|
||||
Functions.DescribePixelFormat(deviceContext, pixel, API.PixelFormatDescriptorSize, ref pfd);
|
||||
GraphicsFormat fmt = new GraphicsFormat(
|
||||
new ColorDepth(pfd.RedBits, pfd.GreenBits, pfd.BlueBits, pfd.AlphaBits),
|
||||
pfd.DepthBits,
|
||||
pfd.StencilBits,
|
||||
0,
|
||||
new ColorDepth(pfd.AccumBits),
|
||||
(pfd.Flags & PixelFormatDescriptorFlags.DOUBLEBUFFER) != 0 ? 2 : 1,
|
||||
(pfd.Flags & PixelFormatDescriptorFlags.STEREO) != 0);
|
||||
|
||||
if (!Functions.SetPixelFormat(deviceContext, pixel, ref pixelFormat))
|
||||
throw new GraphicsContextException(String.Format("Requested GraphicsFormat not available. SetPixelFormat error: {0}",
|
||||
Marshal.GetLastWin32Error()));
|
||||
Debug.Print("done! (format: {0})", pixel);
|
||||
|
||||
return fmt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GraphicsFormat SetGraphicsFormatARB(GraphicsFormat format)
|
||||
|
||||
GraphicsFormat SetGraphicsFormatARB(GraphicsFormat format)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGLContextCreationHack Members ---
|
||||
|
@ -259,7 +373,6 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
|
||||
}
|
||||
|
||||
deviceContext = Functions.GetDC(this.windowInfo.Handle);
|
||||
Debug.WriteLine(String.Format("Device context: {0}", deviceContext));
|
||||
|
||||
|
@ -350,7 +463,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Methods ---
|
||||
#region --- Internal Methods ---
|
||||
|
||||
#region internal IntPtr Device
|
||||
|
||||
|
@ -369,6 +482,17 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
/// <summary>Returns a System.String describing this OpenGL context.</summary>
|
||||
/// <returns>A System.String describing this OpenGL context.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return (this as IGLContextInternal).Context.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace OpenTK.Platform.Windows
|
|||
private bool disposed;
|
||||
private bool isExiting;
|
||||
private bool exists;
|
||||
private WindowInfo window = new WindowInfo();
|
||||
private WinWindowInfo window;
|
||||
private int top, bottom, left, right;
|
||||
private int width = 0, height = 0;
|
||||
private Rectangle pre_maximized;
|
||||
|
@ -53,15 +53,25 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- Contructors ---
|
||||
|
||||
/// <internal />
|
||||
/// <summary>
|
||||
/// Constructs a new WinGLNative class. Call CreateWindow to create the
|
||||
/// actual render window.
|
||||
/// </summary>
|
||||
public WinGLNative()
|
||||
internal WinGLNative()
|
||||
{
|
||||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
}
|
||||
|
||||
/// <internal />
|
||||
/// <summary>Constructs a new win32 top-level window with the specified size.</summary>
|
||||
internal WinGLNative(int width, int height)
|
||||
: this()
|
||||
{
|
||||
this.CreateWindow(width, height);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region protected override void WndProc(ref Message m)
|
||||
|
@ -182,7 +192,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public bool Quit
|
||||
#region public bool IsExiting
|
||||
|
||||
public bool IsExiting
|
||||
{
|
||||
|
@ -217,7 +227,10 @@ namespace OpenTK.Platform.Windows
|
|||
command = ShowWindowCommand.SHOWNORMAL;
|
||||
}
|
||||
|
||||
Functions.SetWindowLongPtr(Handle, GetWindowLongOffsets.STYLE, style);
|
||||
// This calls a C# function that determines whether we need SetWindowLong (32bit platforms)
|
||||
// or SetWindowLongPtr (64bit). This happens because SetWindowLongPtr is a macro on 32bit
|
||||
// platforms, and is *not* available as a function.
|
||||
Functions.SetWindowLong(Handle, GetWindowLongOffsets.STYLE, style);
|
||||
Functions.ShowWindow(Handle, command);
|
||||
if (!value && Fullscreen)
|
||||
Functions.SetWindowPos(Handle, WindowPlacementOptions.TOP, 0, 0, pre_maximized.Width, pre_maximized.Height,
|
||||
|
@ -307,13 +320,13 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void CreateWindow(int width, int height, GraphicsFormat format, out IGraphicsContext context)
|
||||
#region public void CreateWindow(int width, int height)
|
||||
|
||||
public void CreateWindow(int width, int height, GraphicsFormat format, out IGraphicsContext context)
|
||||
public void CreateWindow(int width, int height)//, GraphicsFormat format, out IGraphicsContext context)
|
||||
{
|
||||
Debug.Print("Creating native window.");
|
||||
Debug.Indent();
|
||||
Debug.Print("GraphicsFormat: {0}", format.ToString());
|
||||
//Debug.Print("GraphicsFormat: {0}", format.ToString());
|
||||
|
||||
CreateParams cp = new CreateParams();
|
||||
cp.ClassStyle =
|
||||
|
@ -370,10 +383,10 @@ namespace OpenTK.Platform.Windows
|
|||
//context = new GraphicsContext(mode, window);
|
||||
//context.CreateContext();
|
||||
|
||||
context = new WinGLContext();
|
||||
(context as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
(context as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
||||
context.CreateContext(true, null);
|
||||
//context = new WinGLContext();
|
||||
//(context as IGLContextCreationHack).SetWindowHandle(window.Handle);
|
||||
//(context as IGLContextCreationHack).SelectDisplayMode(mode, window);
|
||||
//context.CreateContext(true, null);
|
||||
|
||||
Debug.Unindent();
|
||||
}
|
||||
|
@ -386,9 +399,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public void OnCreate(EventArgs e)
|
||||
{
|
||||
this.window.Handle = this.Handle;
|
||||
this.window.Parent = null;
|
||||
//this.window = new WindowInfo(this);
|
||||
this.window = new WinWindowInfo(Handle, null);
|
||||
|
||||
//driver = new WinRawInput(this.window); // Disabled until the mouse issues are resolved.
|
||||
driver = new WMInput(this.window);
|
||||
|
@ -409,7 +420,8 @@ namespace OpenTK.Platform.Windows
|
|||
public void DestroyWindow()
|
||||
{
|
||||
Debug.Print("Destroying window: {0}", window.ToString());
|
||||
Functions.PostMessage(this.Handle, WindowMessage.DESTROY, IntPtr.Zero, IntPtr.Zero);
|
||||
//Functions.PostMessage(this.Handle, WindowMessage.DESTROY, IntPtr.Zero, IntPtr.Zero);
|
||||
Functions.DestroyWindow(this.Handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- Constructors ---
|
||||
|
||||
internal WinRawInput(IWindowInfo parent)
|
||||
internal WinRawInput(WinWindowInfo parent)
|
||||
{
|
||||
Debug.WriteLine("Initalizing windows raw input driver.");
|
||||
Debug.Indent();
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the Windows platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
[Obsolete("Use OpenTK.Platform.Windows.WinWindowInfo instead.")]
|
||||
public sealed class WindowInfo : IMutableWindowInfo
|
||||
{
|
||||
private IntPtr handle;
|
||||
|
@ -26,7 +27,7 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
}
|
||||
|
||||
public WindowInfo(IWindowInfo info)
|
||||
public WindowInfo(IWindowInfoOld info)
|
||||
{
|
||||
/*
|
||||
if (info == null)
|
||||
|
@ -64,7 +65,7 @@ namespace OpenTK.Platform.Windows
|
|||
this.Handle = window.WindowInfo.Handle;
|
||||
this.Parent = window.WindowInfo.Parent;
|
||||
*/
|
||||
this.CopyInfoFrom(window.WindowInfo);
|
||||
//this.CopyInfoFrom(window.WindowInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -77,7 +78,7 @@ namespace OpenTK.Platform.Windows
|
|||
internal set { handle = value; }
|
||||
}
|
||||
|
||||
public IWindowInfo Parent
|
||||
public IWindowInfoOld Parent
|
||||
{
|
||||
get { return parent; }
|
||||
internal set
|
||||
|
@ -86,7 +87,7 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(Control control)
|
||||
public IWindowInfoOld GetInfoFrom(Control control)
|
||||
{
|
||||
if (control == null)
|
||||
throw new ArgumentException("Control cannot be null.");
|
||||
|
@ -94,7 +95,7 @@ namespace OpenTK.Platform.Windows
|
|||
return new WindowInfo(control);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(NativeWindow window)
|
||||
public IWindowInfoOld GetInfoFrom(NativeWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("NativeWindow cannot be null.");
|
||||
|
@ -102,15 +103,15 @@ namespace OpenTK.Platform.Windows
|
|||
return new WindowInfo(window);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(GameWindow window)
|
||||
public IWindowInfoOld GetInfoFrom(GameWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
return GetInfoFrom(window.WindowInfo as Windows.WindowInfo);
|
||||
throw new NotSupportedException();
|
||||
//return GetInfoFrom(window.WindowInfo as Windows.WindowInfo);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(IWindowInfo info)
|
||||
public IWindowInfoOld GetInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
if (info == null)
|
||||
throw new ArgumentException("IWindowInfo cannot be null.");
|
||||
|
@ -122,7 +123,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public void CopyInfoFrom(IWindowInfo info)
|
||||
public void CopyInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
this.Handle = info.Handle;
|
||||
this.Parent = info.Parent;
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Windows.Forms;
|
|||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the X11 platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
|
@ -30,7 +31,7 @@ namespace OpenTK.Platform.X11
|
|||
//visinfo = new XVisualInfo();
|
||||
}
|
||||
|
||||
public WindowInfo(IWindowInfo info)
|
||||
public WindowInfo(IWindowInfoOld info)
|
||||
{
|
||||
this.CopyInfoFrom(info);
|
||||
}
|
||||
|
@ -61,16 +62,16 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
this.CopyInfoFrom(window.WindowInfo);
|
||||
throw new NotSupportedException();
|
||||
//this.CopyInfoFrom(window.WindowInfo);
|
||||
}
|
||||
|
||||
#region --- IWindowInfo Members ---
|
||||
#region --- IWindowInfo Members ---
|
||||
|
||||
public IntPtr Handle { get { return handle; } internal set { handle = value; } }
|
||||
public IWindowInfo Parent { get { return parent; } internal set { parent = value as WindowInfo; } }
|
||||
public IWindowInfoOld Parent { get { return parent; } internal set { parent = value as WindowInfo; } }
|
||||
|
||||
public IWindowInfo GetInfoFrom(Control control)
|
||||
public IWindowInfoOld GetInfoFrom(Control control)
|
||||
{
|
||||
if (control == null)
|
||||
throw new ArgumentException("Control cannot be null.");
|
||||
|
@ -78,7 +79,7 @@ namespace OpenTK.Platform.X11
|
|||
return new WindowInfo(control);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(NativeWindow window)
|
||||
public IWindowInfoOld GetInfoFrom(NativeWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("NativeWindow cannot be null.");
|
||||
|
@ -86,15 +87,16 @@ namespace OpenTK.Platform.X11
|
|||
return new WindowInfo(window);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(GameWindow window)
|
||||
public IWindowInfoOld GetInfoFrom(GameWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
return this.GetInfoFrom(window.WindowInfo);
|
||||
throw new NotSupportedException();
|
||||
//return this.GetInfoFrom(window.WindowInfo);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(IWindowInfo info)
|
||||
public IWindowInfoOld GetInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
if (info == null)
|
||||
throw new ArgumentException("WindowInfo cannot be null");
|
||||
|
@ -104,12 +106,12 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public void CopyInfoFrom(IWindowInfo info)
|
||||
public void CopyInfoFrom(IWindowInfoOld info)
|
||||
{
|
||||
if (info == null)
|
||||
throw new ArgumentException("IWindowInfo info cannot be null.");
|
||||
throw new ArgumentNullException("IWindowInfo", "Cannot be null.");
|
||||
this.Handle = info.Handle;
|
||||
this.Parent = info.Parent;
|
||||
|
||||
|
@ -117,7 +119,7 @@ namespace OpenTK.Platform.X11
|
|||
// X11.WindowInfo winfo = info as X11.WindowInfo ?? (X11.WindowInfo)(info as Platform.WindowInfo);
|
||||
X11.WindowInfo winfo = info as X11.WindowInfo;
|
||||
if (winfo == null)
|
||||
winfo = new WindowInfo(info);//(X11.WindowInfo)(info as Platform.WindowInfo);
|
||||
//winfo = (X11.WindowInfo)(info as Platform.WindowInfo);
|
||||
|
||||
this.RootWindow = winfo.RootWindow;
|
||||
this.TopLevelWindow = winfo.TopLevelWindow;
|
||||
|
@ -159,4 +161,5 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
IntPtr context;
|
||||
DisplayMode mode;
|
||||
WindowInfo windowInfo = new WindowInfo();
|
||||
X11WindowInfo windowInfo = new X11WindowInfo();
|
||||
GraphicsFormat format;
|
||||
IntPtr visual;
|
||||
bool vsync_supported;
|
||||
int vsync_interval;
|
||||
|
@ -97,7 +98,7 @@ namespace OpenTK.Platform.X11
|
|||
visualAttributes.Add((int)0);
|
||||
}
|
||||
|
||||
windowInfo.CopyInfoFrom(info);
|
||||
//windowInfo.CopyInfoFrom(info);
|
||||
visual = Glx.ChooseVisual(windowInfo.Display, windowInfo.Screen, visualAttributes.ToArray());
|
||||
if (visual == IntPtr.Zero)
|
||||
return false;
|
||||
|
@ -121,22 +122,6 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region public DisplayMode Mode
|
||||
|
||||
public DisplayMode Mode
|
||||
{
|
||||
get { return mode; }
|
||||
private set
|
||||
{
|
||||
if (context == IntPtr.Zero)
|
||||
mode = value;
|
||||
else
|
||||
Debug.Print("Cannot change DisplayMode of an existing context.");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void CreateContext()
|
||||
|
||||
public void CreateContext()
|
||||
|
@ -319,6 +304,15 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
#region public DisplayMode Mode
|
||||
|
||||
GraphicsFormat IGLContextInternal.GraphicsFormat
|
||||
{
|
||||
get { return format; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IntPtr IGLContextInternal.Context
|
||||
|
||||
ContextHandle IGLContextInternal.Context
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#region --- Fields ---
|
||||
|
||||
private WindowInfo window = new WindowInfo();
|
||||
private X11WindowInfo window = new X11WindowInfo();
|
||||
private DisplayMode mode = new DisplayMode();
|
||||
private X11Input driver;
|
||||
|
||||
|
@ -102,7 +102,7 @@ namespace OpenTK.Platform.X11
|
|||
/// Not used yet.
|
||||
/// Registers the necessary atoms for GameWindow.
|
||||
/// </summary>
|
||||
private static void RegisterAtoms(WindowInfo window)
|
||||
private static void RegisterAtoms(X11WindowInfo window)
|
||||
{
|
||||
string[] atom_names = new string[]
|
||||
{
|
||||
|
@ -392,10 +392,11 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void CreateWindow(int width, int height, GraphicsFormat format, out IGraphicsContext glContext)
|
||||
#region public void CreateWindow(int width, int height)
|
||||
|
||||
public void CreateWindow(int width, int height, GraphicsFormat format, out IGraphicsContext glContext)
|
||||
public void CreateWindow(int width, int height)
|
||||
{
|
||||
#if false
|
||||
if (exists)
|
||||
throw new ApplicationException("Render window already exists!");
|
||||
|
||||
|
@ -407,7 +408,7 @@ namespace OpenTK.Platform.X11
|
|||
if (glContext == null)
|
||||
throw new ApplicationException("Could not create GraphicsContext");
|
||||
Debug.Print("Created GraphicsContext");
|
||||
window.VisualInfo = ((X11.WindowInfo)((IGLContextInternal)glContext).Info).VisualInfo;
|
||||
window.VisualInfo = ((X11WindowInfo)((IGLContextInternal)glContext).Info).VisualInfo;
|
||||
//window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen,
|
||||
|
||||
// Create a window on this display using the visual above
|
||||
|
@ -474,6 +475,7 @@ namespace OpenTK.Platform.X11
|
|||
Debug.Unindent();
|
||||
Debug.WriteLine("GameWindow creation completed successfully!");
|
||||
exists = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -493,7 +495,8 @@ namespace OpenTK.Platform.X11
|
|||
/// </remarks>
|
||||
public void CreateWindow(int width, int height, DisplayMode mode, out IGraphicsContext glContext)
|
||||
{
|
||||
this.CreateWindow(width, height, mode.ToGraphicsFormat(), out glContext);
|
||||
this.CreateWindow(width, height);//, mode.ToGraphicsFormat(), out glContext);
|
||||
glContext = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace OpenTK.Platform.X11
|
|||
/// </summary>
|
||||
internal sealed class X11Input : IInputDriver
|
||||
{
|
||||
X11.WindowInfo window;
|
||||
X11WindowInfo window;
|
||||
KeyboardDevice keyboard = new KeyboardDevice();
|
||||
MouseDevice mouse = new MouseDevice();
|
||||
List<KeyboardDevice> dummy_keyboard_list = new List<KeyboardDevice>(1);
|
||||
|
@ -49,7 +49,8 @@ namespace OpenTK.Platform.X11
|
|||
if (attach == null)
|
||||
throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
|
||||
|
||||
window = new X11.WindowInfo(attach);
|
||||
//window = new X11WindowInfo(attach);
|
||||
window = (X11WindowInfo)attach;
|
||||
|
||||
// Init mouse
|
||||
mouse.Description = "Default X11 mouse";
|
||||
|
|
Loading…
Reference in a new issue