Merge pull request #652 from Nihlus/glwidget-glarea
Base GLWidget on GLArea instead of DrawingArea
This commit is contained in:
commit
870f1abf8e
8 changed files with 85 additions and 468 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
image: Visual Studio 2017
|
||||||
init:
|
init:
|
||||||
- git config --global core.autocrlf input
|
- git config --global core.autocrlf input
|
||||||
build_script:
|
build_script:
|
||||||
|
|
|
@ -105,7 +105,8 @@ Target "AssemblyInfo" (fun _ ->
|
||||||
Attribute.Version release.AssemblyVersion
|
Attribute.Version release.AssemblyVersion
|
||||||
Attribute.FileVersion release.AssemblyVersion
|
Attribute.FileVersion release.AssemblyVersion
|
||||||
Attribute.CLSCompliant true
|
Attribute.CLSCompliant true
|
||||||
Attribute.Copyright copyright ]
|
Attribute.Copyright copyright
|
||||||
|
]
|
||||||
|
|
||||||
let getProjectDetails projectPath =
|
let getProjectDetails projectPath =
|
||||||
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
|
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Gdk;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using OpenTK.OSX;
|
|
||||||
using OpenTK.Win;
|
|
||||||
using OpenTK.X11;
|
|
||||||
|
|
||||||
namespace OpenTK
|
namespace OpenTK
|
||||||
{
|
{
|
||||||
|
@ -17,66 +12,28 @@ namespace OpenTK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
[ToolboxItem(true)]
|
[ToolboxItem(true)]
|
||||||
public class GLWidget: DrawingArea
|
public class GLWidget : GLArea
|
||||||
{
|
{
|
||||||
|
|
||||||
private static int _GraphicsContextCount;
|
private static int _GraphicsContextCount;
|
||||||
private static bool _SharedContextInitialized = false;
|
private static bool _SharedContextInitialized = false;
|
||||||
|
|
||||||
private IGraphicsContext _GraphicsContext;
|
private IGraphicsContext _GraphicsContext;
|
||||||
private IWindowInfo _WindowInfo;
|
|
||||||
private bool _Initialized = false;
|
private bool _Initialized = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use a single buffer versus a double buffer.
|
/// The previous frame time reported by GTK.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Browsable(true)]
|
private double? _PreviousFrameTime;
|
||||||
public bool SingleBuffer { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Color Buffer Bits-Per-Pixel
|
/// Gets the time taken to render the last frame (in seconds).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ColorBPP { get; set; }
|
public double DeltaTime { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Accumulation Buffer Bits-Per-Pixel
|
/// The set <see cref="ContextFlags"/> for this widget.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int AccumulatorBPP { get; set; }
|
public GraphicsContextFlags ContextFlags { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Depth Buffer Bits-Per-Pixel
|
|
||||||
/// </summary>
|
|
||||||
public int DepthBPP { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stencil Buffer Bits-Per-Pixel
|
|
||||||
/// </summary>
|
|
||||||
public int StencilBPP { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of samples
|
|
||||||
/// </summary>
|
|
||||||
public int Samples { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates if steropic renderering is enabled
|
|
||||||
/// </summary>
|
|
||||||
public bool Stereo { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The major version of OpenGL to use.
|
|
||||||
/// </summary>
|
|
||||||
public int GlVersionMajor { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The minor version of OpenGL to use.
|
|
||||||
/// </summary>
|
|
||||||
public int GlVersionMinor { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The set <see cref="GraphicsContextFlags"/> for this widget.
|
|
||||||
/// </summary>
|
|
||||||
public GraphicsContextFlags GraphicsContextFlags { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="GLWidget"/> class.
|
/// Initializes a new instance of the <see cref="GLWidget"/> class.
|
||||||
|
@ -98,24 +55,71 @@ namespace OpenTK
|
||||||
/// <param name="graphicsMode">The <see cref="GraphicsMode"/> which the widget should be constructed with.</param>
|
/// <param name="graphicsMode">The <see cref="GraphicsMode"/> which the widget should be constructed with.</param>
|
||||||
/// <param name="glVersionMajor">The major OpenGL version to attempt to initialize.</param>
|
/// <param name="glVersionMajor">The major OpenGL version to attempt to initialize.</param>
|
||||||
/// <param name="glVersionMinor">The minor OpenGL version to attempt to initialize.</param>
|
/// <param name="glVersionMinor">The minor OpenGL version to attempt to initialize.</param>
|
||||||
/// <param name="graphicsContextFlags">
|
/// <param name="contextFlags">
|
||||||
/// Any flags which should be used during initialization of the <see cref="GraphicsContext"/>.
|
/// Any flags which should be used during initialization of the <see cref="GraphicsContext"/>.
|
||||||
/// </param>
|
/// </param>
|
||||||
public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags graphicsContextFlags)
|
public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags contextFlags)
|
||||||
{
|
{
|
||||||
this.DoubleBuffered = false;
|
ContextFlags = contextFlags;
|
||||||
|
|
||||||
SingleBuffer = graphicsMode.Buffers == 1;
|
AddTickCallback(UpdateFrameTime);
|
||||||
ColorBPP = graphicsMode.ColorFormat.BitsPerPixel;
|
SetRequiredVersion(glVersionMajor, glVersionMinor);
|
||||||
AccumulatorBPP = graphicsMode.AccumulatorFormat.BitsPerPixel;
|
|
||||||
DepthBPP = graphicsMode.Depth;
|
|
||||||
StencilBPP = graphicsMode.Stencil;
|
|
||||||
Samples = graphicsMode.Samples;
|
|
||||||
Stereo = graphicsMode.Stereo;
|
|
||||||
|
|
||||||
GlVersionMajor = glVersionMajor;
|
if (graphicsMode.Depth > 0)
|
||||||
GlVersionMinor = glVersionMinor;
|
{
|
||||||
GraphicsContextFlags = graphicsContextFlags;
|
HasDepthBuffer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphicsMode.Stencil > 0)
|
||||||
|
{
|
||||||
|
HasStencilBuffer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphicsMode.ColorFormat.Alpha > 0)
|
||||||
|
{
|
||||||
|
HasAlpha = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the time delta with a new value from the last frame.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="widget">The sending widget.</param>
|
||||||
|
/// <param name="frameClock">The relevant frame clock.</param>
|
||||||
|
/// <returns>true if the callback should be called again; otherwise, false.</returns>
|
||||||
|
private bool UpdateFrameTime(Widget widget, FrameClock frameClock)
|
||||||
|
{
|
||||||
|
var frameTimeµSeconds = frameClock.FrameTime;
|
||||||
|
|
||||||
|
if (!_PreviousFrameTime.HasValue)
|
||||||
|
{
|
||||||
|
_PreviousFrameTime = frameTimeµSeconds;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var frameTimeSeconds = (frameTimeµSeconds - _PreviousFrameTime) / 10e6;
|
||||||
|
|
||||||
|
DeltaTime = (float)frameTimeSeconds;
|
||||||
|
_PreviousFrameTime = frameTimeµSeconds;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override GLContext OnCreateContext()
|
||||||
|
{
|
||||||
|
var gdkGLContext = Window.CreateGlContext();
|
||||||
|
|
||||||
|
GetRequiredVersion(out var major, out var minor);
|
||||||
|
gdkGLContext.SetRequiredVersion(major, minor);
|
||||||
|
|
||||||
|
gdkGLContext.DebugEnabled = ContextFlags.HasFlag(GraphicsContextFlags.Debug);
|
||||||
|
gdkGLContext.ForwardCompatible = ContextFlags.HasFlag(GraphicsContextFlags.ForwardCompatible);
|
||||||
|
|
||||||
|
gdkGLContext.Realize();
|
||||||
|
return gdkGLContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -137,39 +141,15 @@ namespace OpenTK
|
||||||
base.Destroy();
|
base.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !GTK3
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes the current object, releasing any native resources it was using.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing"></param>
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
Dispose(true);
|
|
||||||
|
|
||||||
base.Dispose();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the current object, releasing any native resources it was using.
|
/// Disposes the current object, releasing any native resources it was using.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing"></param>
|
/// <param name="disposing"></param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
base.Dispose(disposing);
|
|
||||||
#else
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes the current object, releasing any native resources it was using.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing"></param>
|
|
||||||
public virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_GraphicsContext.MakeCurrent(_WindowInfo);
|
MakeCurrent();
|
||||||
OnShuttingDown();
|
OnShuttingDown();
|
||||||
if (GraphicsContext.ShareContexts && (Interlocked.Decrement(ref _GraphicsContextCount) == 0))
|
if (GraphicsContext.ShareContexts && (Interlocked.Decrement(ref _GraphicsContextCount) == 0))
|
||||||
{
|
{
|
||||||
|
@ -231,22 +211,6 @@ namespace OpenTK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when this <see cref="GLWidget"/> needs to render a frame.
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler RenderFrame;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Invokes the <see cref="RenderFrame"/> event.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void OnRenderFrame()
|
|
||||||
{
|
|
||||||
if (RenderFrame != null)
|
|
||||||
{
|
|
||||||
RenderFrame(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when this <see cref="GLWidget"/> is being disposed.
|
/// Called when this <see cref="GLWidget"/> is being disposed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -263,62 +227,19 @@ namespace OpenTK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the widget needs to be (fully or partially) redrawn.
|
/// Called when the widget needs to be (fully or partially) redrawn.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cr"></param>
|
/// <param name="cr"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected override bool OnDrawn(Cairo.Context cr)
|
protected override bool OnDrawn(Cairo.Context cr)
|
||||||
#else
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the widget is exposed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cr"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected override bool OnExposeEvent(Gdk.EventExpose evnt)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (!_Initialized)
|
if (!_Initialized)
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_GraphicsContext.MakeCurrent(_WindowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
var result = base.OnDrawn(cr);
|
var result = base.OnDrawn(cr);
|
||||||
#else
|
|
||||||
bool result = base.OnExposeEvent(evnt);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
OnRenderFrame();
|
|
||||||
|
|
||||||
#if !GTK3
|
|
||||||
evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_GraphicsContext.SwapBuffers();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called whenever the widget is resized.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="evnt"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
|
|
||||||
{
|
|
||||||
bool result = base.OnConfigureEvent(evnt);
|
|
||||||
|
|
||||||
if (_GraphicsContext != null)
|
|
||||||
{
|
|
||||||
_GraphicsContext.Update(_WindowInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,66 +250,17 @@ namespace OpenTK
|
||||||
{
|
{
|
||||||
_Initialized = true;
|
_Initialized = true;
|
||||||
|
|
||||||
// If this looks uninitialized... initialize.
|
// Make the GDK GL context current
|
||||||
if (ColorBPP == 0)
|
MakeCurrent();
|
||||||
|
|
||||||
|
// Create a dummy context that will grab the GdkGLContext that is current on the thread
|
||||||
|
_GraphicsContext = new GraphicsContext(ContextHandle.Zero, null);
|
||||||
|
|
||||||
|
if (ContextFlags.HasFlag(GraphicsContextFlags.Debug))
|
||||||
{
|
{
|
||||||
ColorBPP = 32;
|
_GraphicsContext.ErrorChecking = true;
|
||||||
|
|
||||||
if (DepthBPP == 0)
|
|
||||||
{
|
|
||||||
DepthBPP = 16;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);
|
|
||||||
|
|
||||||
ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);
|
|
||||||
|
|
||||||
int buffers = 2;
|
|
||||||
if (SingleBuffer)
|
|
||||||
{
|
|
||||||
buffers--;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
|
|
||||||
|
|
||||||
if (Configuration.RunningOnWindows)
|
|
||||||
{
|
|
||||||
Console.WriteLine("OpenTK running on windows");
|
|
||||||
}
|
|
||||||
else if (Configuration.RunningOnMacOS)
|
|
||||||
{
|
|
||||||
Console.WriteLine("OpenTK running on OSX");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("OpenTK running on X11");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
IntPtr widgetWindowHandle = this.Window.Handle;
|
|
||||||
#else
|
|
||||||
IntPtr widgetWindowHandle = this.GdkWindow.Handle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// IWindowInfo
|
|
||||||
if (Configuration.RunningOnWindows)
|
|
||||||
{
|
|
||||||
_WindowInfo = WinWindowsInfoInitializer.Initialize(widgetWindowHandle);
|
|
||||||
}
|
|
||||||
else if (Configuration.RunningOnMacOS)
|
|
||||||
{
|
|
||||||
_WindowInfo = OSXWindowInfoInitializer.Initialize(widgetWindowHandle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_WindowInfo = XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GraphicsContext
|
|
||||||
_GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
|
|
||||||
_GraphicsContext.MakeCurrent(_WindowInfo);
|
|
||||||
|
|
||||||
if (GraphicsContext.ShareContexts)
|
if (GraphicsContext.ShareContexts)
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref _GraphicsContextCount);
|
Interlocked.Increment(ref _GraphicsContextCount);
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.OSX
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the OSX platform for both GTK2 and
|
|
||||||
/// GTK3.
|
|
||||||
/// </summary>
|
|
||||||
public static class OSXWindowInfoInitializer
|
|
||||||
{
|
|
||||||
#if GTK3
|
|
||||||
private const string OSXLibGdkName = "libgdk-3.dylib";
|
|
||||||
#else
|
|
||||||
const string OSXLibGdkName = "libgdk-quartz-2.0.0.dylib";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the OSX platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
public static IWindowInfo Initialize(IntPtr gdkWindowHandle)
|
|
||||||
{
|
|
||||||
IntPtr windowHandle = gdk_quartz_window_get_nswindow(gdkWindowHandle);
|
|
||||||
IntPtr viewHandle = gdk_quartz_window_get_nsview(gdkWindowHandle);
|
|
||||||
|
|
||||||
return Utilities.CreateMacOSWindowInfo(windowHandle, viewHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_quartz_window_get_nswindow(IntPtr handle);
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_quartz_window_get_nsview(IntPtr handle);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,7 +42,7 @@
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<LangVersion>6</LangVersion>
|
<LangVersion>7</LangVersion>
|
||||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||||
<CodeAnalysisRuleSet>..\..\stylecop.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>..\..\stylecop.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -98,13 +98,10 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="OSX\OSXWindowInfoInitializer.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="GLWidget.cs" />
|
<Compile Include="GLWidget.cs" />
|
||||||
<Compile Include="Win\WinWindowsInfoInitializer.cs" />
|
|
||||||
<Compile Include="X11\XWindowInfoInitializer.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="paket.references" />
|
<None Include="paket.references" />
|
||||||
|
@ -120,8 +117,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Choose>
|
<Choose>
|
||||||
<When
|
<When Condition="($(DefineConstants.Contains('GTK3')) And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.0.3' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7'))">
|
||||||
Condition="($(DefineConstants.Contains('GTK3')) And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.0.3' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7'))">
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="cairo-sharp">
|
<Reference Include="cairo-sharp">
|
||||||
<HintPath>..\..\packages\gtk-sharp3\lib\net40\cairo-sharp.dll</HintPath>
|
<HintPath>..\..\packages\gtk-sharp3\lib\net40\cairo-sharp.dll</HintPath>
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
|
|
||||||
namespace OpenTK.Win
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the Windows platform for both GTK2 and
|
|
||||||
/// GTK3.
|
|
||||||
/// </summary>
|
|
||||||
public static class WinWindowsInfoInitializer
|
|
||||||
{
|
|
||||||
#if GTK3
|
|
||||||
private const string WinLibGDKName = "libgdk-3-0.dll";
|
|
||||||
#else
|
|
||||||
private const string WinLibGDKName = "libgdk-win32-2.0-0.dll";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the Windows platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
public static IWindowInfo Initialize(IntPtr gdkWindowHandle)
|
|
||||||
{
|
|
||||||
#if GTK3
|
|
||||||
IntPtr windowHandle = gdk_win32_window_get_handle(gdkWindowHandle);
|
|
||||||
#else
|
|
||||||
IntPtr windowHandle = gdk_win32_drawable_get_handle(gdkWindowHandle);
|
|
||||||
#endif
|
|
||||||
return Utilities.CreateWindowsWindowInfo(windowHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
private static extern IntPtr gdk_win32_window_get_handle(IntPtr w);
|
|
||||||
#else
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
static extern IntPtr gdk_win32_drawable_get_handle(IntPtr d);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,175 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Security;
|
|
||||||
using OpenTK.Graphics;
|
|
||||||
using OpenTK.Platform;
|
|
||||||
using OpenTK.Platform.X11;
|
|
||||||
|
|
||||||
namespace OpenTK.X11
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Handler class for initializing <see cref="IWindowInfo"/> objects under the X11 platform for both GTK2 and GTK3.
|
|
||||||
/// </summary>
|
|
||||||
public static class XWindowInfoInitializer
|
|
||||||
{
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
private const string UnixLibGdkName = "libgdk-3.so.0";
|
|
||||||
#else
|
|
||||||
const string UnixLibGdkName = "libgdk-x11-2.0.so.0";
|
|
||||||
#endif
|
|
||||||
private const string UnixLibX11Name = "libX11.so.6";
|
|
||||||
private const string UnixLibGLName = "libGL.so.1";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes an <see cref="IWindowInfo"/> under the X11 platform.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mode"></param>
|
|
||||||
/// <param name="displayHandle"></param>
|
|
||||||
/// <param name="screenNumber"></param>
|
|
||||||
/// <param name="gdkWindowHandle"></param>
|
|
||||||
/// <param name="gdkRootWindowHandle"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IWindowInfo Initialize(GraphicsMode mode, IntPtr displayHandle, int screenNumber, IntPtr gdkWindowHandle, IntPtr gdkRootWindowHandle)
|
|
||||||
{
|
|
||||||
IntPtr display = gdk_x11_display_get_xdisplay(displayHandle);
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
IntPtr windowXid = gdk_x11_window_get_xid(gdkWindowHandle);
|
|
||||||
IntPtr rootWindowXid = gdk_x11_window_get_xid(gdkRootWindowHandle);
|
|
||||||
#else
|
|
||||||
IntPtr windowXid = gdk_x11_drawable_get_xid(gdkWindowHandle);
|
|
||||||
IntPtr rootWindowXid = gdk_x11_drawable_get_xid(gdkRootWindowHandle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IntPtr visualInfo;
|
|
||||||
if (mode.Index.HasValue)
|
|
||||||
{
|
|
||||||
XVisualInfo info = new XVisualInfo
|
|
||||||
{
|
|
||||||
VisualID = mode.Index.Value
|
|
||||||
};
|
|
||||||
|
|
||||||
int dummy;
|
|
||||||
visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
visualInfo = GetVisualInfo(mode, display, screenNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, visualInfo);
|
|
||||||
XFree(visualInfo);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntPtr XGetVisualInfo(IntPtr display, XVisualInfoMask infoMask, ref XVisualInfo template, out int nitems)
|
|
||||||
{
|
|
||||||
return XGetVisualInfoInternal(display, (IntPtr)(int)infoMask, ref template, out nitems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntPtr GetVisualInfo(GraphicsMode mode, IntPtr display, int screenNumber)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int[] attributes = CreateAttributeList(mode).ToArray();
|
|
||||||
return glXChooseVisual(display, screenNumber, attributes);
|
|
||||||
}
|
|
||||||
catch (DllNotFoundException e)
|
|
||||||
{
|
|
||||||
throw new DllNotFoundException("OpenGL dll not found!", e);
|
|
||||||
}
|
|
||||||
catch (EntryPointNotFoundException enf)
|
|
||||||
{
|
|
||||||
throw new EntryPointNotFoundException("Glx entry point not found!", enf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<int> CreateAttributeList(GraphicsMode mode)
|
|
||||||
{
|
|
||||||
List<int> attributeList = new List<int>(24);
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.RGBA);
|
|
||||||
|
|
||||||
if (mode.Buffers > 1)
|
|
||||||
{
|
|
||||||
attributeList.Add((int)GLXAttribute.DOUBLEBUFFER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.Stereo)
|
|
||||||
{
|
|
||||||
attributeList.Add((int)GLXAttribute.STEREO);
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.RED_SIZE);
|
|
||||||
attributeList.Add(mode.ColorFormat.Red / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.GREEN_SIZE);
|
|
||||||
attributeList.Add(mode.ColorFormat.Green / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.BLUE_SIZE);
|
|
||||||
attributeList.Add(mode.ColorFormat.Blue / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.ALPHA_SIZE);
|
|
||||||
attributeList.Add(mode.ColorFormat.Alpha / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.DEPTH_SIZE);
|
|
||||||
attributeList.Add(mode.Depth);
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.STENCIL_SIZE);
|
|
||||||
attributeList.Add(mode.Stencil);
|
|
||||||
|
|
||||||
//attributeList.Add(GLX_AUX_BUFFERS);
|
|
||||||
//attributeList.Add(Buffers);
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.ACCUM_RED_SIZE);
|
|
||||||
attributeList.Add(mode.AccumulatorFormat.Red / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.ACCUM_GREEN_SIZE);
|
|
||||||
attributeList.Add(mode.AccumulatorFormat.Green / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.ACCUM_BLUE_SIZE);
|
|
||||||
attributeList.Add(mode.AccumulatorFormat.Blue / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.ACCUM_ALPHA_SIZE);
|
|
||||||
attributeList.Add(mode.AccumulatorFormat.Alpha / 4); // TODO support 16-bit
|
|
||||||
|
|
||||||
attributeList.Add((int)GLXAttribute.NONE);
|
|
||||||
|
|
||||||
return attributeList;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(UnixLibX11Name, EntryPoint = "XGetVisualInfo")]
|
|
||||||
private static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr infoMask, ref XVisualInfo template, out int nitems);
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibX11Name)]
|
|
||||||
private static extern void XFree(IntPtr handle);
|
|
||||||
|
|
||||||
#if GTK3
|
|
||||||
/// <summary> Returns the X resource (window or pixmap) belonging to a GdkWindow. </summary>
|
|
||||||
/// <remarks> XID gdk_x11_window_get_xid(GdkWindow *drawable); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The ID of window's X resource. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkDisplay);
|
|
||||||
#else
|
|
||||||
/// <summary> Returns the X resource (window or pixmap) belonging to a GdkDrawable. </summary>
|
|
||||||
/// <remarks> XID gdk_x11_drawable_get_xid(GdkDrawable *drawable); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The ID of drawable's X resource. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
static extern IntPtr gdk_x11_drawable_get_xid(IntPtr gdkDisplay);
|
|
||||||
#endif
|
|
||||||
/// <summary> Returns the X display of a GdkDisplay. </summary>
|
|
||||||
/// <remarks> Display* gdk_x11_display_get_xdisplay(GdkDisplay *display); </remarks>
|
|
||||||
/// <param name="gdkDisplay"> The GdkDrawable. </param>
|
|
||||||
/// <returns> The X Display of the GdkDisplay. </returns>
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)]
|
|
||||||
private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay);
|
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity, DllImport(UnixLibGLName)]
|
|
||||||
private static extern IntPtr glXChooseVisual(IntPtr display, int screen, int[] attr);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
// <auto-generated/>
|
// <auto-generated/>
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: AssemblyTitleAttribute("OpenTK")]
|
[assembly: AssemblyTitleAttribute("OpenTK")]
|
||||||
[assembly: AssemblyProductAttribute("OpenTK")]
|
[assembly: AssemblyProductAttribute("OpenTK")]
|
||||||
|
@ -9,6 +10,7 @@ using System.Reflection;
|
||||||
[assembly: AssemblyFileVersionAttribute("3.0.0")]
|
[assembly: AssemblyFileVersionAttribute("3.0.0")]
|
||||||
[assembly: CLSCompliantAttribute(true)]
|
[assembly: CLSCompliantAttribute(true)]
|
||||||
[assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library.")]
|
[assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library.")]
|
||||||
|
[assembly: InternalsVisibleToAttribute("OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8")]
|
||||||
namespace System {
|
namespace System {
|
||||||
internal static class AssemblyVersionInformation {
|
internal static class AssemblyVersionInformation {
|
||||||
internal const System.String AssemblyTitle = "OpenTK";
|
internal const System.String AssemblyTitle = "OpenTK";
|
||||||
|
@ -18,5 +20,6 @@ namespace System {
|
||||||
internal const System.String AssemblyFileVersion = "3.0.0";
|
internal const System.String AssemblyFileVersion = "3.0.0";
|
||||||
internal const System.Boolean CLSCompliant = true;
|
internal const System.Boolean CLSCompliant = true;
|
||||||
internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library.";
|
internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library.";
|
||||||
|
internal const System.String InternalsVisibleTo = "OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue