Fix screen bounds determining in some cases in X11DisplayDevice

This commit is contained in:
UnknownShadow200 2017-08-08 00:03:00 +10:00
parent 63530be40a
commit e6ec7037aa
12 changed files with 416 additions and 449 deletions

View File

@ -1,22 +1,22 @@
using System;
namespace OpenTK {
/// <summary> Placeholder for System.Diagnostics.Debug class because it crashes on some Mono version on Linux. </summary>
public static class Debug {
public static void Print(string text) {
try {
Console.WriteLine(text);
} catch (Exception) {
} // raised by Mono sometimes when trying to write to console from the finalizer thread.
}
public static void Print(string text, params object[] args) {
try {
Console.WriteLine(text, args);
} catch (Exception) {
}
}
}
}
using System;
namespace OpenTK {
/// <summary> Placeholder for System.Diagnostics.Debug class because it crashes on some Mono version on Linux. </summary>
public static class Debug {
public static void Print(string text) {
try {
Console.WriteLine(text);
} catch (Exception) {
} // raised by Mono sometimes when trying to write to console from the finalizer thread.
}
public static void Print(string text, params object[] args) {
try {
Console.WriteLine(text, args);
} catch (Exception) {
}
}
}
}

View File

@ -6,8 +6,8 @@
*/
#endregion
using System;
using System.Drawing;
using System;
using System.Drawing;
namespace OpenTK {

View File

@ -92,8 +92,7 @@ namespace OpenTK
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext,
GameWindowFlags options, DisplayDevice device)
: base(width, height, title, options, mode, device) {
GameWindowFlags options, DisplayDevice device) : base(width, height, title, mode, device) {
try {
glContext = nullContext ? new NullContext() :
Factory.Default.CreateGLContext(mode, WindowInfo);

View File

@ -37,14 +37,9 @@ namespace OpenTK {
/// <summary> Instances of this class implement the <see cref="OpenTK.INativeWindow"/> interface on the current platform. </summary>
public class NativeWindow : INativeWindow {
private readonly GameWindowFlags options;
private readonly DisplayDevice device;
private readonly INativeWindow implementation;
private bool disposed, events;
/// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
public NativeWindow()
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
/// <param name="width">The width of the NativeWindow in pixels.</param>
@ -55,10 +50,10 @@ namespace OpenTK {
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
public NativeWindow(int width, int height, string title, GraphicsMode mode, DisplayDevice device)
: this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
device.Bounds.Top + (device.Bounds.Height - height) / 2,
width, height, title, options, mode, device) { }
width, height, title, mode, device) { }
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
@ -71,7 +66,7 @@ namespace OpenTK {
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
/// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device) {
public NativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
// TODO: Should a constraint be added for the position?
if (width < 1)
throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
@ -82,10 +77,9 @@ namespace OpenTK {
if (device == null)
throw new ArgumentNullException("device");
this.options = options;
this.device = device;
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
implementation = Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, this.device);
}
/// <summary> Closes the NativeWindow. </summary>

View File

@ -1,155 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{35FEE071-2DE6-48A1-9343-B5C1F202A12B}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>OpenTK</RootNamespace>
<AssemblyName>OpenTK</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
<OutputPath>..\output\debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\output\release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<StartAction>Project</StartAction>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="BindingsBase.cs" />
<Compile Include="Debug.cs" />
<Compile Include="DisplayDevice.cs" />
<Compile Include="FrameEventArgs.cs" />
<Compile Include="GameWindow.cs" />
<Compile Include="Graphics\OpenGL\GL.cs" />
<Compile Include="IGameWindow.cs" />
<Compile Include="INativeWindow.cs" />
<Compile Include="Interop.cs" />
<Compile Include="KeyPressEventArgs.cs" />
<Compile Include="MemUtils.cs" />
<Compile Include="NativeWindow.cs" />
<Compile Include="Graphics\ColorFormat.cs" />
<Compile Include="Graphics\GraphicsContextBase.cs" />
<Compile Include="Graphics\GraphicsContextException.cs" />
<Compile Include="Graphics\GraphicsMode.cs" />
<Compile Include="Graphics\GraphicsModeException.cs" />
<Compile Include="Graphics\IGraphicsContext.cs" />
<Compile Include="Graphics\OpenGL\GLEnums.cs" />
<Compile Include="Graphics\OpenGL\GLHelper.cs" />
<Compile Include="Input\Key.cs" />
<Compile Include="Input\KeyboardDevice.cs" />
<Compile Include="Input\MouseButton.cs" />
<Compile Include="Input\MouseDevice.cs" />
<Compile Include="Math\Matrix4.cs" />
<Compile Include="Math\Vector2.cs" />
<Compile Include="Math\Vector3.cs" />
<Compile Include="Math\Vector4.cs" />
<Compile Include="Platform\Configuration.cs" />
<Compile Include="Platform\IPlatformFactory.cs" />
<Compile Include="Platform\IWindowInfo.cs" />
<Compile Include="Platform\MacOS\AglContext.cs" />
<Compile Include="Platform\MacOS\Application.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\Agl.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\CarbonAPI.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\CoreFoundation.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\MacOSKeys.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\QuartzDisplayServicesAPI.cs" />
<Compile Include="Platform\MacOS\CarbonGLNative.cs" />
<Compile Include="Platform\MacOS\CarbonWindowInfo.cs" />
<Compile Include="Platform\MacOS\MacOSException.cs" />
<Compile Include="Platform\MacOS\MacOSKeyMap.cs" />
<Compile Include="Platform\MacOS\QuartzDisplayDevice.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\WinGLContext.cs" />
<Compile Include="Platform\Windows\WinGLNative.cs" />
<Compile Include="Platform\Windows\WinKeyMap.cs" />
<Compile Include="Platform\Windows\WinWindowInfo.cs" />
<Compile Include="Platform\NullContext.cs" />
<Compile Include="Platform\X11\API.cs" />
<Compile Include="Platform\X11\Functions.cs" />
<Compile Include="Platform\X11\Glx.cs" />
<Compile Include="Platform\X11\Structs.cs" />
<Compile Include="Platform\X11\X11DisplayDevice.cs" />
<Compile Include="Platform\X11\X11GLContext.cs" />
<Compile Include="Platform\X11\X11GLNative.cs" />
<Compile Include="Platform\X11\X11KeyMap.cs" />
<Compile Include="Platform\X11\X11WindowInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpDX.Direct3D\AdapterDetails.cs" />
<Compile Include="SharpDX.Direct3D\Device.cs" />
<Compile Include="SharpDX.Direct3D\Direct3D.cs" />
<Compile Include="SharpDX.Direct3D\Enumerations.cs" />
<Compile Include="SharpDX.Direct3D\PresentParameters.cs" />
<Compile Include="SharpDX.Direct3D\Resources.cs" />
<Compile Include="SharpDX.Direct3D\Structures.cs" />
<Compile Include="SharpDX\ComObject.cs" />
<Compile Include="SharpDX\Raw.cs" />
<Compile Include="SharpDX\Result.cs" />
<Compile Include="WindowState.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Graphics" />
<Folder Include="Graphics\OpenGL" />
<Folder Include="Input" />
<Folder Include="Math" />
<Folder Include="Platform" />
<Folder Include="Platform\MacOS" />
<Folder Include="Platform\MacOS\CarbonBindings" />
<Folder Include="Platform\Windows" />
<Folder Include="Platform\X11" />
<Folder Include="Properties" />
<Folder Include="SharpDX" />
<Folder Include="SharpDX.Direct3D" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InteropPatcher\InteropPatcher.csproj">
<Project>{4A4110EE-21CA-4715-AF67-0C8B7CE0642F}</Project>
<Name>InteropPatcher</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<!-- This actually rewrites the calli and fixed code.-->
<Target Name="AfterBuild">
<Exec Command="$(OutputPath)InteropPatcher.exe $(OutDir)OpenTK.dll" />
<!--Copy back *.dll from bin/Debug|Release to obj/Debug/Release directory-->
<Copy SourceFiles="@(MainAssembly)" DestinationFolder="$(IntermediateOutputPath)" SkipUnchangedFiles="true" />
<!-- Copy back *.pdb from bin/Debug|Release to obj/Debug/Release directory-->
<Copy SourceFiles="@(_DebugSymbolsOutputPath)" DestinationFiles="@(_DebugSymbolsIntermediatePath)" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true' and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true'" />
</Target>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{35FEE071-2DE6-48A1-9343-B5C1F202A12B}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>OpenTK</RootNamespace>
<AssemblyName>OpenTK</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
<OutputPath>..\output\debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\output\release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<StartAction>Project</StartAction>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="BindingsBase.cs" />
<Compile Include="Debug.cs" />
<Compile Include="DisplayDevice.cs" />
<Compile Include="FrameEventArgs.cs" />
<Compile Include="GameWindow.cs" />
<Compile Include="Graphics\OpenGL\GL.cs" />
<Compile Include="IGameWindow.cs" />
<Compile Include="INativeWindow.cs" />
<Compile Include="Interop.cs" />
<Compile Include="KeyPressEventArgs.cs" />
<Compile Include="MemUtils.cs" />
<Compile Include="NativeWindow.cs" />
<Compile Include="Graphics\ColorFormat.cs" />
<Compile Include="Graphics\GraphicsContextBase.cs" />
<Compile Include="Graphics\GraphicsContextException.cs" />
<Compile Include="Graphics\GraphicsMode.cs" />
<Compile Include="Graphics\GraphicsModeException.cs" />
<Compile Include="Graphics\IGraphicsContext.cs" />
<Compile Include="Graphics\OpenGL\GLEnums.cs" />
<Compile Include="Graphics\OpenGL\GLHelper.cs" />
<Compile Include="Input\Key.cs" />
<Compile Include="Input\KeyboardDevice.cs" />
<Compile Include="Input\MouseButton.cs" />
<Compile Include="Input\MouseDevice.cs" />
<Compile Include="Math\Matrix4.cs" />
<Compile Include="Math\Vector2.cs" />
<Compile Include="Math\Vector3.cs" />
<Compile Include="Math\Vector4.cs" />
<Compile Include="Platform\Configuration.cs" />
<Compile Include="Platform\IPlatformFactory.cs" />
<Compile Include="Platform\IWindowInfo.cs" />
<Compile Include="Platform\MacOS\AglContext.cs" />
<Compile Include="Platform\MacOS\Application.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\Agl.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\CarbonAPI.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\CoreFoundation.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\MacOSKeys.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\QuartzDisplayServicesAPI.cs" />
<Compile Include="Platform\MacOS\CarbonGLNative.cs" />
<Compile Include="Platform\MacOS\CarbonWindowInfo.cs" />
<Compile Include="Platform\MacOS\MacOSException.cs" />
<Compile Include="Platform\MacOS\MacOSKeyMap.cs" />
<Compile Include="Platform\MacOS\QuartzDisplayDevice.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\WinGLContext.cs" />
<Compile Include="Platform\Windows\WinGLNative.cs" />
<Compile Include="Platform\Windows\WinKeyMap.cs" />
<Compile Include="Platform\Windows\WinWindowInfo.cs" />
<Compile Include="Platform\NullContext.cs" />
<Compile Include="Platform\X11\API.cs" />
<Compile Include="Platform\X11\Functions.cs" />
<Compile Include="Platform\X11\Glx.cs" />
<Compile Include="Platform\X11\Structs.cs" />
<Compile Include="Platform\X11\X11DisplayDevice.cs" />
<Compile Include="Platform\X11\X11GLContext.cs" />
<Compile Include="Platform\X11\X11GLNative.cs" />
<Compile Include="Platform\X11\X11KeyMap.cs" />
<Compile Include="Platform\X11\X11WindowInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpDX.Direct3D\AdapterDetails.cs" />
<Compile Include="SharpDX.Direct3D\Device.cs" />
<Compile Include="SharpDX.Direct3D\Direct3D.cs" />
<Compile Include="SharpDX.Direct3D\Enumerations.cs" />
<Compile Include="SharpDX.Direct3D\PresentParameters.cs" />
<Compile Include="SharpDX.Direct3D\Resources.cs" />
<Compile Include="SharpDX.Direct3D\Structures.cs" />
<Compile Include="SharpDX\ComObject.cs" />
<Compile Include="SharpDX\Raw.cs" />
<Compile Include="SharpDX\Result.cs" />
<Compile Include="WindowState.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Graphics" />
<Folder Include="Graphics\OpenGL" />
<Folder Include="Input" />
<Folder Include="Math" />
<Folder Include="Platform" />
<Folder Include="Platform\MacOS" />
<Folder Include="Platform\MacOS\CarbonBindings" />
<Folder Include="Platform\Windows" />
<Folder Include="Platform\X11" />
<Folder Include="Properties" />
<Folder Include="SharpDX" />
<Folder Include="SharpDX.Direct3D" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InteropPatcher\InteropPatcher.csproj">
<Project>{4A4110EE-21CA-4715-AF67-0C8B7CE0642F}</Project>
<Name>InteropPatcher</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<!-- This actually rewrites the calli and fixed code.-->
<Target Name="AfterBuild">
<Exec Command="$(OutputPath)InteropPatcher.exe $(OutDir)OpenTK.dll" />
<!--Copy back *.dll from bin/Debug|Release to obj/Debug/Release directory-->
<Copy SourceFiles="@(MainAssembly)" DestinationFolder="$(IntermediateOutputPath)" SkipUnchangedFiles="true" />
<!-- Copy back *.pdb from bin/Debug|Release to obj/Debug/Release directory-->
<Copy SourceFiles="@(_DebugSymbolsOutputPath)" DestinationFiles="@(_DebugSymbolsIntermediatePath)" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true' and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true'" />
</Target>
</Project>

View File

@ -1,20 +1,20 @@
#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,
#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
@ -31,7 +31,7 @@ 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);
INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device);
void InitDisplayDeviceDriver();
@ -53,8 +53,8 @@ namespace OpenTK.Platform {
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, options, device);
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
return new CarbonGLNative(x, y, width, height, title, device);
}
public void InitDisplayDeviceDriver() {
@ -70,8 +70,8 @@ namespace OpenTK.Platform.MacOS {
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 INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
return new WinGLNative(x, y, width, height, title, device);
}
public void InitDisplayDeviceDriver() {
@ -87,8 +87,8 @@ namespace OpenTK.Platform.Windows {
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 INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
return new X11GLNative(x, y, width, height, title, mode, device);
}
public void InitDisplayDeviceDriver() {

View File

@ -66,7 +66,7 @@ namespace OpenTK.Platform.MacOS
Application.Initialize();
}
public CarbonGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
public CarbonGLNative(int x, int y, int width, int height, string title, DisplayDevice device)
{
this.title = title;
CreateNativeWindow(WindowClass.Document,

View File

@ -1,57 +1,57 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK team.
* This notice may not be removed.
* See license.txt for licensing detailed licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
namespace OpenTK.Platform.Windows {
internal static class WinDisplayDevice {
/// <summary>Queries available display devices and display resolutions.</summary>
internal static void Init() {
// To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
// we only allow settings to be set through its constructor.
// Thus, we save all necessary parameters in temporary variables
// and construct the device when every needed detail is available.
// The main DisplayDevice constructor adds the newly constructed device
// to the list of available devices.
DisplayResolution currentRes = null;
bool devPrimary = false;
int deviceNum = 0;
// Get available video adapters and enumerate all monitors
WindowsDisplayDevice winDev = new WindowsDisplayDevice();
while (API.EnumDisplayDevices(null, deviceNum++, winDev, 0)) {
if ((winDev.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
continue;
DeviceMode mode = new DeviceMode();
// The second function should only be executed when the first one fails (e.g. when the monitor is disabled)
if (API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Current, mode) ||
API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Registry, mode)) {
if (mode.BitsPerPel > 0) {
currentRes = new DisplayResolution(
mode.PelsWidth, mode.PelsHeight,
mode.BitsPerPel, mode.DisplayFrequency);
devPrimary = (winDev.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0;
}
}
// This device has no valid resolution, ignore it
if (currentRes == null) continue;
// Construct the OpenTK DisplayDevice through the accumulated parameters.
// The constructor automatically adds the DisplayDevice to the list of available devices.
DisplayDevice device = new DisplayDevice(currentRes, devPrimary);
currentRes = null;
}
}
}
}
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK team.
* This notice may not be removed.
* See license.txt for licensing detailed licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
namespace OpenTK.Platform.Windows {
internal static class WinDisplayDevice {
/// <summary>Queries available display devices and display resolutions.</summary>
internal static void Init() {
// To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
// we only allow settings to be set through its constructor.
// Thus, we save all necessary parameters in temporary variables
// and construct the device when every needed detail is available.
// The main DisplayDevice constructor adds the newly constructed device
// to the list of available devices.
DisplayResolution currentRes = null;
bool devPrimary = false;
int deviceNum = 0;
// Get available video adapters and enumerate all monitors
WindowsDisplayDevice winDev = new WindowsDisplayDevice();
while (API.EnumDisplayDevices(null, deviceNum++, winDev, 0)) {
if ((winDev.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
continue;
DeviceMode mode = new DeviceMode();
// The second function should only be executed when the first one fails (e.g. when the monitor is disabled)
if (API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Current, mode) ||
API.EnumDisplaySettings(winDev.DeviceName, (int)DisplayModeSettings.Registry, mode)) {
if (mode.BitsPerPel > 0) {
currentRes = new DisplayResolution(
mode.PelsWidth, mode.PelsHeight,
mode.BitsPerPel, mode.DisplayFrequency);
devPrimary = (winDev.StateFlags & DisplayDeviceStateFlags.PrimaryDevice) != 0;
}
}
// This device has no valid resolution, ignore it
if (currentRes == null) continue;
// Construct the OpenTK DisplayDevice through the accumulated parameters.
// The constructor automatically adds the DisplayDevice to the list of available devices.
DisplayDevice device = new DisplayDevice(currentRes, devPrimary);
currentRes = null;
}
}
}
}

View File

@ -64,15 +64,12 @@ namespace OpenTK.Platform.Windows
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys.
KeyPressEventArgs key_press = new KeyPressEventArgs();
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device) {
public WinGLNative(int x, int y, int width, int height, string title, DisplayDevice device) {
WindowProcedureDelegate = WindowProcedure;
// To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
// bound to the top-level window, but rather to a child window docked in the parent.
window = new WinWindowInfo(
CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null);
child_window = new WinWindowInfo(
CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window);
window = new WinWindowInfo(CreateWindow(x, y, width, height, title, device, IntPtr.Zero), null);
child_window = new WinWindowInfo(CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, device, window.WindowHandle), window);
exists = true;
}
@ -376,7 +373,7 @@ namespace OpenTK.Platform.Windows
Marshal.GetLastWin32Error());
}
IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle) {
IntPtr CreateWindow(int x, int y, int width, int height, string title, DisplayDevice device, IntPtr parentHandle) {
// Use win32 to create the native window.
// Keep in mind that some construction code runs in the WM_CREATE message handler.

View File

@ -26,8 +26,8 @@
// NOT COMPLETE
using System;
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
// X11 Version
namespace OpenTK.Platform.X11

View File

@ -1,166 +1,144 @@
#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.Drawing;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.X11 {
internal static class X11DisplayDevice {
static bool xinerama_supported, xrandr_supported, xf86_supported;
internal static void Init() {
List<DisplayDevice> devices = new List<DisplayDevice>();
try {
xinerama_supported = QueryXinerama(devices);
} catch {
Debug.Print("Xinerama query failed.");
}
if (!xinerama_supported) {
// We assume that devices are equivalent to the number of available screens.
// Note: this won't work correctly in the case of distinct X servers.
for (int i = 0; i < API.ScreenCount; i++) {
DisplayDevice dev = new DisplayDevice();
dev.IsPrimary = i == API.XDefaultScreen(API.DefaultDisplay);
dev.Metadata = i;
devices.Add(dev);
}
}
try {
xrandr_supported = QueryXRandR(devices);
} catch { }
if (!xrandr_supported) {
Debug.Print("XRandR query failed, falling back to XF86.");
try {
xf86_supported = QueryXF86(devices);
} catch { }
if (!xf86_supported) {
Debug.Print("XF86 query failed, no DisplayDevice support available.");
}
}
}
static bool QueryXinerama(List<DisplayDevice> devices) {
// Try to use Xinerama to obtain the geometry of all output devices.
int event_base, error_base;
if (NativeMethods.XineramaQueryExtension(API.DefaultDisplay, out event_base, out error_base) &&
NativeMethods.XineramaIsActive(API.DefaultDisplay)) {
XineramaScreenInfo[] screens = NativeMethods.XineramaQueryScreens(API.DefaultDisplay);
bool first = true;
foreach (XineramaScreenInfo screen in screens) {
DisplayDevice dev = new DisplayDevice();
dev.Bounds = new Rectangle(screen.X, screen.Y, screen.Width, screen.Height);
if (first) {
// We consider the first device returned by Xinerama as the primary one.
// Makes sense conceptually, but is there a way to verify this?
dev.IsPrimary = true;
first = false;
}
devices.Add(dev);
// It seems that all X screens are equal to 0 is Xinerama is enabled, at least on Nvidia (verify?)
dev.Metadata = 0; /*screen.ScreenNumber*/
}
}
return true;
}
static bool QueryXRandR(List<DisplayDevice> devices) {
// Get available resolutions. Then, for each resolution get all available rates.
foreach (DisplayDevice dev in devices) {
int screen = (int)dev.Metadata;
List<DisplayResolution> available_res = new List<DisplayResolution>();
int[] depths = API.XListDepths(API.DefaultDisplay, screen);
int resolution_count = 0;
foreach (XRRScreenSize size in FindAvailableResolutions(screen)) {
if (size.Width == 0 || size.Height == 0) {
Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
continue;
}
short[] rates = API.XRRRates(API.DefaultDisplay, screen, resolution_count);
// It seems that XRRRates returns 0 for modes that are larger than the screen
// can support, as well as for all supported modes. On Ubuntu 7.10 the tool
// "Screens and Graphics" does report these modes, though.
foreach (short rate in rates) {
// Note: some X servers (like Xming on Windows) do not report any rates other than 0.
// If we only have 1 rate, add it even if it is 0.
if (rate != 0 || rates.Length == 1)
foreach (int depth in depths)
available_res.Add(new DisplayResolution(size.Width, size.Height, depth, rate));
}
++resolution_count;
}
IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
ushort curRotation;
int curResolutionIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
float curRefreshRate = API.XRRConfigCurrentRate(screenConfig);
int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen);
API.XRRFreeScreenConfigInfo(screenConfig);
if (dev.Bounds == Rectangle.Empty)
dev.Bounds = new Rectangle(0, 0, available_res[curResolutionIndex].Width, available_res[curResolutionIndex].Height);
dev.BitsPerPixel = curDepth;
dev.RefreshRate = curRefreshRate;
}
return true;
}
static bool QueryXF86(List<DisplayDevice> devices) {
return false;
}
static XRRScreenSize[] FindAvailableResolutions(int screen) {
XRRScreenSize[] resolutions = API.XRRSizes(API.DefaultDisplay, screen);
if (resolutions == null)
throw new NotSupportedException("XRandR extensions not available.");
return resolutions;
}
static class NativeMethods {
const string Xinerama = "libXinerama";
[DllImport(Xinerama)]
public static extern bool XineramaQueryExtension(IntPtr dpy, out int event_basep, out int error_basep);
[DllImport(Xinerama)]
public static extern bool XineramaIsActive(IntPtr dpy);
[DllImport(Xinerama)]
static extern IntPtr XineramaQueryScreens(IntPtr dpy, out int count);
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;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct XineramaScreenInfo {
public int ScreenNumber;
public short X;
public short Y;
public short Width;
public short Height;
}
}
}
#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.Drawing;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.X11 {
internal static class X11DisplayDevice {
static bool xinerama_supported, xrandr_supported, xf86_supported;
internal static void Init() {
List<DisplayDevice> devices = new List<DisplayDevice>();
try {
xinerama_supported = QueryXinerama(devices);
} catch {
Debug.Print("Xinerama query failed.");
}
if (!xinerama_supported) {
// We assume that devices are equivalent to the number of available screens.
// Note: this won't work correctly in the case of distinct X servers.
for (int i = 0; i < API.ScreenCount; i++) {
DisplayDevice dev = new DisplayDevice();
dev.IsPrimary = i == API.XDefaultScreen(API.DefaultDisplay);
dev.Metadata = i;
devices.Add(dev);
}
}
try {
xrandr_supported = QueryXRandR(devices);
} catch { }
if (!xrandr_supported) {
Debug.Print("XRandR query failed, falling back to XF86.");
try {
xf86_supported = QueryXF86(devices);
} catch { }
if (!xf86_supported) {
Debug.Print("XF86 query failed, no DisplayDevice support available.");
}
}
}
static bool QueryXinerama(List<DisplayDevice> devices) {
// Try to use Xinerama to obtain the geometry of all output devices.
int event_base, error_base;
if (NativeMethods.XineramaQueryExtension(API.DefaultDisplay, out event_base, out error_base) &&
NativeMethods.XineramaIsActive(API.DefaultDisplay)) {
XineramaScreenInfo[] screens = NativeMethods.XineramaQueryScreens(API.DefaultDisplay);
bool first = true;
foreach (XineramaScreenInfo screen in screens) {
DisplayDevice dev = new DisplayDevice();
dev.Bounds = new Rectangle(screen.X, screen.Y, screen.Width, screen.Height);
if (first) {
// We consider the first device returned by Xinerama as the primary one.
// Makes sense conceptually, but is there a way to verify this?
dev.IsPrimary = true;
first = false;
}
devices.Add(dev);
// It seems that all X screens are equal to 0 is Xinerama is enabled, at least on Nvidia (verify?)
dev.Metadata = 0; /*screen.ScreenNumber*/
}
}
return true;
}
static bool QueryXRandR(List<DisplayDevice> devices) {
// Get available resolutions. Then, for each resolution get all available rates.
foreach (DisplayDevice dev in devices) {
int screen = (int)dev.Metadata;
XRRScreenSize[] sizes = FindAvailableResolutions(screen);
IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
ushort curRotation;
int curSizesIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
float curRefreshRate = API.XRRConfigCurrentRate(screenConfig);
int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen);
API.XRRFreeScreenConfigInfo(screenConfig);
if (dev.Bounds == Rectangle.Empty)
dev.Bounds = new Rectangle(0, 0, sizes[curSizesIndex].Width, sizes[curSizesIndex].Height);
dev.BitsPerPixel = curDepth;
dev.RefreshRate = curRefreshRate;
}
return true;
}
static bool QueryXF86(List<DisplayDevice> devices) {
return false;
}
static XRRScreenSize[] FindAvailableResolutions(int screen) {
XRRScreenSize[] resolutions = API.XRRSizes(API.DefaultDisplay, screen);
if (resolutions == null)
throw new NotSupportedException("XRandR extensions not available.");
return resolutions;
}
static class NativeMethods {
const string Xinerama = "libXinerama";
[DllImport(Xinerama)]
public static extern bool XineramaQueryExtension(IntPtr dpy, out int event_basep, out int error_basep);
[DllImport(Xinerama)]
public static extern bool XineramaIsActive(IntPtr dpy);
[DllImport(Xinerama)]
static extern IntPtr XineramaQueryScreens(IntPtr dpy, out int count);
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;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct XineramaScreenInfo {
public int ScreenNumber;
public short X;
public short Y;
public short Width;
public short Height;
}
}
}

View File

@ -85,8 +85,7 @@ namespace OpenTK.Platform.X11 {
int keysyms_per_keycode; // The number of KeySyms for each KeyCode.
IntPtr[] keysyms;
public X11GLNative(int x, int y, int width, int height, string title,
GraphicsMode mode, GameWindowFlags options, DisplayDevice device) {
public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) {
if (width <= 0)
throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
if (height <= 0)