Moved OpenTK.GLControl to its own project.

This commit is contained in:
the_fiddler 2009-08-19 14:17:47 +00:00
parent 073109c8c7
commit c6516c2255
25 changed files with 1241 additions and 705 deletions

View 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
}
}

View file

@ -1,53 +1,55 @@
#region License #region License
// //
// The Open Toolkit Library License // The Open Toolkit Library License
// //
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted. // Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to // in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // 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 // the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions: // so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// //
#endregion #endregion
using OpenTK.Graphics; using System;
using OpenTK.Graphics;
namespace OpenTK.Platform.Dummy using OpenTK.Platform;
{
class DummyGLControl : IGLControl namespace OpenTK
{ {
#region IGLControl Members class DummyGLControl : IGLControl
{
public GraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags) #region IGLControl Members
{
return new GraphicsContext(null, null); public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
} {
return new GraphicsContext(null, null);
public bool IsIdle }
{
get { return false; } public bool IsIdle
} {
get { return false; }
public IWindowInfo WindowInfo }
{
get { return new DummyWindowInfo(); } public IWindowInfo WindowInfo
} {
get { return Utilities.CreateWindowInfo(null, IntPtr.Zero, true); }
#endregion }
}
} #endregion
}
}

View file

@ -1,45 +1,45 @@
namespace OpenTK namespace OpenTK
{ {
partial class GLControl partial class GLControl
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Component Designer generated code #region Component Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.SuspendLayout(); this.SuspendLayout();
// //
// NewGLControl // NewGLControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black; this.BackColor = System.Drawing.Color.Black;
this.Name = "NewGLControl"; this.Name = "NewGLControl";
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
} }
} }

View file

@ -1,291 +1,310 @@
#region --- License --- #region License
/* Licensed under the MIT/X11 license. //
* Copyright (c) 2006-2008 the OpenTK Team. // The Open Toolkit Library License
* This notice may not be removed from any source distribution. //
* See license.txt for licensing detailed licensing details. // Copyright (c) 2006 - 2009 the Open Toolkit library, except where noted.
*/ //
#endregion // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
using System; // in the Software without restriction, including without limitation the rights to
using System.Collections.Generic; // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
using System.ComponentModel; // the Software, and to permit persons to whom the Software is furnished to do
using System.Drawing; // so, subject to the following conditions:
using System.Data; //
using System.Text; // The above copyright notice and this permission notice shall be included in all
using System.Windows.Forms; // copies or substantial portions of the Software.
//
using OpenTK.Platform; // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
using OpenTK.Graphics; // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
using System.Diagnostics; // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
namespace OpenTK // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
{ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// <summary> // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
/// Defines a UserControl with OpenGL rendering capabilities. // OTHER DEALINGS IN THE SOFTWARE.
/// </summary> //
public partial class GLControl : UserControl #endregion
{
IGraphicsContext context; using System;
IGLControl implementation; using System.Collections.Generic;
GraphicsMode format; using System.ComponentModel;
IWindowInfo window_info; using System.Diagnostics;
int major, minor; using System.Drawing;
GraphicsContextFlags flags; using System.Data;
using System.Text;
#region --- Constructors --- using System.Windows.Forms;
/// <summary> using OpenTK.Platform;
/// Constructs a new GLControl. using OpenTK.Graphics;
/// </summary> using OpenTK.Graphics.OpenGL;
public GLControl()
: this(GraphicsMode.Default) namespace OpenTK
{ } {
/// <summary>
/// <summary> /// Defines a UserControl with OpenGL rendering capabilities.
/// Constructs a new GLControl with the specified GraphicsMode. /// </summary>
/// </summary> public partial class GLControl : UserControl
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param> {
public GLControl(GraphicsMode mode) IGraphicsContext context;
: this(mode, 1, 0, GraphicsContextFlags.Default) IGLControl implementation;
{ } GraphicsMode format;
IWindowInfo window_info;
/// <summary> int major, minor;
/// Constructs a new GLControl with the specified GraphicsMode. GraphicsContextFlags flags;
/// </summary>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param> #region --- Constructors ---
/// <param name="major">The major version for the OpenGL GraphicsContext.</param>
/// <param name="minor">The minor version for the OpenGL GraphicsContext.</param> /// <summary>
/// <param name="flags">The GraphicsContextFlags for the OpenGL GraphicsContext.</param> /// Constructs a new GLControl.
public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags) /// </summary>
{ public GLControl()
SetStyle(ControlStyles.Opaque, true); : this(GraphicsMode.Default)
SetStyle(ControlStyles.UserPaint, true); { }
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
DoubleBuffered = false; /// <summary>
/// Constructs a new GLControl with the specified GraphicsMode.
InitializeComponent(); /// </summary>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
this.format = mode; public GLControl(GraphicsMode mode)
this.major = major; : this(mode, 1, 0, GraphicsContextFlags.Default)
this.minor = minor; { }
this.flags = flags;
/// <summary>
// On Windows, you first need to create the window, then set the pixel format. /// Constructs a new GLControl with the specified GraphicsMode.
// On X11, you first need to select the visual, then create the window. /// </summary>
// On OSX, the pixel format needs to be selected before the GL context. /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
// Right now, pixel formats/visuals are selected during context creation. In the future, /// <param name="major">The major version for the OpenGL GraphicsContext.</param>
// it would be better to decouple selection from context creation, which will allow us /// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
// to clean up this hacky code. The best option is to do this along with multisampling /// <param name="flags">The GraphicsContextFlags for the OpenGL GraphicsContext.</param>
// support. public GLControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
if (DesignMode) {
implementation = new Platform.Dummy.DummyGLControl(); SetStyle(ControlStyles.Opaque, true);
else SetStyle(ControlStyles.UserPaint, true);
implementation = Platform.Factory.Default.CreateGLControl(mode, this); SetStyle(ControlStyles.AllPaintingInWmPaint, true);
DoubleBuffered = false;
this.CreateControl();
} InitializeComponent();
#endregion this.format = mode;
this.major = major;
#region --- Protected Methods --- this.minor = minor;
this.flags = flags;
/// <summary>Raises the HandleCreated event.</summary>
/// <param name="e">Not used.</param> // On Windows, you first need to create the window, then set the pixel format.
protected override void OnHandleCreated(EventArgs e) // 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.
base.OnHandleCreated(e); // 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
this.Context = implementation.CreateContext(major, minor, flags); // to clean up this hacky code. The best option is to do this along with multisampling
// support.
this.window_info = implementation.WindowInfo; if (DesignMode)
this.MakeCurrent(); implementation = new DummyGLControl();
((IGraphicsContextInternal)this.Context).LoadAll(); else
} implementation = new GLControlFactory().CreateGLControl(mode, this);
/// <summary>Raises the HandleDestroyed event.</summary> this.CreateControl();
/// <param name="e">Not used.</param> }
protected override void OnHandleDestroyed(EventArgs e)
{ #endregion
base.OnHandleDestroyed(e);
if (this.Context != null) #region --- Protected Methods ---
{
this.Context.Dispose(); /// <summary>Raises the HandleCreated event.</summary>
this.Context = null; /// <param name="e">Not used.</param>
} protected override void OnHandleCreated(EventArgs e)
this.window_info.Dispose(); {
this.window_info = null; base.OnHandleCreated(e);
}
this.Context = implementation.CreateContext(major, minor, flags);
/// <summary>
/// Raises the System.Windows.Forms.Control.Paint event. this.window_info = implementation.WindowInfo;
/// </summary> this.MakeCurrent();
/// <param name="e">A System.Windows.Forms.PaintEventArgs that contains the event data.</param> ((IGraphicsContextInternal)this.Context).LoadAll();
protected override void OnPaint(PaintEventArgs e) }
{
if (DesignMode) /// <summary>Raises the HandleDestroyed event.</summary>
e.Graphics.Clear(BackColor); /// <param name="e">Not used.</param>
protected override void OnHandleDestroyed(EventArgs e)
base.OnPaint(e); {
} base.OnHandleDestroyed(e);
if (this.Context != null)
/// <summary> {
/// Raises the Resize event. this.Context.Dispose();
/// </summary> this.Context = null;
/// <param name="e">A System.EventArgs that contains the event data.</param> }
protected override void OnResize(EventArgs e) this.window_info.Dispose();
{ this.window_info = null;
if (context != null) }
context.Update(window_info);
/// <summary>
base.OnResize(e); /// Raises the System.Windows.Forms.Control.Paint event.
} /// </summary>
/// <param name="e">A System.Windows.Forms.PaintEventArgs that contains the event data.</param>
/// <summary> protected override void OnPaint(PaintEventArgs e)
/// Raises the ParentChanged event. {
/// </summary> if (DesignMode)
/// <param name="e">A System.EventArgs that contains the event data.</param> e.Graphics.Clear(BackColor);
protected override void OnParentChanged(EventArgs e)
{ base.OnPaint(e);
if (context != null) }
context.Update(window_info);
/// <summary>
base.OnParentChanged(e); /// Raises the Resize event.
} /// </summary>
/// <param name="e">A System.EventArgs that contains the event data.</param>
#endregion protected override void OnResize(EventArgs e)
{
#region --- Public Methods --- if (context != null)
context.Update(window_info);
#region public void SwapBuffers()
base.OnResize(e);
/// <summary> }
/// Swaps the front and back buffers, presenting the rendered scene to the screen.
/// </summary> /// <summary>
public void SwapBuffers() /// Raises the ParentChanged event.
{ /// </summary>
Context.SwapBuffers(); /// <param name="e">A System.EventArgs that contains the event data.</param>
} protected override void OnParentChanged(EventArgs e)
{
#endregion if (context != null)
context.Update(window_info);
#region public void MakeCurrent()
base.OnParentChanged(e);
/// <summary> }
/// Makes the underlying this GLControl current in the calling thread.
/// All OpenGL commands issued are hereafter interpreted by this GLControl. #endregion
/// </summary>
public void MakeCurrent() #region --- Public Methods ---
{
this.Context.MakeCurrent(this.window_info); #region public void SwapBuffers()
}
/// <summary>
#endregion /// Swaps the front and back buffers, presenting the rendered scene to the screen.
/// </summary>
#region public bool IsIdle public void SwapBuffers()
{
/// <summary> Context.SwapBuffers();
/// Gets a value indicating whether the current thread contains pending system messages. }
/// </summary>
[Browsable(false)] #endregion
public bool IsIdle
{ #region public void MakeCurrent()
get { return implementation.IsIdle; }
} /// <summary>
/// Makes the underlying this GLControl current in the calling thread.
#endregion /// All OpenGL commands issued are hereafter interpreted by this GLControl.
/// </summary>
#region public IGraphicsContext Context public void MakeCurrent()
{
/// <summary> this.Context.MakeCurrent(this.window_info);
/// Gets an interface to the underlying GraphicsContext used by this GLControl. }
/// </summary>
[Browsable(false)] #endregion
public IGraphicsContext Context
{ #region public bool IsIdle
get { return context; }
private set { context = value; } /// <summary>
} /// Gets a value indicating whether the current thread contains pending system messages.
/// </summary>
#endregion [Browsable(false)]
public bool IsIdle
#region public float AspectRatio {
get { return implementation.IsIdle; }
/// <summary> }
/// Gets the aspect ratio of this GLControl.
/// </summary> #endregion
[Description("The aspect ratio of the client area of this GLControl.")]
public float AspectRatio #region public IGraphicsContext Context
{
get /// <summary>
{ /// Gets an interface to the underlying GraphicsContext used by this GLControl.
return this.ClientSize.Width / (float)this.ClientSize.Height; /// </summary>
} [Browsable(false)]
} public IGraphicsContext Context
{
#endregion get { return context; }
private set { context = value; }
#region public bool VSync }
/// <summary> #endregion
/// Gets or sets a value indicating whether vsync is active for this GLControl.
/// </summary> #region public float AspectRatio
[Description("Indicates whether GLControl updates are synced to the monitor's refresh.")]
public bool VSync /// <summary>
{ /// Gets the aspect ratio of this GLControl.
get /// </summary>
{ [Description("The aspect ratio of the client area of this GLControl.")]
if (Context != null) public float AspectRatio
return Context.VSync; {
return false; get
} {
set return this.ClientSize.Width / (float)this.ClientSize.Height;
{ }
if (Context != null) }
Context.VSync = value;
} #endregion
}
#region public bool VSync
#endregion
/// <summary>
#region public GraphicsMode GraphicsMode /// Gets or sets a value indicating whether vsync is active for this GLControl.
/// </summary>
/// <summary> [Description("Indicates whether GLControl updates are synced to the monitor's refresh.")]
/// Gets the GraphicsMode of the GraphicsContext attached to this GLControl. public bool VSync
/// </summary> {
/// <remarks> get
/// To change the GraphicsMode, you must destroy and recreate the GLControl. {
/// </remarks> if (Context != null)
public GraphicsMode GraphicsMode return Context.VSync;
{ return false;
get { return Context.GraphicsMode; } }
} set
{
#endregion if (Context != null)
Context.VSync = value;
#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> #endregion
/// <exception cref="OpenTK.Graphics.GraphicsContextException">
/// Occurs when no OpenTK.Graphics.GraphicsContext is current in the calling thread. #region public GraphicsMode GraphicsMode
/// </exception>
[Obsolete] /// <summary>
public Bitmap GrabScreenshot() /// Gets the GraphicsMode of the GraphicsContext attached to this GLControl.
{ /// </summary>
throw new NotImplementedException(); /// <remarks>
//Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); /// To change the GraphicsMode, you must destroy and recreate the GLControl.
//System.Drawing.Imaging.BitmapData data = /// </remarks>
// bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, public GraphicsMode GraphicsMode
// System.Drawing.Imaging.PixelFormat.Format24bppRgb); {
//GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, PixelFormat.Bgr, PixelType.UnsignedByte, get { return Context.GraphicsMode; }
// data.Scan0); }
//bmp.UnlockBits(data);
//bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); #endregion
//return bmp;
} #region public Bitmap GrabScreenshot()
#endregion /// <summary>Grabs a screenshot of the frontbuffer contents.</summary>
/// <returns>A System.Drawing.Bitmap, containing the contents of the frontbuffer.</returns>
#endregion /// <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
}
}

View 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();
}
}
}

View 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; }
}
}

