fix opengl on glx, cleanup

This commit is contained in:
Emmanuel 2020-09-11 10:26:07 +00:00
parent 79133f4812
commit c35e98f984
22 changed files with 83 additions and 4197 deletions

View File

@ -198,10 +198,7 @@ namespace OpenTK
private static void OnGraphicsContextInitialized()
{
if (GraphicsContextInitialized != null)
{
GraphicsContextInitialized(null, EventArgs.Empty);
}
GraphicsContextInitialized?.Invoke(null, EventArgs.Empty);
}
// Called when the first GraphicsContext is being destroyed in the case of GraphicsContext.ShareContexts == True;
@ -209,10 +206,7 @@ namespace OpenTK
private static void OnGraphicsContextShuttingDown()
{
if (GraphicsContextShuttingDown != null)
{
GraphicsContextShuttingDown(null, EventArgs.Empty);
}
GraphicsContextShuttingDown?.Invoke(null, EventArgs.Empty);
}
// Called when this GLWidget has a valid GraphicsContext
@ -220,10 +214,7 @@ namespace OpenTK
protected virtual void OnInitialized()
{
if (Initialized != null)
{
Initialized(this, EventArgs.Empty);
}
Initialized?.Invoke(this, EventArgs.Empty);
}
// Called when this GLWidget needs to render a frame

View File

@ -9,7 +9,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56"/>
<PackageReference Include="OpenGL.Net" Version="0.8.4"/>
<PackageReference Include="OpenTK.Graphics" Version="4.0.0-pre9.4"/>
<PackageReference Include="OpenTK.Windowing.Common" Version="4.0.0-pre9.4"/>
<PackageReference Include="System.Drawing.Common" Version="4.7.0"/>

View File

@ -115,11 +115,6 @@ namespace OpenTK
LoadBindings("OpenGL4");
}
private static IntPtr GetProcAddressWgl(string function)
{
return UnsafeNativeMethods.wglGetProcAddress(function);
}
private static void LoadLibraries()
{
if (Loaded)
@ -142,30 +137,6 @@ namespace OpenTK
Loaded = true;
}
public static IntPtr GetWindowHandle(IntPtr handle)
{
if(CurrentPlatform == OSPlatform.Windows)
{
return UnsafeNativeMethods.gdk_win32_window_get_handle(handle);
}
else
{
return UnsafeNativeMethods.gdk_x11_window_get_xid(handle);
}
}
public static IntPtr GetDisplayHandle(IntPtr handle)
{
if (CurrentPlatform == OSPlatform.Windows)
{
return IntPtr.Zero;
}
else
{
return UnsafeNativeMethods.gdk_x11_display_get_xdisplay(handle);
}
}
internal static IntPtr GetLibraryHandle(string libraryPath, bool throws)
{
IntPtr libraryHandle;
@ -205,44 +176,8 @@ namespace OpenTK
return symbol;
}
public static void InitXThreads()
{
if (_threadsInitialized)
{
return;
}
if (CurrentPlatform == OSPlatform.Linux)
{
_threadsInitialized = true;
UnsafeNativeMethods.XInitThreads();
}
}
internal static class UnsafeNativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr handle, string funcname);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr LoadLibrary(string dllName);
[DllImport(WglLibrary, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr wglGetProcAddress(string lpszProc);
[DllImport(WglLibrary, EntryPoint = "wglGetCurrentContext")]
public extern static IntPtr wglGetCurrentContext();
[DllImport(WglLibrary, EntryPoint = "wglGetCurrentDC")]
public static extern IntPtr wglGetCurrentDC();
[DllImport(WglLibrary, EntryPoint = "wglSwapBuffers", ExactSpelling = true)]
public static extern bool wglSwapBuffers(IntPtr hdc);
[DllImport("opengl32.dll", SetLastError = true, EntryPoint = "wglMakeCurrent")]
public static extern bool WglMakeCurrent(IntPtr hdc, IntPtr hglrc);
[DllImport(OSXLibrary, EntryPoint = "NSIsSymbolNameDefined")]
public static extern bool NSIsSymbolNameDefined(string s);
@ -251,41 +186,6 @@ namespace OpenTK
[DllImport(OSXLibrary, EntryPoint = "NSAddressOfSymbol")]
public static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
[DllImport("libX11.so.6")]
public extern static int XInitThreads();
[DllImport(OSXLibrary)]
public extern static int CGLSetCurrentContext(IntPtr ctx);
[DllImport(OSXLibrary)]
public extern static IntPtr CGLGetCurrentContext();
[DllImport(OSXLibrary)]
public extern static void CGLReleaseContext(IntPtr ctx);
[DllImport(OSXLibrary)]
public extern static int CGLFlushDrawable(IntPtr ctx);
[DllImport(OSXLibrary)]
internal static extern int CGLDestroyContext(IntPtr ctx);
[DllImport(OSXLibrary)]
internal static extern int CGLSetParameter(IntPtr ctx, int parameter, ref int value);
[DllImport(GlxLibrary, EntryPoint = "glXGetCurrentContext")]
public static extern IntPtr glXGetCurrentContext();
[DllImport(GlxLibrary, EntryPoint = "glXGetProcAddress")]
public static extern IntPtr glXGetProcAddress();
[DllImport(GlxLibrary, EntryPoint = "glXSwapIntervalEXT")]
public static extern IntPtr glXSwapIntervalEXT(int interval);
[DllImport(GlxLibrary, EntryPoint = "glXMakeCurrent")]
public static extern bool glXMakeCurrent(IntPtr display, IntPtr drawable, IntPtr context);
[DllImport(GlxLibrary, EntryPoint = "glXSwapBuffers")]
public static extern void glXSwapBuffers(IntPtr display, IntPtr drawable);
public const int RTLD_LAZY = 1;
public const int RTLD_NOW = 2;
@ -298,17 +198,6 @@ namespace OpenTK
[DllImport("dl")]
public static extern string dlerror();
public const string GdkNativeDll = "libgdk-3-0.dll";
[DllImport(GdkNativeDll, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr gdk_win32_window_get_handle(IntPtr raw);
[DllImport("libgdk-3.so.0", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr raw);
[DllImport("libgdk-3.so.0", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr gdk_x11_window_get_xid(IntPtr raw);
}
private static class Delegates

View File

@ -1,204 +0,0 @@
using System;
using System.Runtime.InteropServices;
using OpenGL;
using static OpenTK.GTKBindingHelper;
namespace OpenTK
{
public interface ILegacyGraphicsContext
{
void MakeCurrent();
void SwapBuffers();
void ClearCurrent();
void SwapInterval(int interval);
}
public abstract class LegacyGraphicsContext : ILegacyGraphicsContext
{
public static IntPtr Display{ get; set; }
public abstract void MakeCurrent();
public abstract void SwapBuffers();
public static void InitializeDefaults(IntPtr handle)
{
if (CurrentPlatform == OSPlatform.Windows)
{
IntPtr deviceContext = Wgl.GetDC(UnsafeNativeMethods.gdk_win32_window_get_handle(handle));
Wgl.PIXELFORMATDESCRIPTOR pfd = new Wgl.PIXELFORMATDESCRIPTOR(24);
pfd.dwFlags |= Wgl.PixelFormatDescriptorFlags.DepthDontCare | Wgl.PixelFormatDescriptorFlags.DoublebufferDontCare | Wgl.PixelFormatDescriptorFlags.StereoDontCare;
int pFormat = Wgl.ChoosePixelFormat(deviceContext, ref pfd);
bool res = Wgl.DescribePixelFormat(deviceContext, pFormat, (uint)pfd.nSize, ref pfd) != 0;
res = Wgl.SetPixelFormat(deviceContext, pFormat, ref pfd);
}
}
public static ILegacyGraphicsContext GetCurrentContext(IntPtr handle)
{
var currentPlatform = CurrentPlatform;
if(currentPlatform == OSPlatform.Windows){
return WglGraphicsContext.GetCurrent(handle);
}
else if(currentPlatform == OSPlatform.Linux){
if (Display == null || Display == IntPtr.Zero)
{
throw new InvalidOperationException("No Display set");
}
return GlxGraphicsContext.GetCurrent(handle, Display);
}
else if (currentPlatform == OSPlatform.OSX)
{
return CglGraphicsContext.GetCurrent();
}
return null;
}
public abstract void ClearCurrent();
public abstract void SwapInterval(int interval);
}
public class WglGraphicsContext : LegacyGraphicsContext
{
private delegate int wglSwapIntervalExtDelegate(int interval);
private static wglSwapIntervalExtDelegate wglSwapIntervalExt = null;
private IntPtr _windowHandle;
private IntPtr _deviceContext;
public WglGraphicsContext(IntPtr deviceContext, IntPtr graphicsContext, IntPtr windowHandle = default)
{
_deviceContext = deviceContext;
_graphicsContext = graphicsContext;
_windowHandle = windowHandle;
IntPtr swapIntervalPointer = UnsafeNativeMethods.wglGetProcAddress("wglSwapIntervalEXT");
if(swapIntervalPointer != null && swapIntervalPointer != IntPtr.Zero)
{
wglSwapIntervalExt = (wglSwapIntervalExtDelegate)Marshal.GetDelegateForFunctionPointer(
swapIntervalPointer, typeof(wglSwapIntervalExtDelegate));
}
}
private IntPtr _graphicsContext;
public static WglGraphicsContext GetCurrent(IntPtr windowHandle)
{
IntPtr dc = UnsafeNativeMethods.wglGetCurrentDC();
IntPtr gc = UnsafeNativeMethods.wglGetCurrentContext();
return new WglGraphicsContext(dc, gc, windowHandle);
}
public override void MakeCurrent()
{
UnsafeNativeMethods.WglMakeCurrent(_deviceContext, _graphicsContext);
}
public override void SwapBuffers()
{
UnsafeNativeMethods.wglSwapBuffers(_deviceContext);
}
public override void ClearCurrent()
{
UnsafeNativeMethods.WglMakeCurrent(_deviceContext, IntPtr.Zero);
}
public override void SwapInterval(int interval)
{
wglSwapIntervalExt?.Invoke(interval);
}
}
public class GlxGraphicsContext : LegacyGraphicsContext
{
private IntPtr _windowHandle;
public static GlxGraphicsContext GetCurrent(IntPtr windowHandle, IntPtr display)
{
var gc = UnsafeNativeMethods.glXGetCurrentContext();
return new GlxGraphicsContext(windowHandle, gc, display);
}
public GlxGraphicsContext(IntPtr windowHandle, IntPtr graphicsContext, IntPtr display)
{
_windowHandle = UnsafeNativeMethods.gdk_x11_window_get_xid(windowHandle);
_display = UnsafeNativeMethods.gdk_x11_display_get_xdisplay(display);
_graphicsContext = graphicsContext;
}
private IntPtr _graphicsContext;
private IntPtr _display;
public override void MakeCurrent()
{
UnsafeNativeMethods.glXMakeCurrent(_display, _windowHandle, _graphicsContext);
}
public override void SwapBuffers()
{
UnsafeNativeMethods.glXSwapBuffers(_display, _windowHandle);
}
public override void ClearCurrent()
{
UnsafeNativeMethods.glXMakeCurrent(_display, _windowHandle, IntPtr.Zero);
}
public override void SwapInterval(int interval)
{
UnsafeNativeMethods.glXSwapIntervalEXT(interval);
}
}
public class CglGraphicsContext : LegacyGraphicsContext
{
private IntPtr _windowHandle;
public static CglGraphicsContext GetCurrent()
{
var gc = UnsafeNativeMethods.CGLGetCurrentContext();
return new CglGraphicsContext(gc);
}
public CglGraphicsContext(IntPtr graphicsContext)
{
_graphicsContext = graphicsContext;
}
private IntPtr _graphicsContext;
private IntPtr _display;
public override void MakeCurrent()
{
UnsafeNativeMethods.CGLSetCurrentContext(_graphicsContext);
}
public override void SwapBuffers()
{
UnsafeNativeMethods.CGLFlushDrawable(_graphicsContext);
}
public override void ClearCurrent()
{
UnsafeNativeMethods.CGLSetCurrentContext(IntPtr.Zero);
}
public override void SwapInterval(int interval)
{
UnsafeNativeMethods.CGLSetParameter(_graphicsContext, 222 , ref interval);
}
}
}

View File

@ -178,7 +178,7 @@ namespace OpenTK
}
catch (OutOfMemoryException)
{
for (i = i - 1; i >= 0; --i)
for (i -= 1; i >= 0; --i)
{
Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size));
}

View File

@ -181,80 +181,6 @@ namespace OpenTK
}
}
/// <summary>Changes the resolution of the DisplayDevice.</summary>
/// <param name="resolution">The resolution to set. <see cref="DisplayDevice.SelectResolution"/></param>
/// <exception cref="Graphics.GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
/// <remarks>If the specified resolution is null, this function will restore the original DisplayResolution.</remarks>
public void ChangeResolution(DisplayResolution resolution)
{
if (resolution == null)
{
this.RestoreResolution();
}
if (resolution == current_resolution)
{
return;
}
//effect.FadeOut();
if (implementation.TryChangeResolution(this, resolution))
{
if (OriginalResolution == null)
{
OriginalResolution = current_resolution;
}
current_resolution = resolution;
}
else
{
throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.",
this, resolution));
}
//effect.FadeIn();
}
/// <summary>Changes the resolution of the DisplayDevice.</summary>
/// <param name="width">The new width of the DisplayDevice.</param>
/// <param name="height">The new height of the DisplayDevice.</param>
/// <param name="bitsPerPixel">The new bits per pixel of the DisplayDevice.</param>
/// <param name="refreshRate">The new refresh rate of the DisplayDevice.</param>
/// <exception cref="Graphics.GraphicsModeException">Thrown if the requested resolution could not be set.</exception>
public void ChangeResolution(int width, int height, int bitsPerPixel, float refreshRate)
{
this.ChangeResolution(this.SelectResolution(width, height, bitsPerPixel, refreshRate));
}
/// <summary>Restores the original resolution of the DisplayDevice.</summary>
/// <exception cref="Graphics.GraphicsModeException">Thrown if the original resolution could not be restored.</exception>
public void RestoreResolution()
{
if (OriginalResolution != null)
{
//effect.FadeOut();
if (implementation.TryRestoreResolution(this))
{
current_resolution = OriginalResolution;
OriginalResolution = null;
}
else
{
throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this));
}
//effect.FadeIn();
}
}
/// <summary>Gets the default (primary) display of this system.</summary>
public static DisplayDevice Default
{
get { return implementation.GetDisplay(DisplayIndex.Primary); }
}
/// <summary>
/// Gets the <see cref="DisplayDevice"/> for the specified <see cref="DisplayIndex"/>.
/// </summary>
@ -270,22 +196,6 @@ namespace OpenTK
/// </summary>
internal DisplayResolution OriginalResolution { get; set; }
internal static DisplayDevice FromPoint(int x, int y)
{
for (DisplayIndex i = DisplayIndex.First; i < DisplayIndex.Sixth; i++)
{
DisplayDevice display = DisplayDevice.GetDisplay(i);
if (display != null)
{
if (display.Bounds.Contains(x, y))
{
return display;
}
}
}
return null;
}
private DisplayResolution FindResolution(int width, int height, int bitsPerPixel, float refreshRate)
{
return available_resolutions.Find(delegate(DisplayResolution test)
@ -308,138 +218,5 @@ namespace OpenTK
Bounds.ToString(), available_resolutions.Count);
}
///// <summary>Determines whether the specified DisplayDevices are equal.</summary>
///// <param name="obj">The System.Object to check against.</param>
///// <returns>True if the System.Object is an equal DisplayDevice; false otherwise.</returns>
//public override bool Equals(object obj)
//{
// if (obj is DisplayDevice)
// {
// DisplayDevice dev = (DisplayDevice)obj;
// return
// IsPrimary == dev.IsPrimary &&
// current_resolution == dev.current_resolution &&
// available_resolutions.Count == dev.available_resolutions.Count;
// }
// return false;
//}
///// <summary>Returns a unique hash representing this DisplayDevice.</summary>
///// <returns>A System.Int32 that may serve as a hash code for this DisplayDevice.</returns>
////public override int GetHashCode()
//{
// return current_resolution.GetHashCode() ^ IsPrimary.GetHashCode() ^ available_resolutions.Count;
//}
}
#if false
class FadeEffect : IDisposable
{
List<Form> forms = new List<Form>();
double opacity_step = 0.04;
int sleep_step;
internal FadeEffect()
{
foreach (Screen s in Screen.AllScreens)
{
Form form = new Form();
form.ShowInTaskbar = false;
form.StartPosition = FormStartPosition.Manual;
form.WindowState = FormWindowState.Maximized;
form.FormBorderStyle = FormBorderStyle.None;
form.TopMost = true;
form.BackColor = System.Drawing.Color.Black;
forms.Add(form);
}
sleep_step = 10 / forms.Count;
MoveToStartPositions();
}
void MoveToStartPositions()
{
int count = 0;
foreach (Screen s in Screen.AllScreens)
{
// forms[count++].Location = new System.Drawing.Point(s.Bounds.X, s.Bounds.Y);
//forms[count].Size = new System.Drawing.Size(4096, 4096);
count++;
}
}
bool FadedOut
{
get
{
bool ready = true;
foreach (Form form in forms)
ready = ready && form.Opacity >= 1.0;
return ready;
}
}
bool FadedIn
{
get
{
bool ready = true;
foreach (Form form in forms)
ready = ready && form.Opacity <= 0.0;
return ready;
}
}
internal void FadeOut()
{
MoveToStartPositions();
foreach (Form form in forms)
{
form.Opacity = 0.0;
form.Visible = true;
}
while (!FadedOut)
{
foreach (Form form in forms)
{
form.Opacity += opacity_step;
form.Refresh();
}
Thread.Sleep(sleep_step);
}
}
internal void FadeIn()
{
MoveToStartPositions();
foreach (Form form in forms)
form.Opacity = 1.0;
while (!FadedIn)
{
foreach (Form form in forms)
{
form.Opacity -= opacity_step;
form.Refresh();
}
Thread.Sleep(sleep_step);
}
foreach (Form form in forms)
form.Visible = false;
}
public void Dispose()
{
foreach (Form form in forms)
form.Dispose();
}
}
#endif
}

View File

@ -38,9 +38,6 @@ namespace OpenTK.Platform
protected readonly List<DisplayDevice> AvailableDevices = new List<DisplayDevice>();
protected DisplayDevice Primary;
public abstract bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
public abstract bool TryRestoreResolution(DisplayDevice device);
// Gets the DisplayDevice that corresponds to the specified index.
public virtual DisplayDevice GetDisplay(DisplayIndex index)
{

View File

@ -27,8 +27,6 @@ namespace OpenTK.Platform
{
internal interface IDisplayDeviceDriver
{
bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution);
bool TryRestoreResolution(DisplayDevice device);
DisplayDevice GetDisplay(DisplayIndex displayIndex);
}
}

View File

@ -380,34 +380,6 @@ namespace OpenTK.Platform.Linux
}
return null;
}
public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
{
unsafe
{
LinuxDisplay display = (LinuxDisplay)device.Id;
ModeInfo* mode = GetModeInfo(display, resolution);
int connector_id = display.pConnector->connector_id;
if (mode != null)
{
return Drm.ModeSetCrtc(FD, display.Id, 0, 0, 0,
&connector_id, 1, mode) == 0;
}
return false;
}
}
public override bool TryRestoreResolution(DisplayDevice device)
{
unsafe
{
LinuxDisplay display = (LinuxDisplay)device.Id;
ModeInfo mode = display.OriginalMode;
int connector_id = display.pConnector->connector_id;
return Drm.ModeSetCrtc(FD, display.Id, 0, 0, 0,
&connector_id, 1, &mode) == 0;
}
}
}
}

