You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Windows, SDL_CaptureMouse is emulated in terms of relative mouse motion under raw input [1] since the use of Win32's SetCapture is avoided because it only tracks while the left mouse button is held [2]. This is actually the use case most people want, but I suppose some people must've reported bugs and this choice was made instead.
There's two problems with this:
This emulation is actually far slower than SetCapture. Enough that mouse motion events can either double-fire or drop randomly while in capturing mode. You can test this yourself by printing mouse motion values while capture is enabled. This is unfortunate.
Since capture is emulated in terms of relative mouse mode. It must register itself for RawInput if not already. This may be fine normally, if only done once (the registration is quite slow), however when capturing is disabled, SDL unregisters RawInput for the mouse. The documentation encourages to only use mouse capture in "short bursts" [3], implying that one captures and uncaptures only when one needs to, under this recommendation the mouse is consistently registered and unregistered for RawInput leading to a lot of overhead. When done during mouse interaction (common), you can drop events, double-fire, and stall input leading to stuttering of mouse input.
It's actually somewhat difficult now to get the performant behavior of SetCapture where you have mouse motion events relative to the window while still having a hardware cursor. There is no equivalent behavior in SDL for it. The use of SDL_SetRelativeMouseMode globally would hide the cursor (maybe it can be reenabled?) and only provide relative motion events (no window position values). Instead the best work around I've found has been to ignore events completely and emulate it like this:
Not only is this far faster than the current SDL_MouseCapture API in my measurements, it's more responsive on Windows too. Despite what the documentation about SDL_GetGlobalMousePosition says [4]. It requires no raw input shenanigans and one can support the behavior of tracking while only left clicking (like SetCapture) and the current global tracking of SDL_MouseCapture without any of the performance loss currently experienced.
SDL 2.0 is now in maintenance mode, and all inactive issues are being closed. If this issue is impacting you, please feel free to reopen it with additional information.
On Windows,
SDL_CaptureMouse
is emulated in terms of relative mouse motion under raw input [1] since the use of Win32'sSetCapture
is avoided because it only tracks while the left mouse button is held [2]. This is actually the use case most people want, but I suppose some people must've reported bugs and this choice was made instead.There's two problems with this:
SetCapture
. Enough that mouse motion events can either double-fire or drop randomly while in capturing mode. You can test this yourself by printing mouse motion values while capture is enabled. This is unfortunate.It's actually somewhat difficult now to get the performant behavior of
SetCapture
where you have mouse motion events relative to the window while still having a hardware cursor. There is no equivalent behavior in SDL for it. The use ofSDL_SetRelativeMouseMode
globally would hide the cursor (maybe it can be reenabled?) and only provide relative motion events (no window position values). Instead the best work around I've found has been to ignore events completely and emulate it like this:Not only is this far faster than the current
SDL_MouseCapture
API in my measurements, it's more responsive on Windows too. Despite what the documentation aboutSDL_GetGlobalMousePosition
says [4]. It requires no raw input shenanigans and one can support the behavior of tracking while only left clicking (likeSetCapture
) and the current global tracking ofSDL_MouseCapture
without any of the performance loss currently experienced.[1] https://github.com/libsdl-org/SDL/blob/main/src/video/windows/SDL_windowsmouse.c#L287
[2] https://github.com/libsdl-org/SDL/blob/main/src/video/windows/SDL_windowsmouse.c#L283-L286
[3] https://github.com/libsdl-org/sdlwiki/blob/main/SDL_CaptureMouse.mediawiki#remarks
[4] https://github.com/libsdl-org/sdlwiki/blob/main/SDL_GetGlobalMouseState.mediawiki#remarks
The text was updated successfully, but these errors were encountered: