mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 17:47:12 -04:00
Combine factory definitions into one file, simplify WinGLContext.
This commit is contained in:
parent
1eb12e83eb
commit
40ce65ab09
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
|
@ -31,10 +31,10 @@ namespace OpenTK.Input {
|
||||
/// <summary> Defines the interface for an input driver. </summary>
|
||||
public interface IInputDriver : IJoystickDriver, IDisposable {
|
||||
|
||||
/// <summary> Gets the list of available KeyboardDevices. </summary>
|
||||
KeyboardDevice Keyboard { get; }
|
||||
/// <summary> Gets the list of available KeyboardDevices. </summary>
|
||||
KeyboardDevice Keyboard { get; }
|
||||
|
||||
/// <summary> Gets the list of available MouseDevices. </summary>
|
||||
/// <summary> Gets the list of available MouseDevices. </summary>
|
||||
MouseDevice Mouse { get; }
|
||||
|
||||
/// <summary> Updates the state of the driver. </summary>
|
||||
|
@ -96,14 +96,12 @@
|
||||
<Compile Include="Platform\MacOS\CarbonWindowInfo.cs" />
|
||||
<Compile Include="Platform\MacOS\EventInfo.cs" />
|
||||
<Compile Include="Platform\MacOS\MacOSException.cs" />
|
||||
<Compile Include="Platform\MacOS\MacOSFactory.cs" />
|
||||
<Compile Include="Platform\MacOS\MacOSKeyMap.cs" />
|
||||
<Compile Include="Platform\MacOS\QuartzDisplayDeviceDriver.cs" />
|
||||
<Compile Include="Platform\PlatformException.cs" />
|
||||
<Compile Include="Platform\Windows\API.cs" />
|
||||
<Compile Include="Platform\Windows\Wgl.cs" />
|
||||
<Compile Include="Platform\Windows\WinDisplayDevice.cs" />
|
||||
<Compile Include="Platform\Windows\WinFactory.cs" />
|
||||
<Compile Include="Platform\Windows\WinGLContext.cs" />
|
||||
<Compile Include="Platform\Windows\WinGLNative.cs" />
|
||||
<Compile Include="Platform\Windows\WinKeyMap.cs" />
|
||||
@ -114,7 +112,6 @@
|
||||
<Compile Include="Platform\X11\Glx.cs" />
|
||||
<Compile Include="Platform\X11\Structs.cs" />
|
||||
<Compile Include="Platform\X11\X11DisplayDevice.cs" />
|
||||
<Compile Include="Platform\X11\X11Factory.cs" />
|
||||
<Compile Include="Platform\X11\X11GLContext.cs" />
|
||||
<Compile Include="Platform\X11\X11GLNative.cs" />
|
||||
<Compile Include="Platform\X11\X11GraphicsMode.cs" />
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
// 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
|
||||
// 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:
|
||||
@ -28,27 +28,90 @@
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform
|
||||
{
|
||||
interface IPlatformFactory
|
||||
{
|
||||
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
|
||||
namespace OpenTK.Platform {
|
||||
|
||||
interface IPlatformFactory {
|
||||
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
|
||||
|
||||
IDisplayDeviceDriver CreateDisplayDeviceDriver();
|
||||
IDisplayDeviceDriver CreateDisplayDeviceDriver();
|
||||
|
||||
IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window);
|
||||
|
||||
IGraphicsMode CreateGraphicsMode();
|
||||
}
|
||||
|
||||
internal static class Factory {
|
||||
public static readonly IPlatformFactory Default;
|
||||
IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window);
|
||||
|
||||
IGraphicsMode CreateGraphicsMode();
|
||||
}
|
||||
|
||||
internal static class Factory {
|
||||
public static readonly IPlatformFactory Default;
|
||||
|
||||
static Factory() {
|
||||
if (Configuration.RunningOnWindows) Default = new Windows.WinFactory();
|
||||
else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory();
|
||||
else if (Configuration.RunningOnX11) Default = new X11.X11Factory();
|
||||
else throw new NotSupportedException( "Running on an unsupported platform, please refer to http://www.opentk.com for more information." );
|
||||
static Factory() {
|
||||
if (Configuration.RunningOnWindows) Default = new Windows.WinFactory();
|
||||
else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory();
|
||||
else if (Configuration.RunningOnX11) Default = new X11.X11Factory();
|
||||
else throw new NotSupportedException( "Running on an unsupported platform, please refer to http://www.opentk.com for more information." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OpenTK.Platform.MacOS {
|
||||
class MacOSFactory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver() {
|
||||
return new QuartzDisplayDeviceDriver();
|
||||
}
|
||||
|
||||
public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window) {
|
||||
return new AglContext(mode, window);
|
||||
}
|
||||
|
||||
public IGraphicsMode CreateGraphicsMode() {
|
||||
return new IGraphicsMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OpenTK.Platform.Windows {
|
||||
class WinFactory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new WinGLNative(x, y, width, height, title, options, device);
|
||||
}
|
||||
|
||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver() {
|
||||
return new WinDisplayDeviceDriver();
|
||||
}
|
||||
|
||||
public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window) {
|
||||
return new WinGLContext(mode, (WinWindowInfo)window);
|
||||
}
|
||||
|
||||
public IGraphicsMode CreateGraphicsMode() {
|
||||
return new IGraphicsMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OpenTK.Platform.X11 {
|
||||
class X11Factory : IPlatformFactory {
|
||||
|
||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver() {
|
||||
return new X11DisplayDevice();
|
||||
}
|
||||
|
||||
public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window) {
|
||||
return new X11GLContext(mode, window);
|
||||
}
|
||||
|
||||
public IGraphicsMode CreateGraphicsMode() {
|
||||
return new X11GraphicsMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace OpenTK.Platform.MacOS
|
||||
{
|
||||
class MacOSFactory : IPlatformFactory
|
||||
{
|
||||
#region IPlatformFactory Members
|
||||
|
||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||
{
|
||||
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return new QuartzDisplayDeviceDriver();
|
||||
}
|
||||
|
||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window)
|
||||
{
|
||||
return new AglContext(mode, window);
|
||||
}
|
||||
|
||||
public virtual IGraphicsMode CreateGraphicsMode()
|
||||
{
|
||||
return new IGraphicsMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
class WinFactory : IPlatformFactory
|
||||
{
|
||||
#region IPlatformFactory Members
|
||||
|
||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
|
||||
return new WinGLNative(x, y, width, height, title, options, device);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver() {
|
||||
return new WinDisplayDeviceDriver();
|
||||
}
|
||||
|
||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window) {
|
||||
return new WinGLContext(mode, (WinWindowInfo)window);
|
||||
}
|
||||
|
||||
public virtual IGraphicsMode CreateGraphicsMode() {
|
||||
return new IGraphicsMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -5,21 +5,13 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region --- Using Directives ---
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
namespace OpenTK.Platform.Windows {
|
||||
|
||||
/// \internal
|
||||
/// <summary>
|
||||
/// Provides methods to create and control an opengl context on the Windows platform.
|
||||
@ -27,81 +19,51 @@ namespace OpenTK.Platform.Windows
|
||||
/// </summary>
|
||||
internal sealed class WinGLContext : GraphicsContextBase
|
||||
{
|
||||
static object SyncRoot = new object();
|
||||
|
||||
static IntPtr opengl32Handle;
|
||||
const string opengl32Name = "OPENGL32.DLL";
|
||||
|
||||
bool vsync_supported;
|
||||
|
||||
#region --- Contructors ---
|
||||
|
||||
static WinGLContext()
|
||||
{
|
||||
lock (SyncRoot)
|
||||
{
|
||||
// Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
|
||||
static WinGLContext() {
|
||||
// Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
|
||||
if (opengl32Handle == IntPtr.Zero) {
|
||||
opengl32Handle = Functions.LoadLibrary(opengl32Name);
|
||||
if (opengl32Handle == IntPtr.Zero)
|
||||
{
|
||||
opengl32Handle = Functions.LoadLibrary(opengl32Name);
|
||||
if (opengl32Handle == IntPtr.Zero)
|
||||
throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
|
||||
opengl32Name, Marshal.GetLastWin32Error()));
|
||||
Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
|
||||
}
|
||||
throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
|
||||
opengl32Name, Marshal.GetLastWin32Error()));
|
||||
Debug.Print( "Loaded opengl32.dll: {0}", opengl32Handle );
|
||||
}
|
||||
}
|
||||
|
||||
public WinGLContext(GraphicsMode format, WinWindowInfo window)
|
||||
{
|
||||
// There are many ways this code can break when accessed by multiple threads. The biggest offender is
|
||||
// the sharedContext stuff, which will only become valid *after* this constructor returns.
|
||||
// The easiest solution is to serialize all context construction - hence the big lock, below.
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentNullException("window", "Must point to a valid window.");
|
||||
if (window.WindowHandle == IntPtr.Zero)
|
||||
throw new ArgumentException("window", "Must be a valid window.");
|
||||
public WinGLContext(GraphicsMode format, WinWindowInfo window) {
|
||||
if (window == null)
|
||||
throw new ArgumentNullException("window", "Must point to a valid window.");
|
||||
if (window.WindowHandle == IntPtr.Zero)
|
||||
throw new ArgumentException("window", "Must be a valid window.");
|
||||
|
||||
Debug.Print("OpenGL will be bound to handle: {0}", window.WindowHandle);
|
||||
SelectGraphicsModePFD(format, (WinWindowInfo)window);
|
||||
Debug.Write("Setting pixel format... ");
|
||||
SetGraphicsModePFD(format, (WinWindowInfo)window);
|
||||
Debug.Print( "OpenGL will be bound to handle: {0}", window.WindowHandle );
|
||||
SelectGraphicsModePFD(format, (WinWindowInfo)window);
|
||||
Debug.Write( "Setting pixel format... " );
|
||||
SetGraphicsModePFD(format, (WinWindowInfo)window);
|
||||
|
||||
Debug.Write("Falling back to GL2... ");
|
||||
ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
|
||||
if (ContextHandle == IntPtr.Zero)
|
||||
ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
|
||||
if (ContextHandle == IntPtr.Zero)
|
||||
ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
|
||||
if (ContextHandle == IntPtr.Zero)
|
||||
throw new GraphicsContextException(
|
||||
String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
|
||||
Marshal.GetLastWin32Error()));
|
||||
|
||||
Debug.WriteLine(String.Format("success! (id: {0})", ContextHandle));
|
||||
}
|
||||
if (ContextHandle == IntPtr.Zero)
|
||||
throw new GraphicsContextException(
|
||||
String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
|
||||
Marshal.GetLastWin32Error()));
|
||||
|
||||
Debug.Print( "success! (id: {0})", ContextHandle );
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGraphicsContext Members ---
|
||||
|
||||
#region SwapBuffers
|
||||
|
||||
public override void SwapBuffers()
|
||||
{
|
||||
public override void SwapBuffers() {
|
||||
if (!Functions.SwapBuffers(dc))
|
||||
throw new GraphicsContextException(String.Format(
|
||||
"Failed to swap buffers for context {0} current. Error: {1}", this, Marshal.GetLastWin32Error()));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MakeCurrent
|
||||
|
||||
IntPtr dc;
|
||||
public override void MakeCurrent(IWindowInfo window)
|
||||
{
|
||||
public override void MakeCurrent(IWindowInfo window) {
|
||||
bool success;
|
||||
|
||||
if (window != null) {
|
||||
@ -118,61 +80,27 @@ namespace OpenTK.Platform.Windows
|
||||
"Failed to make context {0} current. Error: {1}", this, Marshal.GetLastWin32Error()));
|
||||
dc = Wgl.wglGetCurrentDC();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IsCurrent
|
||||
|
||||
public override bool IsCurrent
|
||||
{
|
||||
public override bool IsCurrent {
|
||||
get { return Wgl.wglGetCurrentContext() == ContextHandle; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool VSync
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a System.Boolean indicating whether SwapBuffer calls are synced to the screen refresh rate.
|
||||
/// </summary>
|
||||
/// <summary> Gets or sets a System.Boolean indicating whether SwapBuffer calls are synced to the screen refresh rate. </summary>
|
||||
public override bool VSync {
|
||||
get {
|
||||
return vsync_supported && Wgl.wglGetSwapIntervalEXT() != 0;
|
||||
}
|
||||
get { return vsync_supported && Wgl.wglGetSwapIntervalEXT() != 0; }
|
||||
set {
|
||||
if (vsync_supported)
|
||||
Wgl.wglSwapIntervalEXT(value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region void LoadAll()
|
||||
|
||||
public override void LoadAll()
|
||||
{
|
||||
public override void LoadAll() {
|
||||
new Wgl().LoadEntryPoints();
|
||||
vsync_supported = Wgl.wglGetSwapIntervalEXT != null
|
||||
vsync_supported = Wgl.wglGetSwapIntervalEXT != null
|
||||
&& Wgl.wglSwapIntervalEXT != null;
|
||||
new OpenTK.Graphics.OpenGL.GL().LoadEntryPoints( this );
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IGLContextInternal Members ---
|
||||
|
||||
#region IWindowInfo IGLContextInternal.Info
|
||||
/*
|
||||
IWindowInfo IGraphicsContextInternal.Info
|
||||
{
|
||||
get { return (IWindowInfo)windowInfo; }
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region GetAddress
|
||||
|
||||
public override IntPtr GetAddress(string funcName) {
|
||||
IntPtr dynAddress = Wgl.wglGetProcAddress(funcName);
|
||||
if( !BindingsBase.IsInvalidAddress( dynAddress ) )
|
||||
@ -180,11 +108,6 @@ namespace OpenTK.Platform.Windows
|
||||
return Functions.GetProcAddress( opengl32Handle, funcName );
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Methods ---
|
||||
|
||||
int modeIndex;
|
||||
void SetGraphicsModePFD(GraphicsMode mode, WinWindowInfo window) {
|
||||
@ -237,75 +160,46 @@ namespace OpenTK.Platform.Windows
|
||||
throw new GraphicsModeException("The requested GraphicsMode is not available.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Overrides ---
|
||||
|
||||
/// <summary>Returns a System.String describing this OpenGL context.</summary>
|
||||
/// <returns>A System.String describing this OpenGL context.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return (this as IGraphicsContextInternal).Context.ToString();
|
||||
public override string ToString() {
|
||||
return ContextHandle.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
public override void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool calledManually)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (calledManually)
|
||||
{
|
||||
DestroyContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("[Warning] OpenGL context {0} leaked. Did you forget to call IGraphicsContext.Dispose()?", ContextHandle);
|
||||
}
|
||||
IsDisposed = true;
|
||||
private void Dispose(bool calledManually) {
|
||||
if (IsDisposed) return;
|
||||
|
||||
if (calledManually) {
|
||||
DestroyContext();
|
||||
} else {
|
||||
Debug.Print("[Warning] OpenGL context {0} leaked. Did you forget to call IGraphicsContext.Dispose()?", ContextHandle);
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
~WinGLContext()
|
||||
{
|
||||
~WinGLContext() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#region private void DestroyContext()
|
||||
|
||||
private void DestroyContext()
|
||||
{
|
||||
if (ContextHandle != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
// This will fail if the user calls Dispose() on thread X when the context is current on thread Y.
|
||||
if (!Wgl.wglDeleteContext(ContextHandle))
|
||||
Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}",
|
||||
ContextHandle.ToString(), Marshal.GetLastWin32Error());
|
||||
}
|
||||
catch (AccessViolationException e)
|
||||
{
|
||||
Debug.WriteLine("An access violation occured while destroying the OpenGL context. Please report at http://www.opentk.com.");
|
||||
Debug.Indent();
|
||||
Debug.Print("Marshal.GetLastWin32Error(): {0}", Marshal.GetLastWin32Error().ToString());
|
||||
Debug.WriteLine(e.ToString());
|
||||
Debug.Unindent();
|
||||
}
|
||||
ContextHandle = IntPtr.Zero;
|
||||
private void DestroyContext() {
|
||||
if (ContextHandle == IntPtr.Zero) return;
|
||||
|
||||
try {
|
||||
// This will fail if the user calls Dispose() on thread X when the context is current on thread Y.
|
||||
if (!Wgl.wglDeleteContext(ContextHandle))
|
||||
Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}",
|
||||
ContextHandle.ToString(), Marshal.GetLastWin32Error());
|
||||
} catch (AccessViolationException e) {
|
||||
Debug.WriteLine("An access violation occured while destroying the OpenGL context. Please report at http://www.opentk.com.");
|
||||
Debug.Indent();
|
||||
Debug.Print("Marshal.GetLastWin32Error(): {0}", Marshal.GetLastWin32Error().ToString());
|
||||
Debug.WriteLine(e.ToString());
|
||||
Debug.Unindent();
|
||||
}
|
||||
ContextHandle = IntPtr.Zero;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
internal class WinKeyMap : Dictionary<int, Input.Key>
|
||||
{
|
||||
namespace OpenTK.Platform.Windows {
|
||||
|
||||
internal class WinKeyMap : Dictionary<int, Key> {
|
||||
|
||||
/// <summary> Initializes the map between VirtualKeys and OpenTK.Key </summary>
|
||||
internal WinKeyMap()
|
||||
{
|
||||
internal WinKeyMap() {
|
||||
AddKey(VirtualKeys.ESCAPE, Key.Escape);
|
||||
|
||||
// Function keys
|
||||
@ -76,8 +75,7 @@ namespace OpenTK.Platform.Windows
|
||||
AddKey(VirtualKeys.SLEEP, Key.Sleep);
|
||||
|
||||
// Keypad
|
||||
for (int i = 0; i <= 9; i++)
|
||||
{
|
||||
for (int i = 0; i <= 9; i++) {
|
||||
AddKey((VirtualKeys)((int)VirtualKeys.NUMPAD0 + i), Key.Keypad0 + i);
|
||||
}
|
||||
AddKey(VirtualKeys.DECIMAL, Key.KeypadDecimal);
|
||||
|
@ -26,62 +26,39 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.Platform.Windows
|
||||
{
|
||||
namespace OpenTK.Platform.Windows {
|
||||
|
||||
/// \internal
|
||||
/// <summary>Describes a win32 window.</summary>
|
||||
public sealed class WinWindowInfo : IWindowInfo
|
||||
{
|
||||
public sealed class WinWindowInfo : IWindowInfo {
|
||||
IntPtr handle, dc;
|
||||
WinWindowInfo parent;
|
||||
bool disposed;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance.
|
||||
/// </summary>
|
||||
public WinWindowInfo()
|
||||
{
|
||||
/// <summary> Constructs a new instance. </summary>
|
||||
public WinWindowInfo() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance with the specified window handle and paren.t
|
||||
/// </summary>
|
||||
/// <summary> Constructs a new instance with the specified window handle and parent. </summary>
|
||||
/// <param name="handle">The window handle for this instance.</param>
|
||||
/// <param name="parent">The parent window of this instance (may be null).</param>
|
||||
public WinWindowInfo(IntPtr handle, WinWindowInfo parent)
|
||||
{
|
||||
public WinWindowInfo(IntPtr handle, WinWindowInfo parent) {
|
||||
this.handle = handle;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the handle of the window.
|
||||
/// </summary>
|
||||
/// <summary> Gets or sets the handle of the window. </summary>
|
||||
public IntPtr WindowHandle { get { return handle; } set { handle = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Parent of the window (may be null).
|
||||
/// </summary>
|
||||
/// <summary> Gets or sets the Parent of the window (may be null). </summary>
|
||||
public WinWindowInfo Parent { get { return parent; } set { parent = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device context for this window instance.
|
||||
/// </summary>
|
||||
public IntPtr DeviceContext
|
||||
{
|
||||
get
|
||||
{
|
||||
/// <summary> Gets the device context for this window instance. </summary>
|
||||
public IntPtr DeviceContext {
|
||||
get {
|
||||
if (dc == IntPtr.Zero)
|
||||
dc = Functions.GetDC(this.WindowHandle);
|
||||
//dc = Functions.GetWindowDC(this.WindowHandle);
|
||||
@ -89,21 +66,17 @@ namespace OpenTK.Platform.Windows
|
||||
}
|
||||
}
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>Returns a System.String that represents the current window.</summary>
|
||||
/// <returns>A System.String that represents the current window.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
public override string ToString() {
|
||||
return String.Format("Windows.WindowInfo: Handle {0}, Parent ({1})",
|
||||
this.WindowHandle, this.Parent != null ? this.Parent.ToString() : "null");
|
||||
WindowHandle, Parent != null ? Parent.ToString() : "null");
|
||||
}
|
||||
|
||||
/// <summary>Checks if <c>this</c> and <c>obj</c> reference the same win32 window.</summary>
|
||||
/// <param name="obj">The object to check against.</param>
|
||||
/// <returns>True if <c>this</c> and <c>obj</c> reference the same win32 window; false otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null) return false;
|
||||
if (this.GetType() != obj.GetType()) return false;
|
||||
WinWindowInfo info = (WinWindowInfo)obj;
|
||||
@ -115,59 +88,30 @@ namespace OpenTK.Platform.Windows
|
||||
|
||||
/// <summary>Returns the hash code for this instance.</summary>
|
||||
/// <returns>A hash code for the current <c>WinWindowInfo</c>.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
public override int GetHashCode() {
|
||||
return handle.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable ---
|
||||
|
||||
#region public void Dispose()
|
||||
|
||||
/// <summary>Releases the unmanaged resources consumed by this instance.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region void Dispose(bool manual)
|
||||
|
||||
void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (this.dc != IntPtr.Zero)
|
||||
void Dispose(bool manual) {
|
||||
if (!disposed) {
|
||||
if (dc != IntPtr.Zero)
|
||||
if (!Functions.ReleaseDC(this.handle, this.dc))
|
||||
Debug.Print("[Warning] Failed to release device context {0}. Windows error: {1}.", this.dc, Marshal.GetLastWin32Error());
|
||||
|
||||
if (manual)
|
||||
{
|
||||
if (parent != null)
|
||||
parent.Dispose();
|
||||
}
|
||||
|
||||
if (manual && parent != null)
|
||||
parent.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ~WinWindowInfo()
|
||||
|
||||
~WinWindowInfo()
|
||||
{
|
||||
this.Dispose(false);
|
||||
~WinWindowInfo() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1010,22 +1010,6 @@ namespace OpenTK.Platform.X11
|
||||
BorderWidth = 1 << 4,
|
||||
Sibling = 1 << 5,
|
||||
StackMode = 1 << 6,
|
||||
|
||||
//BackPixmap (1L<<0)
|
||||
//BackPixel (1L<<1)
|
||||
//SaveUnder (1L<<10)
|
||||
//EventMask (1L<<11)
|
||||
//DontPropagate (1L<<12)
|
||||
//Colormap (1L<<13)
|
||||
//Cursor (1L<<14)
|
||||
//BorderPixmap (1L<<2)
|
||||
//BorderPixel (1L<<3)
|
||||
//BitGravity (1L<<4)
|
||||
//WinGravity (1L<<5)
|
||||
//BackingStore (1L<<6)
|
||||
//BackingPlanes (1L<<7)
|
||||
//BackingPixel (1L<<8)
|
||||
OverrideRedirect = 1<<9,
|
||||
}
|
||||
|
||||
internal enum StackMode
|
||||
|
@ -16,7 +16,6 @@ namespace OpenTK.Platform.X11
|
||||
{
|
||||
internal class X11DisplayDevice : IDisplayDeviceDriver
|
||||
{
|
||||
static object display_lock = new object();
|
||||
// Store a mapping between resolutions and their respective
|
||||
// size_index (needed for XRRSetScreenConfig). The size_index
|
||||
// is simply the sequence number of the resolution as returned by
|
||||
@ -95,7 +94,7 @@ namespace OpenTK.Platform.X11
|
||||
if (NativeMethods.XineramaQueryExtension(API.DefaultDisplay, out event_base, out error_base) &&
|
||||
NativeMethods.XineramaIsActive(API.DefaultDisplay))
|
||||
{
|
||||
IList<XineramaScreenInfo> screens = NativeMethods.XineramaQueryScreens(API.DefaultDisplay);
|
||||
XineramaScreenInfo[] screens = NativeMethods.XineramaQueryScreens(API.DefaultDisplay);
|
||||
bool first = true;
|
||||
foreach (XineramaScreenInfo screen in screens)
|
||||
{
|
||||
@ -310,31 +309,21 @@ namespace OpenTK.Platform.X11
|
||||
[DllImport(Xinerama)]
|
||||
public static extern bool XineramaQueryExtension(IntPtr dpy, out int event_basep, out int error_basep);
|
||||
|
||||
[DllImport(Xinerama)]
|
||||
public static extern int XineramaQueryVersion (IntPtr dpy, out int major_versionp, out int minor_versionp);
|
||||
|
||||
[DllImport(Xinerama)]
|
||||
public static extern bool XineramaIsActive(IntPtr dpy);
|
||||
|
||||
[DllImport(Xinerama)]
|
||||
static extern IntPtr XineramaQueryScreens(IntPtr dpy, out int number);
|
||||
|
||||
public static IList<XineramaScreenInfo> XineramaQueryScreens(IntPtr dpy)
|
||||
{
|
||||
int number;
|
||||
IntPtr screen_ptr = XineramaQueryScreens(dpy, out number);
|
||||
List<XineramaScreenInfo> screens = new List<XineramaScreenInfo>(number);
|
||||
|
||||
unsafe
|
||||
{
|
||||
XineramaScreenInfo* ptr = (XineramaScreenInfo*)screen_ptr;
|
||||
while (--number >= 0)
|
||||
{
|
||||
screens.Add(*ptr);
|
||||
ptr++;
|
||||
}
|
||||
public unsafe static XineramaScreenInfo[] XineramaQueryScreens(IntPtr dpy) {
|
||||
int count;
|
||||
IntPtr screen_ptr = XineramaQueryScreens(dpy, out count);
|
||||
XineramaScreenInfo* ptr = (XineramaScreenInfo*)screen_ptr;
|
||||
|
||||
XineramaScreenInfo[] screens = new XineramaScreenInfo[count];
|
||||
for( int i = 0; i < screens.Length; i++ ) {
|
||||
screens[i] = *ptr++;
|
||||
}
|
||||
|
||||
return screens;
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
//
|
||||
// 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.Diagnostics;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace OpenTK.Platform.X11
|
||||
{
|
||||
class X11Factory : IPlatformFactory
|
||||
{
|
||||
#region IPlatformFactory Members
|
||||
|
||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||
{
|
||||
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
||||
}
|
||||
|
||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||
{
|
||||
return new X11DisplayDevice();
|
||||
}
|
||||
|
||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window)
|
||||
{
|
||||
return new X11GLContext(mode, window);
|
||||
}
|
||||
|
||||
public virtual IGraphicsMode CreateGraphicsMode()
|
||||
{
|
||||
return new X11GraphicsMode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user