View File

@ -140,70 +140,5 @@ namespace OpenTK.Platform.MacOS
}
}
static internal IntPtr HandleTo(DisplayDevice displayDevice)
{
return (IntPtr)displayDevice.Id;
}
private Dictionary<IntPtr, IntPtr> storedModes = new Dictionary<IntPtr, IntPtr>();
private List<IntPtr> displaysCaptured = new List<IntPtr>();
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
{
IntPtr display = HandleTo(device);
IntPtr currentModePtr = CG.DisplayCurrentMode(display);
if (storedModes.ContainsKey(display) == false)
{
storedModes.Add(display, currentModePtr);
}
IntPtr displayModesPtr = CG.DisplayAvailableModes(display);
CFArray displayModes = new CFArray(displayModesPtr);
for (int j = 0; j < displayModes.Count; j++)
{
CFDictionary dict = new CFDictionary(displayModes[j]);
int width = (int)dict.GetNumberValue("Width");
int height = (int)dict.GetNumberValue("Height");
int bpp = (int)dict.GetNumberValue("BitsPerPixel");
double freq = dict.GetNumberValue("RefreshRate");
if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
{
// if (displaysCaptured.Contains(display) == false)
// {
// CG.DisplayCapture(display);
// }
Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);
CG.DisplaySwitchToMode(display, displayModes[j]);
return true;
}
}
return false;
}
public sealed override bool TryRestoreResolution(DisplayDevice device)
{
IntPtr display = HandleTo(device);
if (storedModes.ContainsKey(display))
{
Debug.Print("Restoring resolution.");
CG.DisplaySwitchToMode(display, storedModes[display]);
//CG.DisplayRelease(display);
displaysCaptured.Remove(display);
return true;
}
return false;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -61,6 +61,50 @@ namespace OpenTK.Platform.Windows
EntryPoints = new IntPtr[EntryPointNames.Length];
}
public delegate IntPtr CreateContextAttribsARBDelegate(IntPtr hDC, IntPtr shareHGLRC, int[] attribs);
public static CreateContextAttribsARBDelegate wglCreateContextAttribs;
public delegate bool SwapIntervalEXT(int interval);
public static SwapIntervalEXT wglSwapIntervalEXT;
public delegate int GetSwapIntervalEXT();
public static GetSwapIntervalEXT wglGetSwapIntervalEXT;
internal delegate IntPtr GetExtensionsStringARBDelegate(IntPtr hdc);
internal static GetExtensionsStringARBDelegate wglGetExtensionsStringARB;
internal delegate IntPtr GetExtensionsStringEXTDelegate();
internal static GetExtensionsStringEXTDelegate wglGetExtensionsStringEXT;
public delegate bool ChoosePixelFormatARB(IntPtr hdc, int[] piAttribIList, float[] pfAttribFList, uint nMaxFormats, int[] piFormats, ref uint nNumFormats);
public static ChoosePixelFormatARB wglChoosePixelFormatARB;
public delegate bool GetPixelFormatAttribivARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, uint nAttributes, int[] piAttributes, int[] piValues);
public static GetPixelFormatAttribivARB WglGetPixelFormatAttribivARB;
public static string GetExtensionsStringARB(IntPtr hdc)
{
unsafe
{
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(wglGetExtensionsStringARB(hdc));
}
}
public static string GetExtensionsStringEXT()
{
unsafe
{
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(wglGetExtensionsStringEXT());
}
}
public static TDelegate GetProcAddress<TDelegate>(string name) where TDelegate : class
{
IntPtr addr = GetProcAddress(name);
if (addr == IntPtr.Zero) return null;
return (TDelegate)(object)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(addr, typeof(TDelegate));
}
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglCreateContext", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr CreateContext(IntPtr hDc);
@ -74,12 +118,6 @@ namespace OpenTK.Platform.Windows
[DllImport(Wgl.Library, EntryPoint = "wglMakeCurrent", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean MakeCurrent(IntPtr hDc, IntPtr newContext);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglChoosePixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglDescribePixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglGetCurrentDC", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr GetCurrentDC();
[SuppressUnmanagedCodeSecurity]
@ -89,71 +127,7 @@ namespace OpenTK.Platform.Windows
[DllImport(Wgl.Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)]
internal extern static IntPtr GetProcAddress(IntPtr lpszProc);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglGetPixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static int GetPixelFormat(IntPtr hdc);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglSetPixelFormat", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglSwapBuffers", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean SwapBuffers(IntPtr hdc);
[SuppressUnmanagedCodeSecurity]
[DllImport(Wgl.Library, EntryPoint = "wglShareLists", ExactSpelling = true, SetLastError = true)]
internal extern static Boolean ShareLists(IntPtr hrcSrvShare, IntPtr hrcSrvSource);
[Slot(0)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern IntPtr wglCreateContextAttribsARB(IntPtr hDC, IntPtr hShareContext, int* attribList);
[Slot(1)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern IntPtr wglGetExtensionsStringARB(IntPtr hdc);
[Slot(2)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern Boolean wglGetPixelFormatAttribivARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, int* piAttributes, [Out] int* piValues);
[Slot(3)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern Boolean wglGetPixelFormatAttribfvARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, int* piAttributes, [Out] Single* pfValues);
[Slot(4)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern Boolean wglChoosePixelFormatARB(IntPtr hdc, int* piAttribIList, Single* pfAttribFList, UInt32 nMaxFormats, [Out] int* piFormats, [Out] UInt32* nNumFormats);
[Slot(5)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern Boolean wglMakeContextCurrentARB(IntPtr hDrawDC, IntPtr hReadDC, IntPtr hglrc);
[Slot(6)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern IntPtr wglGetCurrentReadDCARB();
[Slot(7)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern IntPtr wglCreatePbufferARB(IntPtr hDC, int iPixelFormat, int iWidth, int iHeight, int* piAttribList);
[Slot(8)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern IntPtr wglGetPbufferDCARB(IntPtr hPbuffer);
[Slot(9)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern int wglReleasePbufferDCARB(IntPtr hPbuffer, IntPtr hDC);
[Slot(10)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern Boolean wglDestroyPbufferARB(IntPtr hPbuffer);
[Slot(11)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern Boolean wglQueryPbufferARB(IntPtr hPbuffer, int iAttribute, [Out] int* piValue);
[Slot(12)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern Boolean wglBindTexImageARB(IntPtr hPbuffer, int iBuffer);
[Slot(13)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern Boolean wglReleaseTexImageARB(IntPtr hPbuffer, int iBuffer);
[Slot(14)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal unsafe static extern Boolean wglSetPbufferAttribARB(IntPtr hPbuffer, int* piAttribList);
[Slot(15)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern IntPtr wglGetExtensionsStringEXT();
[Slot(16)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern Boolean wglSwapIntervalEXT(int interval);
[Slot(17)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
internal static extern int wglGetSwapIntervalEXT();
}
}

View File

@ -51,8 +51,8 @@ namespace OpenTK.Platform.Windows
bool get_arb = SupportsFunction("wglGetExtensionsStringARB");
bool get_ext = SupportsFunction("wglGetExtensionsStringEXT");
string str =
get_arb ? OpenGL.Wgl.GetExtensionsStringARB(dc) :
get_ext ? OpenGL.Wgl.GetExtensionsStringEXT():
get_arb ? Wgl.GetExtensionsStringARB(dc) :
get_ext ? Wgl.GetExtensionsStringEXT():
String.Empty;
if (!String.IsNullOrEmpty(str))
@ -123,6 +123,14 @@ namespace OpenTK.Platform.Windows
EntryPoints[i] = GetAddress(EntryPointNames[i]);
}
extensions.Clear();
wglSwapIntervalEXT = GetProcAddress<SwapIntervalEXT>("wglSwapIntervalEXT");
wglGetSwapIntervalEXT = GetProcAddress<GetSwapIntervalEXT>("wglGetSwapIntervalEXT");
wglGetExtensionsStringARB = GetProcAddress<GetExtensionsStringARBDelegate>("wglGetExtensionsStringARB");
wglGetExtensionsStringEXT = GetProcAddress<GetExtensionsStringEXTDelegate>("wglGetExtensionsStringEXT");
wglCreateContextAttribs = GetProcAddress<CreateContextAttribsARBDelegate>("wglCreateContextAttribsARB");
wglChoosePixelFormatARB = GetProcAddress<ChoosePixelFormatARB>("wglChoosePixelFormatARB");
WglGetPixelFormatAttribivARB = GetProcAddress<GetPixelFormatAttribivARB>("wglGetPixelFormatAttribivARB");
}
}
}

View File

@ -41,33 +41,6 @@ namespace OpenTK.Platform.Windows
HandleDisplaySettingsChanged;
}
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
{
DeviceMode mode = null;
if (resolution != null)
{
mode = new DeviceMode();
mode.PelsWidth = resolution.Width;
mode.PelsHeight = resolution.Height;
mode.BitsPerPel = resolution.BitsPerPixel;
mode.DisplayFrequency = (int)resolution.RefreshRate;
mode.Fields = Constants.DM_BITSPERPEL
| Constants.DM_PELSWIDTH
| Constants.DM_PELSHEIGHT
| Constants.DM_DISPLAYFREQUENCY;
}
return Constants.DISP_CHANGE_SUCCESSFUL ==
Functions.ChangeDisplaySettingsEx((string)device.Id, mode, IntPtr.Zero,
ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero);
}
public sealed override bool TryRestoreResolution(DisplayDevice device)
{
return TryChangeResolution(device, null);
}
public void RefreshDisplayDevices()
{
lock (display_lock)

View File

@ -160,7 +160,7 @@ namespace OpenTK.Platform.Windows
attributes.Add(0);
Handle = new ContextHandle(
OpenGL.Wgl.CreateContextAttribsARB(
Wgl.wglCreateContextAttribs(
window.DeviceContext,
sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero,
attributes.ToArray()));
@ -304,7 +304,7 @@ namespace OpenTK.Platform.Windows
{
if (vsync_supported)
{
return OpenGL.Wgl.GetSwapIntervalEXT();
return Wgl.wglGetSwapIntervalEXT();
}
else
{
@ -322,7 +322,7 @@ namespace OpenTK.Platform.Windows
{
value = 1;
}
if (!OpenGL.Wgl.SwapIntervalEXT(value))
if (!Wgl.wglSwapIntervalEXT(value))
{
Debug.Print("wglSwapIntervalEXT call failed.");
}

View File

@ -184,10 +184,10 @@ namespace OpenTK.Platform.Windows
attributes.Add(0);
attributes.Add(0);
uint[] count = new uint[attributes.Count];
uint count = (uint)attributes.Count;
if (OpenGL.Wgl.ChoosePixelFormatARB(device, attributes.ToArray(), null, (uint)format.Length, format, count)
&& count.Length > 0)
if (Wgl.wglChoosePixelFormatARB(device, attributes.ToArray(), null, (uint)format.Length, format, ref count)
&& count > 0)
{
created_mode = DescribePixelFormatARB(device, format[0]);
retry = false;
@ -377,7 +377,7 @@ namespace OpenTK.Platform.Windows
int[] values = new int[attribs.Length];
// Get the format attributes for this pixel format
if (!OpenGL.Wgl.GetPixelFormatAttribARB(device, pixelformat, 0, (uint)attribs.Length - 1, attribs, values))
if (!Wgl.WglGetPixelFormatAttribivARB(device, pixelformat, 0, (uint)attribs.Length - 1, attribs, values))
{
Debug.Print("[Warning] Failed to detect attributes for PixelFormat: {0}.", pixelformat);
}

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@
using System;
using System.Runtime.InteropServices;
using OpenTK.Core.Native;
#pragma warning disable 1591
@ -140,19 +139,6 @@ namespace OpenTK.Platform.X11
HYPERPIPE_PIXEL_AVERAGE_SGIX = 0x00000004,
}
internal enum GLXStringName : int
{
EXTENSIONS = 0x3,
VERSION = 0x2,
VENDOR = 0x1,
}
internal enum GLXEventMask : int
{
PBUFFER_CLOBBER_MASK = 0x08000000,
BUFFER_CLOBBER_MASK_SGIX = 0x08000000,
}
internal enum GLXRenderTypeMask : int
{
COLOR_INDEX_BIT_SGIX = 0x00000002,
@ -162,67 +148,6 @@ namespace OpenTK.Platform.X11
COLOR_INDEX_BIT = 0x00000002,
}
internal enum GLXHyperpipeTypeMask : int
{
HYPERPIPE_RENDER_PIPE_SGIX = 0x00000002,
HYPERPIPE_DISPLAY_PIPE_SGIX = 0x00000001,
}
internal enum GLXPbufferClobberMask : int
{
ACCUM_BUFFER_BIT_SGIX = 0x00000080,
FRONT_LEFT_BUFFER_BIT = 0x00000001,
BACK_RIGHT_BUFFER_BIT = 0x00000008,
FRONT_RIGHT_BUFFER_BIT_SGIX = 0x00000002,
STENCIL_BUFFER_BIT_SGIX = 0x00000040,
SAMPLE_BUFFERS_BIT_SGIX = 0x00000100,
STENCIL_BUFFER_BIT = 0x00000040,
BACK_RIGHT_BUFFER_BIT_SGIX = 0x00000008,
BACK_LEFT_BUFFER_BIT_SGIX = 0x00000004,
AUX_BUFFERS_BIT = 0x00000010,
DEPTH_BUFFER_BIT_SGIX = 0x00000020,
ACCUM_BUFFER_BIT = 0x00000080,
AUX_BUFFERS_BIT_SGIX = 0x00000010,
DEPTH_BUFFER_BIT = 0x00000020,
FRONT_LEFT_BUFFER_BIT_SGIX = 0x00000001,
BACK_LEFT_BUFFER_BIT = 0x00000004,
FRONT_RIGHT_BUFFER_BIT = 0x00000002,
}
internal enum GLXHyperpipeMisc : int
{
HYPERPIPE_PIPE_NAME_LENGTH_SGIX = 80,
}
internal enum GLXErrorCode : int
{
BAD_CONTEXT = 5,
NO_EXTENSION = 3,
BAD_HYPERPIPE_SGIX = 92,
BAD_ENUM = 7,
BAD_SCREEN = 1,
BAD_VALUE = 6,
BAD_ATTRIBUTE = 2,
BAD_VISUAL = 4,
BAD_HYPERPIPE_CONFIG_SGIX = 91,
}
internal enum GLXSyncType : int
{
SYNC_SWAP_SGIX = 0x00000001,
SYNC_FRAME_SGIX = 0x00000000,
}
internal enum GLXDrawableTypeMask : int
{
WINDOW_BIT = 0x00000001,
PIXMAP_BIT = 0x00000002,
PBUFFER_BIT_SGIX = 0x00000004,
PBUFFER_BIT = 0x00000004,
WINDOW_BIT_SGIX = 0x00000001,
PIXMAP_BIT_SGIX = 0x00000002,
}
internal enum ArbCreateContext : int
{
DebugBit = 0x0001,
@ -300,12 +225,6 @@ namespace OpenTK.Platform.X11
protected override object SyncRoot { get { return sync_root; } }
public override IntPtr GetAddress(string funcname)
{
byte[] procName = System.Text.Encoding.ASCII.GetBytes(funcname);
return OpenGL.Glx.GetProcAddressARB(procName);
}
internal override void LoadEntryPoints()
{
unsafe
@ -354,16 +273,6 @@ namespace OpenTK.Platform.X11
public delegate int SwapIntervalSGI(int interval);
public static SwapIntervalSGI glXSwapIntervalSGI;
internal static bool SupportsFunction(string name)
{
int index = Array.IndexOf(EntryPointNames, name);
if (index >= 0)
{
return EntryPoints[index] != IntPtr.Zero;
}
return false;
}
[DllImport(Library, EntryPoint = "glXIsDirect")]
public static extern bool IsDirect(IntPtr dpy, IntPtr context);
@ -424,9 +333,6 @@ namespace OpenTK.Platform.X11
[DllImport(Library, EntryPoint = "glXChooseVisual")]
public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, IntPtr attriblist);
[DllImport(Library, EntryPoint = "glXChooseVisual")]
public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, ref int attriblist);
public static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist)
{
unsafe

View File

@ -1,304 +0,0 @@
//
// Xkb.cs
//
// Author:
// Stefanos Apostolopoulos <stapostol@gmail.com>
//
// Copyright (c) 2006-2014
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
#pragma warning disable 0169
namespace OpenTK.Platform.X11
{
using Atom = IntPtr;
using KeyCode = Byte;
using XkbControlsPtr = IntPtr;
using XkbServerMapPtr = IntPtr;
using XkbClientMapPtr = IntPtr;
using XkbIndicatorPtr = IntPtr;
using XkbCompatMapPtr = IntPtr;
using XkbGeometryPtr = IntPtr;
internal class Xkb
{
private const string lib = "libX11";
internal const int KeyNameLength = 4;
internal const int NumModifiers = 8;
internal const int NumVirtualMods = 16;
internal const int NumIndicators = 32;
internal const int NumKbdGroups = 4;
internal const int UseCoreKeyboard = 0x0100;
[DllImport(lib, EntryPoint = "XkbFreeKeyboard")]
unsafe internal extern static void FreeKeyboard(XkbDesc* descr, int which, bool free);
[DllImport(lib, EntryPoint = "XkbAllocKeyboard")]
unsafe internal extern static XkbDesc* AllocKeyboard(IntPtr display);
[DllImport(lib, EntryPoint = "XkbGetKeyboard")]
internal extern static IntPtr GetKeyboard(IntPtr display, XkbKeyboardMask which, int device_id);
[DllImport(lib, EntryPoint = "XkbGetMap")]
internal extern static IntPtr GetMap(IntPtr display, XkbKeyboardMask which, int device_spec);
[DllImport(lib, EntryPoint = "XkbGetNames")]
unsafe internal extern static IntPtr GetNames(IntPtr display, XkbNamesMask which, XkbDesc* xkb);
[DllImport(lib, EntryPoint = "XkbKeycodeToKeysym")]
internal extern static XKey KeycodeToKeysym(IntPtr display, int keycode, int group, int level);
[DllImport(lib, EntryPoint = "XkbQueryExtension")]
internal extern static bool QueryExtension(IntPtr display, out int opcode_rtrn, out int event_rtrn,
out int error_rtrn, ref int major_in_out, ref int minor_in_out);
[DllImport(lib, EntryPoint = "XkbSetDetectableAutoRepeat")]
internal extern static bool SetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported);
internal static bool IsSupported(IntPtr display)
{
// The XkbQueryExtension manpage says that we cannot
// use XQueryExtension with XKB.
int opcode, error, ev;
int major = 1;
int minor = 0;
bool supported = QueryExtension(display, out opcode, out ev, out error, ref major, ref minor);
Debug.Print("XKB extension is {0}.", supported ? "supported" : "not supported");
if (supported)
{
Debug.Print("XKB version is {0}.{1}", major, minor);
}
return supported;
}
}
[Flags]
internal enum XkbKeyboardMask
{
Controls = 1 << 0,
ServerMap = 1 << 1,
IClientMap = 1 << 2,
IndicatorMap = 1 << 3,
Names = 1 << 4,
CompatibilityMap = 1 << 5,
Geometry = 1 << 6,
AllComponents = 1 << 7,
}
[Flags]
internal enum XkbNamesMask
{
Keycodes = 1 << 0,
Geometry = 1 << 1,
Symbols = 1 << 2,
PhysSymbols = 1 << 3,
Types = 1 << 4,
Compat = 1 << 5,
KeyType = 1 << 6,
KTLevel = 1 << 7,
Indicator = 1 << 8,
Key = 1 << 9,
KeyAliasesMask = 1 << 10,
VirtualMod = 1 << 11,
Group = 1 << 12,
RG = 1 << 13,
Component = 0x3f,
All = 0x3fff
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct XkbDesc
{
internal IntPtr dpy;
internal ushort flags;
internal ushort device_spec;
internal KeyCode min_key_code;
internal KeyCode max_key_code;
internal XkbControlsPtr ctrls;
internal XkbServerMapPtr server;
internal XkbClientMapPtr map;
internal XkbIndicatorPtr indicators;
internal XkbNames* names;
internal XkbCompatMapPtr compat;
internal XkbGeometryPtr geom;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct XkbKeyAlias
{
internal fixed byte real[Xkb.KeyNameLength];
internal fixed byte alias[Xkb.KeyNameLength];
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct XkbKeyName
{
internal fixed byte name[Xkb.KeyNameLength];
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct XkbNames
{
[StructLayout(LayoutKind.Sequential)]
internal struct Groups
{
private Atom groups0;
private Atom groups1;
private Atom groups2;
private Atom groups3;
internal Atom this[int i]
{
get
{
if (i < 0 || i > 3)
{
throw new IndexOutOfRangeException();
}
unsafe
{
fixed (Atom* ptr = &groups0)
{
return *(ptr + i);
}
}
}
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct Indicators
{
private Atom indicators0;
private Atom indicators1;
private Atom indicators2;
private Atom indicators3;
private Atom indicators4;
private Atom indicators5;
private Atom indicators6;
private Atom indicators7;
private Atom indicators8;
private Atom indicators9;
private Atom indicators10;
private Atom indicators11;
private Atom indicators12;
private Atom indicators13;
private Atom indicators14;
private Atom indicators15;
private Atom indicators16;
private Atom indicators17;
private Atom indicators18;
private Atom indicators19;
private Atom indicators20;
private Atom indicators21;
private Atom indicators22;
private Atom indicators23;
private Atom indicators24;
private Atom indicators25;
private Atom indicators26;
private Atom indicators27;
private Atom indicators28;
private Atom indicators29;
private Atom indicators30;
private Atom indicators31;
internal Atom this[int i]
{
get
{
if (i < 0 || i > 31)
{
throw new IndexOutOfRangeException();
}
unsafe
{
fixed (Atom* ptr = &indicators0)
{
return *(ptr + i);
} }
}
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct VMods
{
private Atom vmods0;
private Atom vmods1;
private Atom vmods2;
private Atom vmods3;
private Atom vmods4;
private Atom vmods5;
private Atom vmods6;
private Atom vmods7;
private Atom vmods8;
private Atom vmods9;
private Atom vmods10;
private Atom vmods11;
private Atom vmods12;
private Atom vmods13;
private Atom vmods14;
private Atom vmods15;
internal Atom this[int i]
{
get
{
if (i < 0 || i > 15)
{
throw new IndexOutOfRangeException();
}
unsafe
{
fixed (Atom* ptr = &vmods0)
{
return *(ptr + i);
}
}
}
}
}
internal Atom keycodes;
internal Atom geometry;
internal Atom symbols;
internal Atom types;
internal Atom compat;
internal VMods vmods;
internal Indicators indicators;
internal Groups groups;
internal XkbKeyName* keys;
internal XkbKeyAlias* key_aliases;
internal Atom *radio_groups;
internal Atom phys_symbols;
internal byte num_keys;
internal byte num_key_aliases;
internal byte num_rg;
}
}

View File

@ -61,7 +61,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XCreateWindow")]
public unsafe extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, IntPtr valuemask, XSetWindowAttributes* attributes);
[DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]//]
public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, UIntPtr border, UIntPtr background);
[DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]
public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, IntPtr border, IntPtr background);
@ -151,10 +151,10 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XRaiseWindow")]
public extern static int XRaiseWindow(IntPtr display, IntPtr window);
[DllImport("libX11", EntryPoint = "XLowerWindow")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XLowerWindow")]//]
public extern static uint XLowerWindow(IntPtr display, IntPtr window);
[DllImport("libX11", EntryPoint = "XConfigureWindow")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XConfigureWindow")]//]
public extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowAttributes value_mask, ref XWindowChanges values);
[DllImport("libX11", EntryPoint = "XInternAtom")]
@ -222,7 +222,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XGetGeometry")]
public extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, IntPtr x, IntPtr y, out int width, out int height, IntPtr border_width, IntPtr depth);
[DllImport("libX11", EntryPoint = "XWarpPointer")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XWarpPointer")]//]
public extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
[DllImport("libX11", EntryPoint = "XClearWindow")]
@ -241,7 +241,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XDefaultVisual")]
public extern static IntPtr XDefaultVisual(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XDefaultDepth")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XDefaultDepth")]//]
public extern static uint XDefaultDepth(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XDefaultScreen")]
@ -250,10 +250,10 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XDefaultColormap")]
public extern static IntPtr XDefaultColormap(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XLookupColor")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XLookupColor")]//]
public extern static int XLookupColor(IntPtr display, IntPtr Colormap, string Coloranem, ref XColor exact_def_color, ref XColor screen_def_color);
[DllImport("libX11", EntryPoint = "XAllocColor")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XAllocColor")]//]
public extern static int XAllocColor(IntPtr display, IntPtr Colormap, ref XColor colorcell_def);
[DllImport("libX11", EntryPoint = "XSetTransientForHint")]
@ -262,15 +262,15 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XChangeProperty")]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref MotifWmHints data, int nelements);
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref uint value, int nelements);
[DllImport("libX11", EntryPoint = "XChangeProperty")]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref int value, int nelements);
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref IntPtr value, int nelements);
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, uint[] data, int nelements);
[DllImport("libX11", EntryPoint = "XChangeProperty")]
@ -337,7 +337,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XCreateFontCursor")]
public extern static IntPtr XCreateFontCursor(IntPtr display, CursorFontShape shape);
[DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//]
public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot);
[DllImport("libX11", EntryPoint = "XCreatePixmapFromBitmapData")]
@ -409,12 +409,12 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XSetPlaneMask")]
public extern static int XSetPlaneMask(IntPtr display, IntPtr gc, IntPtr mask);
[DllImport("libX11", EntryPoint = "XSetForeground")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XSetForeground")]//]
public extern static int XSetForeground(IntPtr display, IntPtr gc, UIntPtr foreground);
[DllImport("libX11", EntryPoint = "XSetForeground")]
public extern static int XSetForeground(IntPtr display, IntPtr gc, IntPtr foreground);
[DllImport("libX11", EntryPoint = "XSetBackground")]//, CLSCompliant(false)]
[DllImport("libX11", EntryPoint = "XSetBackground")]//]
public extern static int XSetBackground(IntPtr display, IntPtr gc, UIntPtr background);
[DllImport("libX11", EntryPoint = "XSetBackground")]
public extern static int XSetBackground(IntPtr display, IntPtr gc, IntPtr background);

View File

@ -318,84 +318,7 @@ namespace OpenTK.Platform.X11
{
return (int)Functions.XDefaultDepth(API.DefaultDisplay, screen);
}
private bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution)
{
using (new XLock(API.DefaultDisplay))
{
int screen = deviceToScreen[device];
IntPtr root = Functions.XRootWindow(API.DefaultDisplay, screen);
IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, root);
ushort current_rotation;
int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation);
int new_resolution_index;
if (resolution != null)
{
new_resolution_index = screenResolutionToIndex[screen]
[new DisplayResolution(0, 0, resolution.Width, resolution.Height, resolution.BitsPerPixel, 0)];
}
else
{
new_resolution_index = deviceToDefaultResolution[device];
}
Debug.Print("Changing size of screen {0} from {1} to {2}",
screen, current_resolution_index, new_resolution_index);
int ret = 0;
short refresh_rate = (short)(resolution != null ? resolution.RefreshRate : 0);
if (refresh_rate > 0)
{
ret = Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay,
screen_config, root, new_resolution_index, current_rotation,
refresh_rate, IntPtr.Zero);
}
else
{
ret = Functions.XRRSetScreenConfig(API.DefaultDisplay,
screen_config, root, new_resolution_index, current_rotation,
IntPtr.Zero);
}
if (ret != 0)
{
Debug.Print("[Error] Change to resolution {0} failed with error {1}.",
resolution, (ErrorCode)ret);
}
return ret == 0;
}
}
private static bool ChangeResolutionXF86(DisplayDevice device, DisplayResolution resolution)
{
return false;
}
public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
{
// If resolution is null, restore the default resolution (new_resolution_index = 0).
if (xrandr_supported)
{
return ChangeResolutionXRandR(device, resolution);
}
else if (xf86_supported)
{
return ChangeResolutionXF86(device, resolution);
}
else
{
return false;
}
}
public sealed override bool TryRestoreResolution(DisplayDevice device)
{
return TryChangeResolution(device, null);
}
private static class NativeMethods
{
private const string Xinerama = "libXinerama";
@ -403,9 +326,6 @@ namespace OpenTK.Platform.X11
[DllImport(Xinerama)]
public static extern bool XineramaQueryExtension(IntPtr dpy, out int event_basep, out int error_basep);
[DllImport(Xinerama)]
public static extern int XineramaQueryVersion (IntPtr dpy, out int major_versionp, out int minor_versionp);
[DllImport(Xinerama)]
public static extern bool XineramaIsActive(IntPtr dpy);

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
@ -17,7 +17,6 @@
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56" />
<PackageReference Include="OpenTK" Version="4.0.0-pre9.4" />
<PackageReference Include="OpenGL.Net" Version="1.0.304" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="interfaces\MainWindow.glade" />