-
-
Notifications
You must be signed in to change notification settings - Fork 431
Silk extensions no longer work with 2.0 #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IWindow implements IView. The real problem is the extensions have not been updated to 2.0. There aren't any plans to do this today, but PRs welcome. |
I submitted a pull request. It only needed a few changes in order to work: UltzArchives/SilkExtensions#3 |
Nice, I had been trying to get this extension working with ImGui docking with the following: private readonly Platform_CreateWindow _createWindow;
private readonly Platform_DestroyWindow _destroyWindow;
private readonly Platform_GetWindowPos _getWindowPos;
private readonly Platform_ShowWindow _showWindow;
private readonly Platform_SetWindowPos _setWindowPos;
private readonly Platform_SetWindowSize _setWindowSize;
private readonly Platform_GetWindowSize _getWindowSize;
private readonly Platform_SetWindowFocus _setWindowFocus;
private readonly Platform_GetWindowFocus _getWindowFocus;
private readonly Platform_GetWindowMinimized _getWindowMinimized;
private readonly Platform_SetWindowTitle _setWindowTitle;
public ImGuiController(GL gl, IView view, IInputContext input)
{
Init(gl, view, input);
var io = ImGuiNET.ImGui.GetIO();
io.Fonts.AddFontDefault();
io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;
io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors;
io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos;
io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports;
io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports;
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
var platformIO = ImGuiNET.ImGui.GetPlatformIO();
var mainViewport = platformIO.MainViewport;
mainViewport.PlatformHandle = view.Handle;
var handle = GCHandle.Alloc(view);
view.Resize += (size) => mainViewport.PlatformRequestResize = true;
//view.Moved += p => mainViewport.PlatformRequestMove = true;
view.Closing += () => mainViewport.PlatformRequestClose = true;
mainViewport.PlatformUserData = (IntPtr)handle;
_createWindow = CreateWindow;
_destroyWindow = DestroyWindow;
_getWindowPos = GetWindowPos;
_showWindow = ShowWindow;
_setWindowPos = SetWindowPos;
_setWindowSize = SetWindowSize;
_getWindowSize = GetWindowSize;
_setWindowFocus = SetWindowFocus;
_getWindowFocus = GetWindowFocus;
_getWindowMinimized = GetWindowMinimized;
_setWindowTitle = SetWindowTitle;
platformIO.Platform_CreateWindow = Marshal.GetFunctionPointerForDelegate(_createWindow);
platformIO.Platform_DestroyWindow = Marshal.GetFunctionPointerForDelegate(_destroyWindow);
platformIO.Platform_ShowWindow = Marshal.GetFunctionPointerForDelegate(_showWindow);
platformIO.Platform_SetWindowPos = Marshal.GetFunctionPointerForDelegate(_setWindowPos);
platformIO.Platform_SetWindowSize = Marshal.GetFunctionPointerForDelegate(_setWindowSize);
platformIO.Platform_SetWindowFocus = Marshal.GetFunctionPointerForDelegate(_setWindowFocus);
platformIO.Platform_GetWindowFocus = Marshal.GetFunctionPointerForDelegate(_getWindowFocus);
platformIO.Platform_GetWindowMinimized = Marshal.GetFunctionPointerForDelegate(_getWindowMinimized);
platformIO.Platform_SetWindowTitle = Marshal.GetFunctionPointerForDelegate(_setWindowTitle);
ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowPos(platformIO.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowPos));
ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowSize(platformIO.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowSize));
CreateDeviceResources();
SetKeyMappings();
SetPerFrameImGuiData(1f / 60f);
BeginFrame();
}
private void CreateWindow(ImGuiViewportPtr vp)
{
// VeldridImGuiWindow window = new VeldridImGuiWindow(_gd, vp);
}
private void DestroyWindow(ImGuiViewportPtr vp)
{
// if (vp.PlatformUserData != IntPtr.Zero)
// {
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// window.Dispose();
// vp.PlatformUserData = IntPtr.Zero;
// }
}
private void ShowWindow(ImGuiViewportPtr vp)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// Sdl2Native.SDL_ShowWindow(window.Window.SdlWindowHandle);
}
private unsafe void GetWindowPos(ImGuiViewportPtr vp, Vector2* outPos)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// *outPos = new Vector2(window.Window.Bounds.X, window.Window.Bounds.Y);
}
private void SetWindowPos(ImGuiViewportPtr vp, Vector2 pos)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// window.Window.X = (int)pos.X;
// window.Window.Y = (int)pos.Y;
}
private void SetWindowSize(ImGuiViewportPtr vp, Vector2 size)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// Sdl2Native.SDL_SetWindowSize(window.Window.SdlWindowHandle, (int)size.X, (int)size.Y);
}
private unsafe void GetWindowSize(ImGuiViewportPtr vp, Vector2* outSize)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// Rectangle bounds = window.Window.Bounds;
// *outSize = new Vector2(bounds.Width, bounds.Height);
}
private void SetWindowFocus(ImGuiViewportPtr vp)
{
// if (p_sdl_RaiseWindow == null)
// {
// p_sdl_RaiseWindow = Sdl2Native.LoadFunction<SDL_RaiseWindow_t>("SDL_RaiseWindow");
// }
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// p_sdl_RaiseWindow(window.Window.SdlWindowHandle);
}
private byte GetWindowFocus(ImGuiViewportPtr vp)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// SDL_WindowFlags flags = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);
// return (flags & SDL_WindowFlags.InputFocus) != 0 ? (byte)1 : (byte)0;
}
private byte GetWindowMinimized(ImGuiViewportPtr vp)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// SDL_WindowFlags flags = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);
// return (flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0;
}
private unsafe void SetWindowTitle(ImGuiViewportPtr vp, IntPtr title)
{
// VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
// byte* titlePtr = (byte*)title;
// int count = 0;
// while (titlePtr[count] != 0)
// {
// titlePtr += 1;
// }
// window.Window.Title = System.Text.Encoding.ASCII.GetString(titlePtr, count);
} Based on: https://github.com/mellinoe/ImGui.NET/blob/docking/src/ImGui.NET.SampleProgram/ImGuiController.cs from the docking branch. The problem is I don't know how I would perform all the required operations on a windows using Silk as done in Veldrid via the marshalled delegates |
I had been using the ImGuiController included in the extensions repo, this doesn't work with 2.0 as IWindow is no longer an IView? Is there any chance this can be updated?
Also would be cool if you're planning to merge these extensions in the future to make it a little more generic as the current implementation will only work with OpenGL
The text was updated successfully, but these errors were encountered: