Example #1
0
        private unsafe void PlatformCreateWindow(ImGuiViewportPtr viewport)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            SDL_WindowFlags sdlFlags = (Sdl2Native.SDL_GetWindowFlags(mainWindow.SdlWindow.SdlWindowHandle) & SDL_WindowFlags.AllowHighDpi)
                                       | SDL_WindowFlags.Hidden;
            sdlFlags |= ((viewport.Flags & ImGuiViewportFlags.NoDecoration) != 0) ? SDL_WindowFlags.Borderless : SDL_WindowFlags.Resizable;

            if (graphicsDevice.BackendType == GraphicsBackend.OpenGL || graphicsDevice.BackendType == GraphicsBackend.OpenGLES)
            {
                sdlFlags |= SDL_WindowFlags.OpenGL;
            }
            if ((viewport.Flags & ImGuiViewportFlags.TopMost) != 0)
            {
                sdlFlags |= SDL_WindowFlags.AlwaysOnTop;
            }
            //Seems to work
            if ((viewport.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0)
            {
                sdlFlags |= SDL_WindowFlags.SkipTaskbar;
            }

            Sdl2Window sdlWindow = new Sdl2Window("Viewport", (int)viewport.Pos.X, (int)viewport.Pos.Y,
                                                  (int)viewport.Size.X, (int)viewport.Size.Y, sdlFlags, false);

            sdlWindow.Resized += () => viewport.PlatformRequestResize = true;
            sdlWindow.Moved   += (_) => viewport.PlatformRequestMove = true;
            sdlWindow.Closed  += () => viewport.PlatformRequestClose = true;

            WindowBase newWindow = WindowBase.CreateSubWindow(graphicsDevice, sdlWindow, mainWindow.GetType());

            viewport.PlatformUserData = (IntPtr)newWindow.GcHandle;
            viewport.PlatformHandle   = newWindow.SdlWindow.Handle;
        }
        /// <summary>
        /// Infinite While Loop to render the ImGui.
        /// </summary>
        private void WhileLoop()
        {
            while (window.Exists)
            {
                if (requireResize)
                {
                    Sdl2Native.SDL_SetWindowPosition(window.SdlWindowHandle, (int)futurePos.X, (int)futurePos.Y);
                    Sdl2Native.SDL_SetWindowSize(window.SdlWindowHandle, (int)futureSize.X, (int)futureSize.Y);
                    window.PumpEvents();
                    continue;
                }

                if (!window.Visible)
                {
                    window.PumpEvents();
                    Thread.Sleep(10);
                    continue;
                }

                if (!window.Exists)
                {
                    break;
                }

                imController.InitlizeFrame(1f / myFps);
                this.SubmitUI?.Invoke(this, new EventArgs());
                commandList.Begin();
                commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W));
                imController.Render(graphicsDevice, commandList);
                commandList.End();
                graphicsDevice.SubmitCommands(commandList);
                graphicsDevice.SwapBuffers(graphicsDevice.MainSwapchain);
            }
        }
Example #3
0
    public void PumpEvents(double deltaSeconds)
    {
        SetTitle();
        Sdl2Events.ProcessEvents();
        var snapshot = _window.PumpEvents();

        if (_window != null)
        {
            if (_pendingCursorUpdate.HasValue && _window.Focused)
            {
                using (PerfTracker.FrameEvent("3 Warping mouse"))
                {
                    Sdl2Native.SDL_WarpMouseInWindow(
                        _window.SdlWindowHandle,
                        (int)_pendingCursorUpdate.Value.X,
                        (int)_pendingCursorUpdate.Value.Y);

                    _pendingCursorUpdate = null;
                }
            }

            using (PerfTracker.FrameEvent("4 Raising input event"))
                Raise(new InputEvent(deltaSeconds, snapshot, _window.MouseDelta));
        }
    }
