mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-22 20:45:38 +00:00
Merge pull request #652 from Nihlus/glwidget-glarea
Base GLWidget on GLArea instead of DrawingArea
This commit is contained in:
commit
870f1abf8e
|
@ -1,3 +1,4 @@
|
|||
image: Visual Studio 2017
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
build_script:
|
||||
|
|
|
@ -105,7 +105,8 @@ Target "AssemblyInfo" (fun _ ->
|
|||
Attribute.Version release.AssemblyVersion
|
||||
Attribute.FileVersion release.AssemblyVersion
|
||||
Attribute.CLSCompliant true
|
||||
Attribute.Copyright copyright ]
|
||||
Attribute.Copyright copyright
|
||||
]
|
||||
|
||||
let getProjectDetails projectPath =
|
||||
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Gdk;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
|
||||
using Gtk;
|
||||
using OpenTK.OSX;
|
||||
using OpenTK.Win;
|
||||
using OpenTK.X11;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
|
@ -17,66 +12,28 @@ namespace OpenTK
|
|||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
[ToolboxItem(true)]
|
||||
public class GLWidget: DrawingArea
|
||||
public class GLWidget : GLArea
|
||||
{
|
||||
|
||||
private static int _GraphicsContextCount;
|
||||
private static bool _SharedContextInitialized = false;
|
||||
|
||||
private IGraphicsContext _GraphicsContext;
|
||||
private IWindowInfo _WindowInfo;
|
||||
private bool _Initialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Use a single buffer versus a double buffer.
|
||||
/// The previous frame time reported by GTK.
|
||||
/// </summary>
|
||||
[Browsable(true)]
|
||||
public bool SingleBuffer { get; set; }
|
||||
private double? _PreviousFrameTime;
|
||||
|
||||
/// <summary>
|
||||
/// Color Buffer Bits-Per-Pixel
|
||||
/// Gets the time taken to render the last frame (in seconds).
|
||||
/// </summary>
|
||||
public int ColorBPP { get; set; }
|
||||
public double DeltaTime { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Accumulation Buffer Bits-Per-Pixel
|
||||
/// The set <see cref="ContextFlags"/> for this widget.
|
||||
/// </summary>
|
||||
public int AccumulatorBPP { get; set; }
|
||||
|
||||
/// <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; }
|
||||
public GraphicsContextFlags ContextFlags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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="glVersionMajor">The major 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"/>.
|
||||
/// </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;
|
||||
ColorBPP = graphicsMode.ColorFormat.BitsPerPixel;
|
||||
AccumulatorBPP = graphicsMode.AccumulatorFormat.BitsPerPixel;
|
||||
DepthBPP = graphicsMode.Depth;
|
||||
StencilBPP = graphicsMode.Stencil;
|
||||
Samples = graphicsMode.Samples;
|
||||
Stereo = graphicsMode.Stereo;
|
||||
AddTickCallback(UpdateFrameTime);
|
||||
SetRequiredVersion(glVersionMajor, glVersionMinor);
|
||||
|
||||
GlVersionMajor = glVersionMajor;
|
||||
GlVersionMinor = glVersionMinor;
|
||||
GraphicsContextFlags = graphicsContextFlags;
|
||||
if (graphicsMode.Depth > 0)
|
||||
{
|
||||
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>
|
||||
|
@ -137,39 +141,15 @@ namespace OpenTK
|
|||
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>
|
||||
/// Disposes the current object, releasing any native resources it was using.
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
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)
|
||||
{
|
||||
_GraphicsContext.MakeCurrent(_WindowInfo);
|
||||
MakeCurrent();
|
||||
OnShuttingDown();
|
||||
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>
|
||||
/// Called when this <see cref="GLWidget"/> is being disposed.
|
||||
/// </summary>
|
||||
|
@ -263,62 +227,19 @@ namespace OpenTK
|
|||
}
|
||||
}
|
||||
|
||||
#if GTK3
|
||||
/// <summary>
|
||||
/// Called when the widget needs to be (fully or partially) redrawn.
|
||||
/// </summary>
|
||||
/// <param name="cr"></param>
|
||||
/// <returns></returns>
|
||||
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)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
_GraphicsContext.MakeCurrent(_WindowInfo);
|
||||
}
|
||||
|
||||
#if GTK3
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -329,66 +250,17 @@ namespace OpenTK
|
|||
{
|
||||
_Initialized = true;
|
||||
|
||||
// If this looks uninitialized... initialize.
|
||||
if (ColorBPP == 0)
|
||||
// Make the GDK GL context current
|
||||
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;
|
||||
|
||||
if (DepthBPP == 0)
|
||||
{
|
||||
DepthBPP = 16;
|
||||
}
|
||||
_GraphicsContext.ErrorChecking = true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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>
|
||||
<TargetFrameworkProfile />
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>6</LangVersion>
|
||||
<LangVersion>7</LangVersion>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
<CodeAnalysisRuleSet>..\..\stylecop.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
|
@ -98,13 +98,10 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OSX\OSXWindowInfoInitializer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="GLWidget.cs" />
|
||||
<Compile Include="Win\WinWindowsInfoInitializer.cs" />
|
||||
<Compile Include="X11\XWindowInfoInitializer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="paket.references" />
|
||||
|
@ -120,8 +117,7 @@
|
|||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Choose>
|
||||
<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'))">
|
||||
<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'))">
|
||||
<ItemGroup>
|
||||
<Reference Include="cairo-sharp">
|
||||
<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/>
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: AssemblyTitleAttribute("OpenTK")]
|
||||
[assembly: AssemblyProductAttribute("OpenTK")]
|
||||
|
@ -9,6 +10,7 @@ using System.Reflection;
|
|||
[assembly: AssemblyFileVersionAttribute("3.0.0")]
|
||||
[assembly: CLSCompliantAttribute(true)]
|
||||
[assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos <stapostol@gmail.com> for the Open Toolkit library.")]
|
||||
[assembly: InternalsVisibleToAttribute("OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8")]
|
||||
namespace System {
|
||||
internal static class AssemblyVersionInformation {
|
||||
internal const System.String AssemblyTitle = "OpenTK";
|
||||
|
@ -18,5 +20,6 @@ namespace System {
|
|||
internal const System.String AssemblyFileVersion = "3.0.0";
|
||||
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 InternalsVisibleTo = "OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue