Moved OpenTK.GLControl to its own project.
This commit is contained in:
parent
073109c8c7
commit
c6516c2255
25 changed files with 1241 additions and 705 deletions
77
Source/GLControl/CarbonGLControl.cs
Normal file
77
Source/GLControl/CarbonGLControl.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class CarbonGLControl : IGLControl
|
||||
{
|
||||
GraphicsMode mode;
|
||||
Control control;
|
||||
|
||||
internal CarbonGLControl(GraphicsMode mode, Control owner)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.control = owner;
|
||||
}
|
||||
|
||||
#region IGLControl Members
|
||||
|
||||
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(mode, WindowInfo, major, minor, flags);
|
||||
}
|
||||
|
||||
// TODO: Fix this
|
||||
bool lastIsIdle = false;
|
||||
public bool IsIdle
|
||||
{
|
||||
get
|
||||
{
|
||||
lastIsIdle = !lastIsIdle;
|
||||
return lastIsIdle;
|
||||
}
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return Utilities.CreateWindowInfo(mode, control.Handle, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,53 +1,55 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform.Dummy
|
||||
{
|
||||
class DummyGLControl : IGLControl
|
||||
{
|
||||
#region IGLControl Members
|
||||
|
||||
public GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(null, null);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get { return new DummyWindowInfo(); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class DummyGLControl : IGLControl
|
||||
{
|
||||
#region IGLControl Members
|
||||
|
||||
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(null, null);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get { return Utilities.CreateWindowInfo(null, IntPtr.Zero, true); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,45 +1,45 @@
|
|||
namespace OpenTK
|
||||
{
|
||||
partial class GLControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// NewGLControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Black;
|
||||
this.Name = "NewGLControl";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
namespace OpenTK
|
||||
{
|
||||
partial class GLControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// NewGLControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Black;
|
||||
this.Name = "NewGLControl";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,291 +1,310 @@
|
|||
#region --- License ---
|
||||
/* 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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.Platform;
|
||||
using OpenTK.Graphics;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a UserControl with OpenGL rendering capabilities.
|
||||
/// </summary>
|
||||
public partial class GLControl : UserControl
|
||||
{
|
||||
IGraphicsContext context;
|
||||
IGLControl implementation;
|
||||
GraphicsMode format;
|
||||
IWindowInfo window_info;
|
||||
int major, minor;
|
||||
GraphicsContextFlags flags;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl.
|
||||
/// </summary>
|
||||
public GLControl()
|
||||
: this(GraphicsMode.Default)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl with the specified GraphicsMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
|
||||
public GLControl(GraphicsMode mode)
|
||||
: this(mode, 1, 0, GraphicsContextFlags.Default)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl with the specified GraphicsMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
|
||||
/// <param name="major">The major version for the OpenGL GraphicsContext.</param>
|
||||
/// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
|
||||
/// <param name="flags">The GraphicsContextFlags for the OpenGL GraphicsContext.</param>
|
||||
public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
SetStyle(ControlStyles.Opaque, true);
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
DoubleBuffered = false;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
this.format = mode;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.flags = flags;
|
||||
|
||||
// On Windows, you first need to create the window, then set the pixel format.
|
||||
// On X11, you first need to select the visual, then create the window.
|
||||
// On OSX, the pixel format needs to be selected before the GL context.
|
||||
// Right now, pixel formats/visuals are selected during context creation. In the future,
|
||||
// it would be better to decouple selection from context creation, which will allow us
|
||||
// to clean up this hacky code. The best option is to do this along with multisampling
|
||||
// support.
|
||||
if (DesignMode)
|
||||
implementation = new Platform.Dummy.DummyGLControl();
|
||||
else
|
||||
implementation = Platform.Factory.Default.CreateGLControl(mode, this);
|
||||
|
||||
this.CreateControl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Protected Methods ---
|
||||
|
||||
/// <summary>Raises the HandleCreated event.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
|
||||
this.Context = implementation.CreateContext(major, minor, flags);
|
||||
|
||||
this.window_info = implementation.WindowInfo;
|
||||
this.MakeCurrent();
|
||||
((IGraphicsContextInternal)this.Context).LoadAll();
|
||||
}
|
||||
|
||||
/// <summary>Raises the HandleDestroyed event.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnHandleDestroyed(EventArgs e)
|
||||
{
|
||||
base.OnHandleDestroyed(e);
|
||||
if (this.Context != null)
|
||||
{
|
||||
this.Context.Dispose();
|
||||
this.Context = null;
|
||||
}
|
||||
this.window_info.Dispose();
|
||||
this.window_info = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the System.Windows.Forms.Control.Paint event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.Windows.Forms.PaintEventArgs that contains the event data.</param>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (DesignMode)
|
||||
e.Graphics.Clear(BackColor);
|
||||
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the Resize event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.EventArgs that contains the event data.</param>
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
if (context != null)
|
||||
context.Update(window_info);
|
||||
|
||||
base.OnResize(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the ParentChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.EventArgs that contains the event data.</param>
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
if (context != null)
|
||||
context.Update(window_info);
|
||||
|
||||
base.OnParentChanged(e);
|
||||
}
|
||||
|
||||
#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()
|
||||
{
|
||||
this.Context.MakeCurrent(this.window_info);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool IsIdle
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current thread contains pending system messages.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return implementation.IsIdle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public IGraphicsContext Context
|
||||
|
||||
/// <summary>
|
||||
/// Gets an interface to the underlying GraphicsContext used by this GLControl.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public IGraphicsContext Context
|
||||
{
|
||||
get { return context; }
|
||||
private set { context = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public float AspectRatio
|
||||
|
||||
/// <summary>
|
||||
/// Gets the aspect ratio of this GLControl.
|
||||
/// </summary>
|
||||
[Description("The aspect ratio of the client area of this GLControl.")]
|
||||
public float AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClientSize.Width / (float)this.ClientSize.Height;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool VSync
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether vsync is active for this GLControl.
|
||||
/// </summary>
|
||||
[Description("Indicates whether GLControl updates are synced to the monitor's refresh.")]
|
||||
public bool VSync
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Context != null)
|
||||
return Context.VSync;
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Context != null)
|
||||
Context.VSync = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode GraphicsMode
|
||||
|
||||
/// <summary>
|
||||
/// Gets the GraphicsMode of the GraphicsContext attached to this GLControl.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To change the GraphicsMode, you must destroy and recreate the GLControl.
|
||||
/// </remarks>
|
||||
public GraphicsMode GraphicsMode
|
||||
{
|
||||
get { return Context.GraphicsMode; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Bitmap GrabScreenshot()
|
||||
|
||||
/// <summary>Grabs a screenshot of the frontbuffer contents.</summary>
|
||||
/// <returns>A System.Drawing.Bitmap, containing the contents of the frontbuffer.</returns>
|
||||
/// <exception cref="OpenTK.Graphics.GraphicsContextException">
|
||||
/// Occurs when no OpenTK.Graphics.GraphicsContext is current in the calling thread.
|
||||
/// </exception>
|
||||
[Obsolete]
|
||||
public Bitmap GrabScreenshot()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
|
||||
//System.Drawing.Imaging.BitmapData data =
|
||||
// bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly,
|
||||
// System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||
//GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, PixelFormat.Bgr, PixelType.UnsignedByte,
|
||||
// data.Scan0);
|
||||
//bmp.UnlockBits(data);
|
||||
//bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
//return bmp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.Platform;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a UserControl with OpenGL rendering capabilities.
|
||||
/// </summary>
|
||||
public partial class GLControl : UserControl
|
||||
{
|
||||
IGraphicsContext context;
|
||||
IGLControl implementation;
|
||||
GraphicsMode format;
|
||||
IWindowInfo window_info;
|
||||
int major, minor;
|
||||
GraphicsContextFlags flags;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl.
|
||||
/// </summary>
|
||||
public GLControl()
|
||||
: this(GraphicsMode.Default)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl with the specified GraphicsMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
|
||||
public GLControl(GraphicsMode mode)
|
||||
: this(mode, 1, 0, GraphicsContextFlags.Default)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl with the specified GraphicsMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
|
||||
/// <param name="major">The major version for the OpenGL GraphicsContext.</param>
|
||||
/// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
|
||||
/// <param name="flags">The GraphicsContextFlags for the OpenGL GraphicsContext.</param>
|
||||
public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
SetStyle(ControlStyles.Opaque, true);
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
DoubleBuffered = false;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
this.format = mode;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.flags = flags;
|
||||
|
||||
// On Windows, you first need to create the window, then set the pixel format.
|
||||
// On X11, you first need to select the visual, then create the window.
|
||||
// On OSX, the pixel format needs to be selected before the GL context.
|
||||
// Right now, pixel formats/visuals are selected during context creation. In the future,
|
||||
// it would be better to decouple selection from context creation, which will allow us
|
||||
// to clean up this hacky code. The best option is to do this along with multisampling
|
||||
// support.
|
||||
if (DesignMode)
|
||||
implementation = new DummyGLControl();
|
||||
else
|
||||
implementation = new GLControlFactory().CreateGLControl(mode, this);
|
||||
|
||||
this.CreateControl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Protected Methods ---
|
||||
|
||||
/// <summary>Raises the HandleCreated event.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
|
||||
this.Context = implementation.CreateContext(major, minor, flags);
|
||||
|
||||
this.window_info = implementation.WindowInfo;
|
||||
this.MakeCurrent();
|
||||
((IGraphicsContextInternal)this.Context).LoadAll();
|
||||
}
|
||||
|
||||
/// <summary>Raises the HandleDestroyed event.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnHandleDestroyed(EventArgs e)
|
||||
{
|
||||
base.OnHandleDestroyed(e);
|
||||
if (this.Context != null)
|
||||
{
|
||||
this.Context.Dispose();
|
||||
this.Context = null;
|
||||
}
|
||||
this.window_info.Dispose();
|
||||
this.window_info = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the System.Windows.Forms.Control.Paint event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.Windows.Forms.PaintEventArgs that contains the event data.</param>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (DesignMode)
|
||||
e.Graphics.Clear(BackColor);
|
||||
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the Resize event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.EventArgs that contains the event data.</param>
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
if (context != null)
|
||||
context.Update(window_info);
|
||||
|
||||
base.OnResize(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the ParentChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">A System.EventArgs that contains the event data.</param>
|
||||
protected override void OnParentChanged(EventArgs e)
|
||||
{
|
||||
if (context != null)
|
||||
context.Update(window_info);
|
||||
|
||||
base.OnParentChanged(e);
|
||||
}
|
||||
|
||||
#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()
|
||||
{
|
||||
this.Context.MakeCurrent(this.window_info);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool IsIdle
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current thread contains pending system messages.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return implementation.IsIdle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public IGraphicsContext Context
|
||||
|
||||
/// <summary>
|
||||
/// Gets an interface to the underlying GraphicsContext used by this GLControl.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public IGraphicsContext Context
|
||||
{
|
||||
get { return context; }
|
||||
private set { context = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public float AspectRatio
|
||||
|
||||
/// <summary>
|
||||
/// Gets the aspect ratio of this GLControl.
|
||||
/// </summary>
|
||||
[Description("The aspect ratio of the client area of this GLControl.")]
|
||||
public float AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ClientSize.Width / (float)this.ClientSize.Height;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool VSync
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether vsync is active for this GLControl.
|
||||
/// </summary>
|
||||
[Description("Indicates whether GLControl updates are synced to the monitor's refresh.")]
|
||||
public bool VSync
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Context != null)
|
||||
return Context.VSync;
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Context != null)
|
||||
Context.VSync = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public GraphicsMode GraphicsMode
|
||||
|
||||
/// <summary>
|
||||
/// Gets the GraphicsMode of the GraphicsContext attached to this GLControl.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To change the GraphicsMode, you must destroy and recreate the GLControl.
|
||||
/// </remarks>
|
||||
public GraphicsMode GraphicsMode
|
||||
{
|
||||
get { return Context.GraphicsMode; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Bitmap GrabScreenshot()
|
||||
|
||||
/// <summary>Grabs a screenshot of the frontbuffer contents.</summary>
|
||||
/// <returns>A System.Drawing.Bitmap, containing the contents of the frontbuffer.</returns>
|
||||
/// <exception cref="OpenTK.Graphics.GraphicsContextException">
|
||||
/// Occurs when no OpenTK.Graphics.GraphicsContext is current in the calling thread.
|
||||
/// </exception>
|
||||
[Obsolete("This method will be removed. Please provide your own code to capture framebuffer contents.")]
|
||||
public Bitmap GrabScreenshot()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
|
||||
System.Drawing.Imaging.BitmapData data =
|
||||
bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly,
|
||||
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||
GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, PixelFormat.Bgr, PixelType.UnsignedByte,
|
||||
data.Scan0);
|
||||
bmp.UnlockBits(data);
|
||||
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
47
Source/GLControl/GLControlFactory.cs
Normal file
47
Source/GLControl/GLControlFactory.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
// Constructs GLControls.
|
||||
class GLControlFactory
|
||||
{
|
||||
public IGLControl CreateGLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
if (Configuration.RunningOnWindows) return new WinGLControl(mode, control);
|
||||
else if (Configuration.RunningOnX11) return new X11GLControl(mode, control);
|
||||
else if (Configuration.RunningOnMacOS) return new CarbonGLControl(mode, control);
|
||||
else throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
43
Source/GLControl/IGLControl.cs
Normal file
43
Source/GLControl/IGLControl.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
internal interface IGLControl
|
||||
{
|
||||
IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags);
|
||||
bool IsIdle { get; }
|
||||
IWindowInfo WindowInfo { get; }
|
||||
}
|
||||
}
|
182
Source/GLControl/OpenTK.GLControl.csproj
Normal file
182
Source/GLControl/OpenTK.GLControl.csproj
Normal file
|
@ -0,0 +1,182 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{8CC9D641-0000-0000-0000-000000000000}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
<AssemblyKeyContainerName>
|
||||
</AssemblyKeyContainerName>
|
||||
<AssemblyName>OpenTK.GLControl</AssemblyName>
|
||||
<DefaultClientScript>JScript</DefaultClientScript>
|
||||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
|
||||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||
<DelaySign>false</DelaySign>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>
|
||||
</AppDesignerFolder>
|
||||
<RootNamespace>OpenTK.GLControl</RootNamespace>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<StartArguments>
|
||||
</StartArguments>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.GLControl.xml</DocumentationFile>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\..\Binaries\Debug\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DocumentationFile>OpenTK.GLControl.xml</DocumentationFile>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\..\Binaries\Release\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<Name>System.Windows.Forms</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.Xml</Name>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenTK\OpenTK.csproj">
|
||||
<Name>OpenTK</Name>
|
||||
<Project>{2C035F6B-0000-0000-0000-000000000000}</Project>
|
||||
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
|
||||
<Private>False</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CarbonGLControl.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DummyGLControl.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="GLControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="GLControl.Designer.cs">
|
||||
<DependentUpon>GLControl.cs</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="GLControlFactory.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IGLControl.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="WinGLControl.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="X11GLControl.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
38
Source/GLControl/Properties/AssemblyInfo.cs
Normal file
38
Source/GLControl/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("OpenTK.GLControl")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("OpenTK.GLControl")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5414b90b-d7be-4382-b0e1-f07ce154f7f7")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
[assembly: System.CLSCompliant(true)]
|
158
Source/GLControl/WinGLControl.cs
Normal file
158
Source/GLControl/WinGLControl.cs
Normal file
|
@ -0,0 +1,158 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class WinGLControl : IGLControl
|
||||
{
|
||||
#region P/Invoke declarations
|
||||
|
||||
#region Message
|
||||
|
||||
struct MSG
|
||||
{
|
||||
public IntPtr HWnd;
|
||||
public uint Message;
|
||||
public IntPtr WParam;
|
||||
public IntPtr LParam;
|
||||
public uint Time;
|
||||
public POINT Point;
|
||||
//internal object RefObject;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("msg=0x{0:x} ({1}) hwnd=0x{2:x} wparam=0x{3:x} lparam=0x{4:x} pt=0x{5:x}", (int)Message, Message.ToString(), HWnd.ToInt32(), WParam.ToInt32(), LParam.ToInt32(), Point);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Point
|
||||
|
||||
struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public POINT(int x, int y)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
}
|
||||
|
||||
public System.Drawing.Point ToPoint()
|
||||
{
|
||||
return new System.Drawing.Point(X, Y);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Point {" + X.ToString() + ", " + Y.ToString() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PeekMessage
|
||||
|
||||
[System.Security.SuppressUnmanagedCodeSecurity]
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
MSG msg = new MSG();
|
||||
IWindowInfo window_info;
|
||||
GraphicsMode mode;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public WinGLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
this.mode = mode;
|
||||
|
||||
control.HandleCreated += delegate(object sender, EventArgs e)
|
||||
{
|
||||
if (window_info != null)
|
||||
window_info.Dispose();
|
||||
window_info = Utilities.CreateWindowInfo(mode, ((Control)sender).Handle, true);
|
||||
};
|
||||
|
||||
control.HandleDestroyed += delegate(object sender, EventArgs e)
|
||||
{
|
||||
if (window_info != null)
|
||||
{
|
||||
window_info.Dispose();
|
||||
window_info = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGLControl Members
|
||||
|
||||
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(mode, window_info, major, minor, flags);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return !PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0); }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
// This method forces the creation of the control. Beware of this side-effect!
|
||||
return window_info;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
67
Source/GLControl/X11GLControl.cs
Normal file
67
Source/GLControl/X11GLControl.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
#region --- License ---
|
||||
/* 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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class X11GLControl : IGLControl
|
||||
{
|
||||
#region P/Invokes
|
||||
|
||||
[DllImport("libX11")]
|
||||
public extern static int XPending(IntPtr diplay);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
GraphicsMode mode;
|
||||
Control control;
|
||||
IWindowInfo window_info;
|
||||
|
||||
#endregion
|
||||
|
||||
internal X11GLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.control = control;
|
||||
|
||||
window_info = Utilities.CreateWindowInfo(mode, control.Handle, true);
|
||||
}
|
||||
|
||||
#region IGLControl Members
|
||||
|
||||
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(mode, this.WindowInfo, major, minor, flags);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return XPending(((Platform.X11.X11WindowInfo)window_info).Display) == 0; }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return window_info;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -118,18 +118,6 @@ namespace OpenTK.Platform.Egl
|
|||
}
|
||||
}
|
||||
|
||||
// Todo: implement this!
|
||||
public bool ErrorChecking
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGraphicsContextInternal Members
|
||||
|
|
|
@ -89,11 +89,6 @@ namespace OpenTK.Platform
|
|||
return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
|
||||
{
|
||||
return default_implementation.CreateGLControl(mode, owner);
|
||||
}
|
||||
|
||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return default_implementation.CreateDisplayDeviceDriver();
|
||||
|
@ -134,11 +129,6 @@ namespace OpenTK.Platform
|
|||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
|
||||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
}
|
||||
|
||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
throw new PlatformNotSupportedException(error_string);
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#region --- License ---
|
||||
/* 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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
internal interface IGLControl
|
||||
{
|
||||
GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags);
|
||||
bool IsIdle { get; }
|
||||
IWindowInfo WindowInfo { get; }
|
||||
}
|
||||
}
|
|
@ -37,8 +37,6 @@ namespace OpenTK.Platform
|
|||
{
|
||||
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
|
||||
|
||||
IGLControl CreateGLControl(GraphicsMode mode, GLControl owner);
|
||||
|
||||
IDisplayDeviceDriver CreateDisplayDeviceDriver();
|
||||
|
||||
IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags);
|
||||
|
|
|
@ -228,7 +228,7 @@ namespace OpenTK.Platform.MacOS
|
|||
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
||||
return windowPort;
|
||||
}
|
||||
public void Update(IWindowInfo window)
|
||||
public override void Update(IWindowInfo window)
|
||||
{
|
||||
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenTK.Platform.MacOS
|
||||
{
|
||||
using Graphics;
|
||||
|
||||
class CarbonGLControl : IGLControl
|
||||
{
|
||||
GraphicsMode mode;
|
||||
Control control;
|
||||
|
||||
internal CarbonGLControl(GraphicsMode mode, Control owner)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.control = owner;
|
||||
}
|
||||
|
||||
#region IGLControl Members
|
||||
|
||||
public GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(mode, WindowInfo, major, minor, flags);
|
||||
}
|
||||
|
||||
// TODO: Fix this
|
||||
bool lastIsIdle = false;
|
||||
public bool IsIdle
|
||||
{
|
||||
get
|
||||
{
|
||||
lastIsIdle = !lastIsIdle;
|
||||
return lastIsIdle;
|
||||
}
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
control.CreateControl();
|
||||
return new CarbonWindowInfo(control.Handle, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -42,11 +42,6 @@ namespace OpenTK.Platform.MacOS
|
|||
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public virtual IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
|
||||
{
|
||||
return new CarbonGLControl(mode, owner);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return new QuartzDisplayDeviceDriver();
|
||||
|
|
|
@ -263,7 +263,7 @@ namespace OpenTK.Platform
|
|||
public static void CreateGraphicsContext(GraphicsMode mode, IntPtr cntrlHandle,
|
||||
out IGraphicsContext context, out IWindowInfo info)
|
||||
{
|
||||
info = CreateWindowInfo(mode, cntrlHandle);
|
||||
info = CreateWindowInfo(mode, cntrlHandle, true);
|
||||
|
||||
context = new GraphicsContext(mode, info);
|
||||
context.MakeCurrent(info);
|
||||
|
@ -273,30 +273,19 @@ namespace OpenTK.Platform
|
|||
|
||||
#region --- CreateWindowInfo ---
|
||||
|
||||
/// <summary>
|
||||
/// Creates an object which implements the IWindowInfo interface for the platform
|
||||
/// currently running on. This will create a handle for the control, so it is not
|
||||
/// recommended that this be called in the constructor of a custom control.
|
||||
/// </summary>
|
||||
/// <param name="mode">The desired GraphicsMode for this window.</param>
|
||||
/// <param name="cntrl">A <see cref="System.Windows.Forms.Control"/> to get the IWindowInfo from.</param>
|
||||
/// <returns></returns>
|
||||
public static IWindowInfo CreateWindowInfo(GraphicsMode mode, Control cntrl)
|
||||
{
|
||||
return CreateWindowInfo(mode, cntrl.Handle);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an object which implements the IWindowInfo interface for the platform
|
||||
/// currently running on.
|
||||
/// </summary>
|
||||
/// <param name="mode">The desired GraphicsMode for this window.</param>
|
||||
/// <param name="controlHandle">The handle to the control, obtained from Control.Handle.</param>
|
||||
/// <param name="isControl">Set to true if this is a Windows.Forms control.</param>
|
||||
/// <returns></returns>
|
||||
public static IWindowInfo CreateWindowInfo(GraphicsMode mode, IntPtr controlHandle)
|
||||
public static IWindowInfo CreateWindowInfo(GraphicsMode mode, IntPtr controlHandle, bool isControl)
|
||||
{
|
||||
if (Configuration.RunningOnWindows) return CreateWinWindowInfo(controlHandle);
|
||||
else if (Configuration.RunningOnX11) return CreateX11WindowInfo(mode, controlHandle);
|
||||
else if (Configuration.RunningOnMacOS) return CreateMacOSCarbonWindowInfo(controlHandle);
|
||||
else if (Configuration.RunningOnX11) return CreateX11WindowInfo(mode, controlHandle, isControl);
|
||||
else if (Configuration.RunningOnMacOS) return CreateMacOSCarbonWindowInfo(controlHandle, isControl);
|
||||
else
|
||||
throw new PlatformNotSupportedException("Refer to http://www.opentk.com for more information.");
|
||||
}
|
||||
|
@ -305,37 +294,42 @@ namespace OpenTK.Platform
|
|||
|
||||
#region --- X11 Platform-specific implementation ---
|
||||
|
||||
private static IWindowInfo CreateX11WindowInfo(GraphicsMode mode, IntPtr controlHandle)
|
||||
private static IWindowInfo CreateX11WindowInfo(GraphicsMode mode, IntPtr controlHandle, bool isControl)
|
||||
{
|
||||
Platform.X11.X11WindowInfo window = new OpenTK.Platform.X11.X11WindowInfo();
|
||||
|
||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
if (xplatui == null) throw new PlatformNotSupportedException(
|
||||
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
||||
|
||||
window.WindowHandle = controlHandle;
|
||||
|
||||
// get the required handles from the X11 API.
|
||||
window.Display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
||||
window.RootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
||||
window.Screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
||||
if (isControl)
|
||||
{
|
||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
if (xplatui == null) throw new PlatformNotSupportedException(
|
||||
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
||||
|
||||
// get the X11 Visual info for the display.
|
||||
Platform.X11.XVisualInfo info = new Platform.X11.XVisualInfo();
|
||||
// get the required handles from the X11 API.
|
||||
window.Display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
||||
window.RootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
||||
window.Screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
||||
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
|
||||
// get the X11 Visual info for the display.
|
||||
Platform.X11.XVisualInfo info = new Platform.X11.XVisualInfo();
|
||||
|
||||
info.VisualID = mode.Index.Value;
|
||||
int dummy;
|
||||
window.VisualInfo = (Platform.X11.XVisualInfo)Marshal.PtrToStructure(
|
||||
Platform.X11.Functions.XGetVisualInfo(window.Display, Platform.X11.XVisualInfoMask.ID,
|
||||
ref info, out dummy), typeof(Platform.X11.XVisualInfo));
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
|
||||
|
||||
// set the X11 colormap.
|
||||
SetStaticFieldValue(xplatui, "CustomVisual", window.VisualInfo.Visual);
|
||||
SetStaticFieldValue(xplatui, "CustomColormap",
|
||||
Platform.X11.Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0));
|
||||
info.VisualID = mode.Index.Value;
|
||||
int dummy;
|
||||
window.VisualInfo = (Platform.X11.XVisualInfo)Marshal.PtrToStructure(
|
||||
Platform.X11.Functions.XGetVisualInfo(window.Display, Platform.X11.XVisualInfoMask.ID,
|
||||
ref info, out dummy), typeof(Platform.X11.XVisualInfo));
|
||||
|
||||
// set the X11 colormap.
|
||||
SetStaticFieldValue(xplatui, "CustomVisual", window.VisualInfo.Visual);
|
||||
SetStaticFieldValue(xplatui, "CustomColormap",
|
||||
Platform.X11.Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
|
@ -351,9 +345,9 @@ namespace OpenTK.Platform
|
|||
#endregion
|
||||
#region --- Mac OS X Platform-specific implementation ---
|
||||
|
||||
private static IWindowInfo CreateMacOSCarbonWindowInfo(IntPtr controlHandle)
|
||||
private static IWindowInfo CreateMacOSCarbonWindowInfo(IntPtr controlHandle, bool isControl)
|
||||
{
|
||||
return new OpenTK.Platform.MacOS.CarbonWindowInfo(controlHandle, false, true);
|
||||
return new OpenTK.Platform.MacOS.CarbonWindowInfo(controlHandle, false, isControl);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -43,11 +43,6 @@ namespace OpenTK.Platform.Windows
|
|||
return new WinGLNative(x, y, width, height, title, options, device);
|
||||
}
|
||||
|
||||
public virtual IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
|
||||
{
|
||||
return new WinGLControl(mode, owner);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return new WinDisplayDeviceDriver();
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
#region --- License ---
|
||||
/* 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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
class WinGLControl : IGLControl
|
||||
{
|
||||
MSG msg = new MSG();
|
||||
GraphicsMode mode;
|
||||
Control control;
|
||||
WinWindowInfo window_info;
|
||||
|
||||
internal WinGLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.control = control;
|
||||
this.control.HandleCreated += delegate(object sender, EventArgs e)
|
||||
{
|
||||
if (window_info != null)
|
||||
window_info.Dispose();
|
||||
window_info = new WinWindowInfo(this.control.Handle, null);
|
||||
};
|
||||
this.control.HandleDestroyed += delegate(object sender, EventArgs e)
|
||||
{
|
||||
if (window_info != null)
|
||||
{
|
||||
window_info.Dispose();
|
||||
window_info = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#region --- IGLControl Members ---
|
||||
|
||||
public GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
// Make sure the Control exists before create the context.
|
||||
if (window_info == null)
|
||||
window_info = new WinWindowInfo(control.Handle, null);
|
||||
|
||||
return new GraphicsContext(mode, window_info, major, minor, flags);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return !OpenTK.Platform.Windows.Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0); }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
// This method forces the creation of the control. Beware of this side-effect!
|
||||
return window_info;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -15,11 +15,6 @@ namespace OpenTK.Platform.X11
|
|||
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public virtual IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
|
||||
{
|
||||
return new X11GLControl(mode, owner);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return new X11XrandrDisplayDevice();
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
#region --- License ---
|
||||
/* 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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
class X11GLControl : IGLControl
|
||||
{
|
||||
GraphicsMode mode;
|
||||
Control control;
|
||||
IntPtr display;
|
||||
|
||||
internal X11GLControl(GraphicsMode mode, Control control)
|
||||
{
|
||||
if (!mode.Index.HasValue)
|
||||
throw new GraphicsModeException("Invalid GraphicsMode.");
|
||||
|
||||
this.mode = mode;
|
||||
this.control = control;
|
||||
|
||||
X11WindowInfo window = (X11WindowInfo)this.WindowInfo;
|
||||
XVisualInfo info = new XVisualInfo();
|
||||
|
||||
info.VisualID = mode.Index.Value;
|
||||
int dummy;
|
||||
window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
|
||||
Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));
|
||||
|
||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
xplatui.GetField("CustomVisual", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
.SetValue(null, window.VisualInfo.Visual);
|
||||
xplatui.GetField("CustomColormap", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
.SetValue(null, Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0));
|
||||
}
|
||||
|
||||
#region --- IGLControl Members ---
|
||||
|
||||
public GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
return new GraphicsContext(mode, this.WindowInfo, major, minor, flags);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return Functions.XPending(display) == 0; }
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
if (xplatui == null) throw new PlatformNotSupportedException(
|
||||
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
||||
|
||||
X11WindowInfo window = new X11WindowInfo();
|
||||
|
||||
if (control.IsHandleCreated)
|
||||
window.WindowHandle = control.Handle;
|
||||
|
||||
display =
|
||||
window.Display = (IntPtr)xplatui.GetField("DisplayHandle",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
window.RootWindow = (IntPtr)xplatui.GetField("RootWindow",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
window.Screen = (int)xplatui.GetField("ScreenNo",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
|
||||
if (control.IsHandleCreated)
|
||||
window.WindowHandle = control.Handle;
|
||||
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
63
Source/OpenTK/Properties/Resources.Designer.cs
generated
Normal file
63
Source/OpenTK/Properties/Resources.Designer.cs
generated
Normal file
|
@ -0,0 +1,63 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.4918
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace OpenTK.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenTK.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Source/OpenTK/Properties/Resources.resx
Normal file
120
Source/OpenTK/Properties/Resources.resx
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Reference in a new issue