fix glx issues, 1.0.4-pre5

This commit is contained in:
Emmanuel 2020-09-22 09:54:00 +00:00
parent f04d3b0d46
commit abebaeb48e
11 changed files with 1614 additions and 85 deletions

View file

@ -118,8 +118,6 @@ namespace OpenTK
/// <summary>Constructs a new GLWidget</summary>
public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags graphicsContextFlags)
{
OpenTK.Toolkit.Init();
SingleBuffer = graphicsMode.Buffers == 1;
ColorBPP = graphicsMode.ColorFormat.BitsPerPixel;
AccumulatorBPP = graphicsMode.AccumulatorFormat.BitsPerPixel;

View file

@ -3,7 +3,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>GLWigdet for GTKSharp, using Opentk.</Description>
<Version>1.0.4-pre4</Version>
<Version>1.0.4-pre5</Version>
<RepositoryUrl>https://github.com/Ryujinx/GLWidget</RepositoryUrl>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -82,6 +82,9 @@ namespace OpenTK
// Try to load OpenTK.Graphics assembly.
Assembly assembly;
OpenTK.Toolkit.Init();
try
{
assembly = Assembly.Load("OpenTK.Graphics");

File diff suppressed because it is too large Load diff

View file

@ -139,6 +139,19 @@ 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,
@ -148,6 +161,67 @@ 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,
@ -359,5 +433,3 @@ namespace OpenTK.Platform.X11
public unsafe extern static IntPtr GetVisualFromFBConfig(IntPtr dpy, IntPtr fbconfig);
}
}
#pragma warning restore 1591

View file

@ -0,0 +1,304 @@
//
// 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

@ -5,8 +5,14 @@
*/
using System;
#if !MINIMAL
using System.Drawing;
#endif
#if ANDROID || IPHONE || MINIMAL
using OpenTK.Minimal;
#else
using System.Drawing.Imaging;
#endif
using System.Text;
using System.Runtime.InteropServices;
@ -61,7 +67,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")]//]
[DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]//, CLSCompliant(false)]
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 +157,10 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XRaiseWindow")]
public extern static int XRaiseWindow(IntPtr display, IntPtr window);
[DllImport("libX11", EntryPoint = "XLowerWindow")]//]
[DllImport("libX11", EntryPoint = "XLowerWindow")]//, CLSCompliant(false)]
public extern static uint XLowerWindow(IntPtr display, IntPtr window);
[DllImport("libX11", EntryPoint = "XConfigureWindow")]//]
[DllImport("libX11", EntryPoint = "XConfigureWindow")]//, CLSCompliant(false)]
public extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowAttributes value_mask, ref XWindowChanges values);
[DllImport("libX11", EntryPoint = "XInternAtom")]
@ -222,7 +228,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")]//]
[DllImport("libX11", EntryPoint = "XWarpPointer")]//, CLSCompliant(false)]
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 +247,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XDefaultVisual")]
public extern static IntPtr XDefaultVisual(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XDefaultDepth")]//]
[DllImport("libX11", EntryPoint = "XDefaultDepth")]//, CLSCompliant(false)]
public extern static uint XDefaultDepth(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XDefaultScreen")]
@ -250,10 +256,10 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XDefaultColormap")]
public extern static IntPtr XDefaultColormap(IntPtr display, int screen_number);
[DllImport("libX11", EntryPoint = "XLookupColor")]//]
[DllImport("libX11", EntryPoint = "XLookupColor")]//, CLSCompliant(false)]
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")]//]
[DllImport("libX11", EntryPoint = "XAllocColor")]//, CLSCompliant(false)]
public extern static int XAllocColor(IntPtr display, IntPtr Colormap, ref XColor colorcell_def);
[DllImport("libX11", EntryPoint = "XSetTransientForHint")]
@ -262,15 +268,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")]//]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
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")]//]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
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")]//]
[DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)]
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 +343,7 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XCreateFontCursor")]
public extern static IntPtr XCreateFontCursor(IntPtr display, CursorFontShape shape);
[DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//]
[DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//, CLSCompliant(false)]
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 +415,12 @@ namespace OpenTK.Platform.X11
[DllImport("libX11", EntryPoint = "XSetPlaneMask")]
public extern static int XSetPlaneMask(IntPtr display, IntPtr gc, IntPtr mask);
[DllImport("libX11", EntryPoint = "XSetForeground")]//]
[DllImport("libX11", EntryPoint = "XSetForeground")]//, CLSCompliant(false)]
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")]//]
[DllImport("libX11", EntryPoint = "XSetBackground")]//, CLSCompliant(false)]
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

@ -26,7 +26,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
#if !MINIMAL
using System.Drawing;
#endif
using System.Runtime.InteropServices;
namespace OpenTK.Platform.X11
@ -326,6 +328,9 @@ 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

@ -26,11 +26,11 @@
using System;
using System.Diagnostics;
using OpenTK.Graphics;
namespace OpenTK.Platform.X11
{
internal class X11Factory : PlatformFactoryBase
{
public X11Factory()
{
int result = Functions.XInitThreads();
@ -59,10 +59,5 @@ namespace OpenTK.Platform.X11
return new ContextHandle(Glx.GetCurrentContext());
};
}
protected override void Dispose(bool manual)
{
base.Dispose(manual);
}
}
}

View file

@ -184,13 +184,13 @@ namespace OpenTK.Platform.X11
using (new XLock(display))
{
fixed (int* attribs_ptr = attributes.ToArray())
fixed (int* attrib = attributes.ToArray())
{
context = Glx.pglXCreateContextAttribsARB(display, fbconfig, shareContext.Handle, direct, attribs_ptr);
context = Glx.pglXCreateContextAttribsARB(display, fbconfig, shareContext.Handle, direct, attrib);
if (context == IntPtr.Zero)
{
Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
context = Glx.pglXCreateContextAttribsARB(display, fbconfig, shareContext.Handle, !direct, attribs_ptr);
context = Glx.pglXCreateContextAttribsARB(display, fbconfig, shareContext.Handle, !direct, attrib);
}
}
}
@ -305,8 +305,6 @@ namespace OpenTK.Platform.X11
}
public override void MakeCurrent(IWindowInfo window)
{
using (new XLock(Display))
{
if (window == currentWindow && IsCurrent)
{
@ -363,7 +361,6 @@ namespace OpenTK.Platform.X11
currentWindow = (X11WindowInfo)window;
}
}
public override bool IsCurrent
{
@ -429,7 +426,7 @@ namespace OpenTK.Platform.X11
}
else if (vsync_sgi_supported)
{
error_code = (ErrorCode)Glx.glXSwapIntervalMESA((uint)value);
error_code = (ErrorCode)Glx.glXSwapIntervalSGI(value);
}
}
@ -465,7 +462,7 @@ namespace OpenTK.Platform.X11
Debug.Print("Context supports adaptive vsync: {0}.",
vsync_tear_supported);
GTKBindingHelper.InitializeGlBindings();
base.LoadAll();
}
public override IntPtr GetAddress(IntPtr function)

View file

@ -134,6 +134,8 @@ namespace GLWidgetTestGTK3
this.GLInit = false;
ResetCamera();
OpenTK.Toolkit.Init();
this.MainGLWidget = new GLWidget(GraphicsMode.Default)
{
CanFocus = true,