mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-05 11:38:21 +00:00
Merge branch 'sdl2' of https://github.com/thefiddler/opentk
Conflicts: Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
This commit is contained in:
commit
be7200d37e
|
@ -38,6 +38,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
class Sdl2NativeWindow : INativeWindow, IInputDriver
|
class Sdl2NativeWindow : INativeWindow, IInputDriver
|
||||||
{
|
{
|
||||||
|
readonly object sync = new object();
|
||||||
|
|
||||||
Sdl2WindowInfo window;
|
Sdl2WindowInfo window;
|
||||||
uint window_id;
|
uint window_id;
|
||||||
bool is_visible;
|
bool is_visible;
|
||||||
|
@ -65,6 +67,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public Sdl2NativeWindow(int x, int y, int width, int height,
|
public Sdl2NativeWindow(int x, int y, int width, int height,
|
||||||
string title, GameWindowFlags options, DisplayDevice device)
|
string title, GameWindowFlags options, DisplayDevice device)
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
{
|
{
|
||||||
var bounds = device.Bounds;
|
var bounds = device.Bounds;
|
||||||
var flags = TranslateFlags(options);
|
var flags = TranslateFlags(options);
|
||||||
|
@ -80,31 +84,29 @@ namespace OpenTK.Platform.SDL2
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
||||||
|
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
|
||||||
|
SDL.SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
window = new Sdl2WindowInfo(handle, null);
|
window = new Sdl2WindowInfo(handle, null);
|
||||||
window_id = SDL.SDL_GetWindowID(handle);
|
window_id = SDL.SDL_GetWindowID(handle);
|
||||||
windows.Add(window_id, this);
|
windows.Add(window_id, this);
|
||||||
window_title = title;
|
window_title = title;
|
||||||
|
|
||||||
keyboard.Description = "Standard Windows keyboard";
|
keyboard.Description = "Standard keyboard";
|
||||||
keyboard.NumberOfFunctionKeys = 12;
|
keyboard.NumberOfFunctionKeys = 12;
|
||||||
keyboard.NumberOfKeys = 101;
|
keyboard.NumberOfKeys = 101;
|
||||||
keyboard.NumberOfLeds = 3;
|
keyboard.NumberOfLeds = 3;
|
||||||
|
|
||||||
mouse.Description = "Standard Windows mouse";
|
mouse.Description = "Standard mouse";
|
||||||
mouse.NumberOfButtons = 3;
|
mouse.NumberOfButtons = 3;
|
||||||
mouse.NumberOfWheels = 1;
|
mouse.NumberOfWheels = 1;
|
||||||
|
|
||||||
keyboards.Add(keyboard);
|
keyboards.Add(keyboard);
|
||||||
mice.Add(mouse);
|
mice.Add(mouse);
|
||||||
|
|
||||||
lock (SDL.Sync)
|
|
||||||
{
|
|
||||||
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Private Members
|
#region Private Members
|
||||||
|
|
||||||
|
@ -142,7 +144,6 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
Sdl2NativeWindow window = null;
|
Sdl2NativeWindow window = null;
|
||||||
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
||||||
|
|
||||||
|
@ -191,12 +192,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL.SDL_EventType.SDL_QUIT:
|
case SDL.SDL_EventType.SDL_QUIT:
|
||||||
/*
|
Debug.WriteLine("Sdl2 application quit");
|
||||||
if (windows.TryGetValue(ev.quit.windowID, out window))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +267,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
if (!close_args.Cancel)
|
if (!close_args.Cancel)
|
||||||
{
|
{
|
||||||
window.Closed(window, EventArgs.Empty);
|
window.Closed(window, EventArgs.Empty);
|
||||||
window.DestroyWindow();
|
//window.DestroyWindow();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -347,12 +343,12 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
SDL.SDL_DestroyWindow(window.Handle);
|
|
||||||
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
|
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
|
||||||
if (windows.ContainsKey(window_id))
|
if (windows.ContainsKey(window_id))
|
||||||
{
|
{
|
||||||
windows.Remove(window_id);
|
windows.Remove(window_id);
|
||||||
}
|
}
|
||||||
|
SDL.SDL_DestroyWindow(window.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,12 +422,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
{
|
{
|
||||||
if (Exists)
|
if (Exists)
|
||||||
{
|
{
|
||||||
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
||||||
|
|
||||||
SDL.SDL_Event e = new SDL.SDL_Event();
|
SDL.SDL_Event e = new SDL.SDL_Event();
|
||||||
//e.type = SDL.SDL_EventType.SDL_QUIT;
|
|
||||||
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
|
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
|
||||||
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
|
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
|
||||||
e.window.windowID = window_id;
|
e.window.windowID = window_id;
|
||||||
|
@ -441,12 +439,13 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ProcessEvents()
|
public void ProcessEvents()
|
||||||
{
|
{
|
||||||
if (Exists)
|
lock (sync)
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_PumpEvents();
|
SDL.SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
|
@ -474,6 +473,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
// Set the new icon, if any, or clear the current
|
// Set the new icon, if any, or clear the current
|
||||||
// icon if null
|
// icon if null
|
||||||
|
@ -510,19 +513,34 @@ namespace OpenTK.Platform.SDL2
|
||||||
IconChanged(this, EventArgs.Empty);
|
IconChanged(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
return SDL.SDL_GetWindowTitle(window.Handle);
|
return SDL.SDL_GetWindowTitle(window.Handle);
|
||||||
}
|
}
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowTitle(window.Handle, value);
|
SDL.SDL_SetWindowTitle(window.Handle, value);
|
||||||
window_title = value;
|
window_title = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Focused
|
public bool Focused
|
||||||
{
|
{
|
||||||
|
@ -539,6 +557,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
return is_visible;
|
return is_visible;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
SDL.SDL_ShowWindow(window.Handle);
|
SDL.SDL_ShowWindow(window.Handle);
|
||||||
|
@ -546,6 +568,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
SDL.SDL_HideWindow(window.Handle);
|
SDL.SDL_HideWindow(window.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Exists
|
public bool Exists
|
||||||
{
|
{
|
||||||
|
@ -571,11 +595,12 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (WindowState == value)
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
|
if (WindowState != value)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the new WindowState
|
// Set the new WindowState
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
|
@ -613,6 +638,9 @@ namespace OpenTK.Platform.SDL2
|
||||||
GrabCursor(true);
|
GrabCursor(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public WindowBorder WindowBorder
|
public WindowBorder WindowBorder
|
||||||
{
|
{
|
||||||
|
@ -622,8 +650,13 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != WindowBorder)
|
if (WindowBorder != value)
|
||||||
{
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case WindowBorder.Resizable:
|
case WindowBorder.Resizable:
|
||||||
|
@ -640,11 +673,16 @@ namespace OpenTK.Platform.SDL2
|
||||||
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
|
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
WindowBorderChanged(this, EventArgs.Empty);
|
WindowBorderChanged(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Rectangle Bounds
|
public Rectangle Bounds
|
||||||
{
|
{
|
||||||
|
@ -662,30 +700,56 @@ namespace OpenTK.Platform.SDL2
|
||||||
public Point Location
|
public Point Location
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
|
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
|
||||||
return new Point(x, y);
|
return new Point(x, y);
|
||||||
}
|
}
|
||||||
|
return new Point();
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
|
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Size Size
|
public Size Size
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
||||||
return new Size(w, h);
|
return new Size(w, h);
|
||||||
}
|
}
|
||||||
|
return new Size();
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
|
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
|
@ -778,11 +842,17 @@ namespace OpenTK.Platform.SDL2
|
||||||
return is_cursor_visible;
|
return is_cursor_visible;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
GrabCursor(!value);
|
GrabCursor(!value);
|
||||||
is_cursor_visible = value;
|
is_cursor_visible = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -790,7 +860,6 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public void Poll()
|
public void Poll()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -840,11 +909,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
Debug.Print("Disposing {0}", GetType());
|
Debug.Print("Disposing {0}", GetType());
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
if (Exists)
|
if (Exists)
|
||||||
{
|
{
|
||||||
DestroyWindow();
|
DestroyWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");
|
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");
|
||||||
|
|
|
@ -64,7 +64,14 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
lock (LoadLock)
|
lock (LoadLock)
|
||||||
{
|
{
|
||||||
if (!wgl_loaded)
|
// On intel drivers, wgl entry points appear to change
|
||||||
|
// when creating multiple contexts. As a workaround,
|
||||||
|
// we reload Wgl entry points every time we create a
|
||||||
|
// new context - this solves the issue without any apparent
|
||||||
|
// side-effects (i.e. the old contexts can still be handled
|
||||||
|
// using the new entry points.)
|
||||||
|
// Sigh...
|
||||||
|
// if (!wgl_loaded)
|
||||||
{
|
{
|
||||||
// We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3).
|
// We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3).
|
||||||
// We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll().
|
// We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll().
|
||||||
|
|
Loading…
Reference in a new issue