Example #4
0
        public static unsafe SwapchainSource GetSwapchainSource(Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            switch (sysWmInfo.subsystem)
            {
            case SysWMType.Windows:
                Win32WindowInfo w32Info = Unsafe.Read <Win32WindowInfo>(&sysWmInfo.info);
                return(SwapchainSource.CreateWin32(w32Info.Sdl2Window, w32Info.hinstance));

            case SysWMType.X11:
                X11WindowInfo x11Info = Unsafe.Read <X11WindowInfo>(&sysWmInfo.info);
                return(SwapchainSource.CreateXlib(
                           x11Info.display,
                           x11Info.Sdl2Window));

            case SysWMType.Cocoa:
                CocoaWindowInfo cocoaInfo = Unsafe.Read <CocoaWindowInfo>(&sysWmInfo.info);
                IntPtr          nsWindow  = cocoaInfo.Window;
                return(SwapchainSource.CreateNSWindow(nsWindow));

            default:
                throw new PlatformNotSupportedException("Cannot create a SwapchainSource for " + sysWmInfo.subsystem + ".");
            }
        }
Example #5
0
        private unsafe void RegisterInitialGamepads()
        {
            var numJoySticks = Sdl2Native.SDL_NumJoysticks();

            var numGameControllers = 0;

            for (var c = 0; c < numJoySticks; c++)
            {
                if (Sdl2Native.SDL_IsGameController(c))
                {
                    var index      = c;
                    var controller = Sdl2Native.SDL_GameControllerOpen(index);
                    var joystick   = Sdl2Native.SDL_GameControllerGetJoystick(controller);
                    var instanceId = index; //Sdl2Native.SDL_JoystickInstanceID(joystick);
                                            //How to check for controller NULL?
                    var name = Marshal.PtrToStringAnsi((IntPtr)Sdl2Native.SDL_GameControllerName(controller));
                    _frameworkMessenger.Report(string.Concat("Detected Controller name: ", name));

                    if (_controllers.ContainsKey(instanceId))
                    {
                        _frameworkMessenger.Report("Cannot add controller as instanceId already exists in dictionary, skipping...");
                        continue;
                    }

                    var gameController = new GameController(name, controller, joystick);
                    _controllers.Add(instanceId, gameController);

                    numGameControllers++;
                }
            }

            _frameworkMessenger.Report(string.Concat("Number of Joysticks detected: ", numJoySticks, " -> of those, number of GameControllers: ", numGameControllers));
        }
Example #6
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);
        }
Example #7
0
        private unsafe void UpdateMonitors()
        {
            if (p_sdl_GetNumVideoDisplays == null)
            {
                p_sdl_GetNumVideoDisplays = Sdl2Native.LoadFunction <SDL_GetNumVideoDisplays_t>("SDL_GetNumVideoDisplays");
            }
            if (p_sdl_GetDisplayUsableBounds_t == null)
            {
                p_sdl_GetDisplayUsableBounds_t = Sdl2Native.LoadFunction <SDL_GetDisplayUsableBounds_t>("SDL_GetDisplayUsableBounds");
            }

            ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();

            Marshal.FreeHGlobal(platformIO.NativePtr->Monitors.Data);
            int    numMonitors = p_sdl_GetNumVideoDisplays();
            IntPtr data        = Marshal.AllocHGlobal(Unsafe.SizeOf <ImGuiPlatformMonitor>() * numMonitors);

            platformIO.NativePtr->Monitors = new ImVector(numMonitors, numMonitors, data);
            for (int i = 0; i < numMonitors; i++)
            {
                Rectangle r;
                p_sdl_GetDisplayUsableBounds_t(i, &r);
                ImGuiPlatformMonitorPtr monitor = platformIO.Monitors[i];
                monitor.DpiScale = 1f;
                monitor.MainPos  = new Vector2(r.X, r.Y);
                monitor.MainSize = new Vector2(r.Width, r.Height);
                monitor.WorkPos  = new Vector2(r.X, r.Y);
                monitor.WorkSize = new Vector2(r.Width, r.Height);
            }
        }