View 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>

View 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)]

View 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
}
}

View 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
}
}

View file

@ -118,18 +118,6 @@ namespace OpenTK.Platform.Egl
} }
} }
// Todo: implement this!
public bool ErrorChecking
{
get
{
return false;
}
set
{
}
}
#endregion #endregion
#region IGraphicsContextInternal Members #region IGraphicsContextInternal Members

View file

@ -89,11 +89,6 @@ namespace OpenTK.Platform
return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device); return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device);
} }
public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
{
return default_implementation.CreateGLControl(mode, owner);
}
public IDisplayDeviceDriver CreateDisplayDeviceDriver() public IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
return default_implementation.CreateDisplayDeviceDriver(); return default_implementation.CreateDisplayDeviceDriver();
@ -134,11 +129,6 @@ namespace OpenTK.Platform
throw new PlatformNotSupportedException(error_string); throw new PlatformNotSupportedException(error_string);
} }
public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner)
{
throw new PlatformNotSupportedException(error_string);
}
public IDisplayDeviceDriver CreateDisplayDeviceDriver() public IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
throw new PlatformNotSupportedException(error_string); throw new PlatformNotSupportedException(error_string);

View file

@ -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; }
}
}

View file

@ -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); 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(); IDisplayDeviceDriver CreateDisplayDeviceDriver();
IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags); IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags);

View file

@ -228,7 +228,7 @@ namespace OpenTK.Platform.MacOS
windowPort = API.GetWindowPort(carbonWindow.WindowRef); windowPort = API.GetWindowPort(carbonWindow.WindowRef);
return windowPort; return windowPort;
} }
public void Update(IWindowInfo window) public override void Update(IWindowInfo window)
{ {
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window; CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;

View file

@ -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
}
}

View file

@ -42,11 +42,6 @@ namespace OpenTK.Platform.MacOS
return new CarbonGLNative(x, y, width, height, title, mode, options, device); 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() public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
return new QuartzDisplayDeviceDriver(); return new QuartzDisplayDeviceDriver();

View file

@ -263,7 +263,7 @@ namespace OpenTK.Platform
public static void CreateGraphicsContext(GraphicsMode mode, IntPtr cntrlHandle, public static void CreateGraphicsContext(GraphicsMode mode, IntPtr cntrlHandle,
out IGraphicsContext context, out IWindowInfo info) out IGraphicsContext context, out IWindowInfo info)
{ {
info = CreateWindowInfo(mode, cntrlHandle); info = CreateWindowInfo(mode, cntrlHandle, true);
context = new GraphicsContext(mode, info); context = new GraphicsContext(mode, info);
context.MakeCurrent(info); context.MakeCurrent(info);
@ -273,30 +273,19 @@ namespace OpenTK.Platform
#region --- CreateWindowInfo --- #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> /// <summary>
/// Creates an object which implements the IWindowInfo interface for the platform /// Creates an object which implements the IWindowInfo interface for the platform
/// currently running on. /// currently running on.
/// </summary> /// </summary>
/// <param name="mode">The desired GraphicsMode for this window.</param> /// <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="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> /// <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); if (Configuration.RunningOnWindows) return CreateWinWindowInfo(controlHandle);
else if (Configuration.RunningOnX11) return CreateX11WindowInfo(mode, controlHandle); else if (Configuration.RunningOnX11) return CreateX11WindowInfo(mode, controlHandle, isControl);
else if (Configuration.RunningOnMacOS) return CreateMacOSCarbonWindowInfo(controlHandle); else if (Configuration.RunningOnMacOS) return CreateMacOSCarbonWindowInfo(controlHandle, isControl);
else else
throw new PlatformNotSupportedException("Refer to http://www.opentk.com for more information."); throw new PlatformNotSupportedException("Refer to http://www.opentk.com for more information.");
} }
@ -305,37 +294,42 @@ namespace OpenTK.Platform
#region --- X11 Platform-specific implementation --- #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(); 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; window.WindowHandle = controlHandle;
// get the required handles from the X11 API. if (isControl)
window.Display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle"); {
window.RootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow"); Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
window.Screen = (int)GetStaticFieldValue(xplatui, "ScreenNo"); 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. // get the required handles from the X11 API.
Platform.X11.XVisualInfo info = new Platform.X11.XVisualInfo(); window.Display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
window.RootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
window.Screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
if (!mode.Index.HasValue) // get the X11 Visual info for the display.
throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); Platform.X11.XVisualInfo info = new Platform.X11.XVisualInfo();
info.VisualID = mode.Index.Value; if (!mode.Index.HasValue)
int dummy; throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
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. info.VisualID = mode.Index.Value;
SetStaticFieldValue(xplatui, "CustomVisual", window.VisualInfo.Visual); int dummy;
SetStaticFieldValue(xplatui, "CustomColormap", window.VisualInfo = (Platform.X11.XVisualInfo)Marshal.PtrToStructure(
Platform.X11.Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0)); 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; return window;
} }
@ -351,9 +345,9 @@ namespace OpenTK.Platform
#endregion #endregion
#region --- Mac OS X Platform-specific implementation --- #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 #endregion

View file

@ -43,11 +43,6 @@ namespace OpenTK.Platform.Windows
return new WinGLNative(x, y, width, height, title, options, device); 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() public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
return new WinDisplayDeviceDriver(); return new WinDisplayDeviceDriver();

View file

@ -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
}
}

View file

@ -15,11 +15,6 @@ namespace OpenTK.Platform.X11
return new X11GLNative(x, y, width, height, title, mode, options, device); 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() public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
{ {
return new X11XrandrDisplayDevice(); return new X11XrandrDisplayDevice();

View file

@ -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
}
}

View 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;
}
}
}
}

View 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>