Example #8
0
        private static unsafe GraphicsDevice CreateMetalGraphicsDevice(GraphicsDeviceOptions options, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            ref CocoaWindowInfo cocoaInfo = ref Unsafe.AsRef <CocoaWindowInfo>(&sysWmInfo.info);
Example #9
0
        public static unsafe void SetSDLGLContextAttributes(GraphicsDeviceOptions options, GraphicsBackend backend)
        {
            if (backend != GraphicsBackend.OpenGL && backend != GraphicsBackend.OpenGLES)
            {
                throw new VeldridException(
                          $"{nameof(backend)} must be {nameof(GraphicsBackend.OpenGL)} or {nameof(GraphicsBackend.OpenGLES)}.");
            }

            SDL_GLContextFlag contextFlags = options.Debug ? SDL_GLContextFlag.Debug | SDL_GLContextFlag.ForwardCompatible : SDL_GLContextFlag.ForwardCompatible;

            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.ContextFlags, (int)contextFlags);

            SetMaxGLVersion(backend == GraphicsBackend.OpenGLES);

            int depthBits   = 0;
            int stencilBits = 0;

            if (options.SwapchainDepthFormat.HasValue)
            {
                switch (options.SwapchainDepthFormat)
                {
                case PixelFormat.R16_UNorm:
                    depthBits = 16;
                    break;

                case PixelFormat.D24_UNorm_S8_UInt:
                    depthBits   = 24;
                    stencilBits = 8;
                    break;

                case PixelFormat.R32_Float:
                    depthBits = 32;
                    break;

                case PixelFormat.D32_Float_S8_UInt:
                    depthBits   = 32;
                    stencilBits = 8;
                    break;

                default:
                    throw new VeldridException("Invalid depth format: " + options.SwapchainDepthFormat.Value);
                }
            }

            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.DepthSize, depthBits);
            Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.StencilSize, stencilBits);

            if (options.SwapchainSrgbFormat)
            {
                Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.FramebufferSrgbCapable, 1);
            }
            else
            {
                Sdl2Native.SDL_GL_SetAttribute(SDL_GLAttribute.FramebufferSrgbCapable, 0);
            }
        }
Example #10
0
        static unsafe void Main(string[] args)
        {
            SDL_version version;

            Sdl2Native.SDL_GetVersion(&version);

            var app = new Lanegam();

            app.Run();
        }
Example #11
0
        private void SetWindowSize(ImGuiViewportPtr vp, Vector2 size)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            Sdl2Native.SDL_SetWindowSize(window.Window.SdlWindowHandle, (int)size.X, (int)size.Y);
        }
Example #12
0
        private void ShowWindow(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            Sdl2Native.SDL_ShowWindow(window.Window.SdlWindowHandle);
        }
Example #13
0
        public static unsafe GraphicsDevice CreateDefaultOpenGLGraphicsDevice(
            GraphicsDeviceOptions options,
            Sdl2Window window,
            GraphicsBackend backend)
        {
            Sdl2Native.SDL_ClearError();

            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(window.SdlWindowHandle, &sysWmInfo);

            SetSDLGLContextAttributes(options, backend);

            IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(window.SdlWindowHandle);
            byte * error         = Sdl2Native.SDL_GetError();

            if (error != null)
            {
                string errorString = GetString(error);
                if (!string.IsNullOrEmpty(errorString))
                {
                    throw new VeldridException(
                              $"Unable to create OpenGL Context: \"{errorString}\". This may indicate that the system does not support the requested OpenGL profile, version, or Swapchain format.");
                }
            }

            Sdl2Native.SDL_GL_SetSwapInterval(options.SyncToVerticalBlank ? 1 : 0);

            Veldrid.OpenGL.OpenGLPlatformInfo platformInfo = new Veldrid.OpenGL.OpenGLPlatformInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                context => Sdl2Native.SDL_GL_MakeCurrent(window.SdlWindowHandle, context),
                Sdl2Native.SDL_GL_GetCurrentContext,
                () => Sdl2Native.SDL_GL_MakeCurrent(new SDL_Window(IntPtr.Zero), IntPtr.Zero),
                Sdl2Native.SDL_GL_DeleteContext,
                () => Sdl2Native.SDL_GL_SwapWindow(window.SdlWindowHandle),
                sync => Sdl2Native.SDL_GL_SetSwapInterval(sync ? 1 : 0));

            Veldrid.OpenGLBinding.OpenGLNative.LoadGetString(Sdl2Native.SDL_GL_GetCurrentContext(), Sdl2Native.SDL_GL_GetProcAddress);
            byte *version  = Veldrid.OpenGLBinding.OpenGLNative.glGetString(Veldrid.OpenGLBinding.StringName.Version);
            byte *vendor   = Veldrid.OpenGLBinding.OpenGLNative.glGetString(Veldrid.OpenGLBinding.StringName.Vendor);
            byte *renderer = Veldrid.OpenGLBinding.OpenGLNative.glGetString(Veldrid.OpenGLBinding.StringName.Renderer);

            Logger.CoreVerbose("OpenGl info: ");
            Logger.CoreVerbose("  - Vendor: " + GetString(vendor));
            Logger.CoreVerbose("  - Renderer: " + GetString(renderer));
            Logger.CoreVerbose("  - Version: " + GetString(version));

            return(GraphicsDevice.CreateOpenGL(
                       options,
                       platformInfo,
                       (uint)window.Width,
                       (uint)window.Height));
        }
Example #14
0
        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);
        }
Example #15
0
        private static unsafe RenderContext CreateVulkanRenderContext(Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            Win32WindowInfo w32Info = Unsafe.Read <Win32WindowInfo>(&sysWmInfo.info);

            return(new VkRenderContext(VkSurfaceSource.CreateWin32(w32Info.hinstance, w32Info.window), window.Width, window.Height));
        }
Example #16
0
        unsafe static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CrashHandler);

            SDL_version version;

            Sdl2Native.SDL_GetVersion(&version);
            new StudioCore.MapStudioNew().Run();
        }
Example #17
0
        private static unsafe RenderContext CreateVulkanRenderContext(Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);

            return(new VkRenderContext(surfaceSource, window.Width, window.Height));
        }
Example #18
0
        private unsafe bool PlatformCreateVkSurface(ImGuiViewportPtr viewport)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            //TODO: Properly avoid memory leak for unreleased Vk surface
            WindowBase    window = (WindowBase)GCHandle.FromIntPtr(viewport.PlatformUserData).Target;
            SDL_SysWMinfo sysWmInfo;
            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(window.SdlWindow.SdlWindowHandle, &sysWmInfo);
            return(GetSurfaceSource(sysWmInfo).CreateSurface(new Vulkan.VkInstance(window.SdlWindow.SdlWindowHandle)) != Vulkan.VkSurfaceKHR.Null);
        }
Example #19
0
        public static unsafe GraphicsDevice CreateVulkanGraphicsDevice(ref GraphicsDeviceCreateInfo contextCI, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);
            GraphicsDevice  gd            = Hacks.CreateVulkan(surfaceSource, (uint)window.Width, (uint)window.Height, contextCI.DebugDevice);

            return(gd);
        }
Example #20
0
        public static unsafe GraphicsDevice CreateDefaultOpenGLGraphicsDevice(
            GraphicsDeviceOptions options,
            Sdl2Window window,
            GraphicsBackend backend,
            bool colorSrgb)
        {
            Sdl2Native.SDL_ClearError();
            IntPtr sdlHandle = window.SdlWindowHandle;

            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);

            SetSDLGLContextAttributes(options, backend, colorSrgb);

            IntPtr contextHandle = Sdl2Native.SDL_GL_CreateContext(sdlHandle);
            byte * error         = Sdl2Native.SDL_GetError();

            if (error != null)
            {
                string errorString = GetString(error);
                if (!string.IsNullOrEmpty(errorString))
                {
                    throw new VeldridException(
                              $"Unable to create OpenGL Context: \"{errorString}\". This may indicate that the system does not support the requested OpenGL profile, version, or Swapchain format.");
                }
            }

            int actualDepthSize;
            int result = Sdl2Native.SDL_GL_GetAttribute(SDL_GLAttribute.DepthSize, &actualDepthSize);
            int actualStencilSize;

            result = Sdl2Native.SDL_GL_GetAttribute(SDL_GLAttribute.StencilSize, &actualStencilSize);

            result = Sdl2Native.SDL_GL_SetSwapInterval(options.SyncToVerticalBlank ? 1 : 0);

            OpenGL.OpenGLPlatformInfo platformInfo = new OpenGL.OpenGLPlatformInfo(
                contextHandle,
                Sdl2Native.SDL_GL_GetProcAddress,
                context => Sdl2Native.SDL_GL_MakeCurrent(sdlHandle, context),
                () => Sdl2Native.SDL_GL_GetCurrentContext(),
                () => Sdl2Native.SDL_GL_MakeCurrent(new SDL_Window(IntPtr.Zero), IntPtr.Zero),
                Sdl2Native.SDL_GL_DeleteContext,
                () => Sdl2Native.SDL_GL_SwapWindow(sdlHandle),
                sync => Sdl2Native.SDL_GL_SetSwapInterval(sync ? 1 : 0));

            return(GraphicsDevice.CreateOpenGL(
                       options,
                       platformInfo,
                       (uint)window.Width,
                       (uint)window.Height));
        }
Example #21
0
        private byte GetWindowMinimized(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            SDL_WindowFlags flags = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);

            return((flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0);
        }
Example #22
0
        public static unsafe GraphicsDevice CreateVulkanGraphicsDevice(GraphicsDeviceOptions options, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);
            GraphicsDevice  gd            = GraphicsDevice.CreateVulkan(options, surfaceSource, (uint)window.Width, (uint)window.Height);

            return(gd);
        }
Example #23
0
        public InputGameController(IFrameworkMessenger frameworkMessenger, IApplicationMessenger applicationMessenger)
        {
            _frameworkMessenger   = frameworkMessenger;
            _applicationMessenger = applicationMessenger;

            Sdl2Native.SDL_Init(SDLInitFlags.GameController);

            _eventQueue = new Queue <SDL_Event>();

            _controllers = new Dictionary <int, GameController>();

            UpdateGamepadRegister();
        }
Example #24
0
 static unsafe TestUtils()
 {
     int result = Sdl2Native.SDL_Init(SDLInitFlags.Video);
     if (result != 0)
     {
         InitializationFailedMessage = GetString(Sdl2Native.SDL_GetError());
         InitializedSdl2 = false;
     }
     else
     {
         InitializedSdl2 = true;
     }
 }
Example #25
0
        private unsafe void UpdateGamepadRegister()
        {
            var validIds = new List <int>();

            var numJoySticks = Sdl2Native.SDL_NumJoysticks();

            var numGameControllers = 0;

            for (var c = 0; c < numJoySticks; c++)
            {
                if (Sdl2Native.SDL_IsGameController(c))
                {
                    var index      = c;
                    var controller = Sdl2Native.SDL_GameControllerOpen(index);
                    var joystick   = Sdl2Native.SDL_GameControllerGetJoystick(controller);
                    var instanceId = Sdl2Native.SDL_JoystickInstanceID(joystick);

                    var name = Marshal.PtrToStringAnsi((IntPtr)Sdl2Native.SDL_GameControllerName(controller));
                    _frameworkMessenger.Report(string.Concat("Detected Controller name: ", name));

                    var gameController = new GameController(name, controller, joystick);
                    if (_controllers.ContainsKey(instanceId))
                    {
                        if (_controllers[instanceId].Name != name)
                        {
                            _frameworkMessenger.Report(string.Concat("Warning: Controller replaced at instance id: ", instanceId, " does not have the same name as the previous controller here"));
                        }
                        _controllers.Remove(instanceId);
                    }

                    _controllers.Add(instanceId, gameController);
                    validIds.Add(instanceId);

                    numGameControllers++;
                }
            }

            var ids = _controllers.Keys.ToList();

            ids.ForEach(x =>
            {
                if (!validIds.Contains(x))
                {
                    _controllers.Remove(x);
                }
            });

            _frameworkMessenger.Report(string.Concat("Number of Joysticks detected: ", numJoySticks, " -> of those, number of GameControllers: ", numGameControllers));
        }
Example #26
0
        public static void CreateWindowAndGraphicsDevice(
            WindowCreateInfo windowCI,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
            Sdl2Native.SDL_Init(SDLInitFlags.Video);
            if (preferredBackend == GraphicsBackend.OpenGL || preferredBackend == GraphicsBackend.OpenGLES)
            {
                SetSDLGLContextAttributes(deviceOptions, preferredBackend);
            }

            window = CreateWindow(ref windowCI);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
Example #27
0
        public static void CreateWindowAndGraphicsDevice(
            WindowProps windowProps,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(typeof(WindowStartup));
            using (Profiler sdlProfiler = new Profiler("SDL_Init"))
#endif
            Sdl2Native.SDL_Init(SDLInitFlags.Video);

            window = CreateWindow(ref windowProps, preferredBackend);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
        public static unsafe RenderContext CreateVulkanRenderContext(ref RenderContextCreateInfo contextCI, Sdl2Window window)
        {
            IntPtr        sdlHandle = window.SdlWindowHandle;
            SDL_SysWMinfo sysWmInfo;

            Sdl2Native.SDL_GetVersion(&sysWmInfo.version);
            Sdl2Native.SDL_GetWMWindowInfo(sdlHandle, &sysWmInfo);
            VkSurfaceSource surfaceSource = GetSurfaceSource(sysWmInfo);
            VkRenderContext rc            = new VkRenderContext(surfaceSource, window.Width, window.Height);

            if (contextCI.DebugContext)
            {
                rc.EnableDebugCallback();
            }

            return(rc);
        }
Example #29
0
        public RenderView()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            Window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };

            void CreateAndAddCursor(SDL_SystemCursor type)
            {
                var cursor = Sdl2Native.SDL_CreateSystemCursor(type);

                cursorMap.Add(type, cursor);
            }

            CreateAndAddCursor(SDL_SystemCursor.Arrow);
            CreateAndAddCursor(SDL_SystemCursor.Crosshair);
            CreateAndAddCursor(SDL_SystemCursor.Hand);
            CreateAndAddCursor(SDL_SystemCursor.IBeam);
            CreateAndAddCursor(SDL_SystemCursor.No);
            CreateAndAddCursor(SDL_SystemCursor.SizeAll);
            CreateAndAddCursor(SDL_SystemCursor.SizeNESW);
            CreateAndAddCursor(SDL_SystemCursor.SizeNS);
            CreateAndAddCursor(SDL_SystemCursor.SizeNWSE);
            CreateAndAddCursor(SDL_SystemCursor.SizeWE);
            CreateAndAddCursor(SDL_SystemCursor.Wait);
            CreateAndAddCursor(SDL_SystemCursor.WaitArrow);

            GraphicsDevice = dispose.Add(VeldridStartup.CreateGraphicsDevice(Window, options, GraphicsBackend.Direct3D11));

            Window.Resized += () =>
            {
                GraphicsDevice.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
            };
        }
Example #30
0
        public DesktopWindow(string title, uint width, uint height)
        {
            const int centered = Sdl2Native.SDL_WINDOWPOS_CENTERED;

            Sdl2Native.SDL_Init(SDLInitFlags.Video | SDLInitFlags.GameController);
            _window = new Sdl2Window(title,
                                     centered, centered,
                                     (int)width, (int)height,
                                     SDL_WindowFlags.OpenGL,
                                     threadedProcessing: false
                                     );
            SwapchainSource = VeldridStartup.GetSwapchainSource(_window);

            _arrow  = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Arrow);
            _hand   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Hand);
            _wait   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Wait);
            _cursor = SystemCursor.Arrow;
        }