33 return SDL_SYSTEM_CURSOR_NO;
69 DIVIDE_ASSERT(
_windows.empty(),
"WindowManager::~WindowManager(): close() was not called before destruction!" );
82 const I32 targetDisplayIndex)
90 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
98 const I32 displayCount = SDL_GetNumVideoDisplays();
99 for (
I32 i = 0; i < displayCount; ++i)
104 SDL_GetDisplayBounds(i, &r);
108 SDL_GetDisplayUsableBounds(i, &r);
112 SDL_GetDisplayDPI(i, &data.
dpi,
nullptr,
nullptr);
122 const I32 displayIndex = std::max(std::min(targetDisplayIndex, displayCount - 1), 0);
127 descriptor.
position = initialPosition;
186 for (
I32 display = 0; display < numDisplays; ++display)
188 numberOfDisplayModes[display] = SDL_GetNumDisplayModes(display);
192 for (
U8 display = 0u; display < numDisplays; ++display)
195 for (
I32 mode = 0; mode < numberOfDisplayModes[display]; ++mode)
217 window->destroyWindow();
229 SDL_QuitSubSystem(SDL_INIT_VIDEO);
241 std::unique_ptr<DisplayWindow> window = std::make_unique<DisplayWindow>(*
this, *
_context);
253 windowFlags |= SDL_WINDOW_RESIZABLE;
257 windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
261 windowFlags |= SDL_WINDOW_HIDDEN;
265 windowFlags |= SDL_WINDOW_BORDERLESS;
269 windowFlags |= SDL_WINDOW_ALWAYS_ON_TOP;
273 windowFlags |= SDL_WINDOW_SKIP_TASKBAR;
280 windowFlags |= SDL_WINDOW_FULLSCREEN;
285 windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
300 bool contextChanged =
false;
304 contextChanged =
true;
307 err = window->init(windowFlags, winType, descriptor);
309 if ( crtWindow !=
nullptr && contextChanged )
311 Validate( SDL_GL_MakeCurrent( crtWindow->
getRawWindow(),
nullptr ) );
319 const bool isMainWindow = _mainWindow ==
nullptr;
323 _mainWindow = window.get();
332 _mainWindow =
nullptr;
342 params.height =
to_U16(args.
y);
343 params.isFullScreen = args.
_flag;
345 params.isMainWindow = isMainWindow;
366 auto tempWindow = win.get();
386 if (window ==
nullptr)
398 _mainWindow =
nullptr;
401 erase_if(
_windows, [targetGUID = window->
getGUID()](
auto& win)
noexcept { return win->getGUID() == targetGUID;});
411 if (!window || !(SDL_GetWindowFlags(window->getRawWindow()) &
to_U32(SDL_WINDOW_OPENGL)))
416 if ( window->userData()._glContext !=
nullptr)
418 if ( window->userData()._ownsContext)
420 SDL_GL_DeleteContext( window->userData()._glContext );
423 window->userData()._glContext =
nullptr;
437 Uint32 OpenGLFlags = SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG | SDL_GL_CONTEXT_RESET_ISOLATION_FLAG;
439 bool useDebugContext =
false;
443 OpenGLFlags |= SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG;
446 useDebugContext =
true;
447 OpenGLFlags |= SDL_GL_CONTEXT_DEBUG_FLAG;
450 if (!useDebugContext)
452 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_NO_ERROR, 1));
455 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, OpenGLFlags));
456 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_RELEASE_BEHAVIOR, SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE));
458 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1));
460 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
461 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
462 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
463 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8));
464 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8));
465 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
468 Validate(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE));
469 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4));
470 if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6) != 0)
472 ValidateAssert(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5));
477 ValidateAssert( SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ) );
492 if ( targetWindow->parentWindow() !=
nullptr)
494 targetWindow->userData( targetWindow->parentWindow()->userData() );
495 targetWindow->userData()._ownsContext =
false;
500 if ( targetWindow->userData()._glContext ==
nullptr )
502 targetWindow->userData()._glContext = SDL_GL_CreateContext( targetWindow->
getRawWindow() );
503 targetWindow->userData()._ownsContext =
true;
504 ValidateAssert( SDL_GL_SetAttribute( SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1 ) );
507 if ( targetWindow->userData()._glContext ==
nullptr)
518 bool vsyncSet =
false;
522 vsyncSet = SDL_GL_SetSwapInterval(-1) != -1;
531 vsyncSet = SDL_GL_SetSwapInterval(1) != -1;
538 SDL_GL_SetSwapInterval(0);
557 params.winGUID = mainWindow()->getGUID();
558 params.isMainWindow = window.
getGUID() == mainWindow()->getGUID();
582 if ( remainingWindows > 0 )
595 switch ( mainWindow()->type() )
625 return a.
x > b.x || a.
y > b.y;
636 for (
auto it = displayModes.rbegin(); it != displayModes.rend(); ++it )
639 if ( compare( res, renderingResolution ) )
649 for (
const auto& mode : displayModes )
652 if ( compare( renderingResolution, res ) )
670 SDL_CaptureMouse(state ? SDL_TRUE : SDL_FALSE);
676 if (focusedWindow ==
nullptr)
678 focusedWindow = mainWindow();
691 SDL_WarpMouseInWindow(focusedWindow->
getRawWindow(), x, y);
699 x = SDL_WINDOWPOS_CENTERED;
704 y = SDL_WINDOWPOS_CENTERED;
707 return SDL_WarpMouseGlobal(x, y) == 0;
713 if (style != s_CurrentStyle )
715 s_CurrentStyle = style;
722 [[maybe_unused]]
const I32 result = SDL_SetRelativeMouseMode(state ? SDL_TRUE : SDL_FALSE);
723 assert(result != -1);
728 return SDL_GetRelativeMouseMode() == SDL_TRUE;
734 SDL_GetGlobalMouseState(&ret.
x, &ret.
y);
741 SDL_GetMouseState(&ret.
x, &ret.
y);
749 return to_U32(SDL_GetGlobalMouseState(&pos.x, &pos.y));
752 return to_U32(SDL_GetMouseState(&pos.x, &pos.y));
757 SDL_CaptureMouse(state ? SDL_TRUE : SDL_FALSE);
763 if (focusedWindow ==
nullptr)
765 focusedWindow = mainWindow();
Class that provides an interface between our framework and the OS (start/stop, display support,...
bool mainLoopPaused() const
bool onResolutionChange(const SizeChangeParams ¶ms) const
bool onWindowSizeChange(const SizeChangeParams ¶ms) const
void RequestShutdown(bool clearCache) noexcept
static void RegisterDisplayMode(const U8 displayIndex, const DisplayManager::OutputDisplayProperties &mode)
static void SetActiveDisplayCount(const U8 displayCount)
static void drawToWindow(GFXDevice &device, DisplayWindow &window)
static void flushWindow(GFXDevice &device, DisplayWindow &window)
ErrorCode destroyWindow()
bool fullscreen() const noexcept
I32 currentDisplayIndex() const noexcept
vec2< U16 > getDimensions() const noexcept
SDL_Window * getRawWindow() const noexcept
void addEventListener(WindowEvent windowEvent, const EventListener &listener)
vec2< U16 > renderingResolution() const noexcept
FORCE_INLINE I64 getGUID() const noexcept
Application & app() noexcept
GFXDevice & gfx() noexcept
Configuration & config() noexcept
void toggleFullScreen() const
static bool IsRelativeMouseMode() noexcept
static void CaptureMouse(bool state) noexcept
static vec2< U16 > GetFullscreenResolution() noexcept
DisplayWindow * activeWindow() const noexcept
static U32 GetMouseState(vec2< I32 > &pos, bool global) noexcept
DisplayWindow * getFocusedWindow() noexcept
static void DestroyAPISettings(DisplayWindow *window) noexcept
static ErrorCode ConfigureAPISettings(const PlatformContext &context, const WindowDescriptor &descriptor)
vector< std::unique_ptr< DisplayWindow > > _windows
vector< MonitorData > _monitors
static void ToggleRelativeMouseMode(bool state) noexcept
void stepResolution(bool increment)
static void SetCaptureMouse(bool state) noexcept
static vec2< I32 > GetGlobalCursorPosition() noexcept
size_t pushActiveWindow(DisplayWindow *window)
Returns the total number of active windows after the push.
static vec2< I32 > GetCursorPosition() noexcept
PlatformContext * _context
DisplayWindow * createWindow(const WindowDescriptor &descriptor, ErrorCode &err)
static ErrorCode ApplyAPISettings(const PlatformContext &context, RenderAPI api, DisplayWindow *targetWindow, DisplayWindow *activeWindow)
void increaseResolution()
ErrorCode init(PlatformContext &context, RenderAPI renderingAPI, vec2< I16 > initialPosition, vec2< U16 > initialSize, WindowMode windowMode, I32 targetDisplayIndex)
static void SetCursorStyle(CursorStyle style)
size_t popActiveWindow()
Returns the remaining number of windows after the pop.
bool destroyWindow(DisplayWindow *&window)
static SDL_DisplayMode s_mainDisplayMode
static bool SetGlobalCursorPosition(I32 x, I32 y) noexcept
void decreaseResolution()
void snapCursorToCenter()
bool setCursorPosition(I32 x, I32 y) noexcept
void drawToWindow(DisplayWindow &window)
static std::array< SDL_Cursor *, to_base(CursorStyle::COUNT)> s_cursors
std::pair< vec2< U16 >, bool > _resolutionChangeQueued
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
constexpr bool ENABLE_GPU_VALIDATION
Error callbacks, validations, buffer checks, etc. are controlled by this flag. Heavy performance impa...
void DestroyPools() noexcept
void InitPools(const size_t poolSizeFactor)
bool ReplaceStringInPlace(T_str &subject, std::span< const std::string_view > search, std::string_view replace, bool recursive=false)
SDL_SystemCursor CursorToSDL(const CursorStyle style) noexcept
bool ValidateAssert(const I32 errCode)
bool Validate(const I32 errCode)
Handle console commands that start with a forward slash.
constexpr U32 to_U32(const T value)
constexpr U16 to_U16(const T value)
@ Vulkan
not supported yet
@ None
No rendering. Used for testing or server code.
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
constexpr U8 to_U8(const T value)
constexpr I16 to_I16(const T value)
constexpr I32 to_I32(const T value)
constexpr auto to_base(const Type value) -> Type
bool enableRenderAPIDebugging
bool enableRenderAPIBestPractices
struct Divide::Configuration::Debug::Renderer renderer
struct Divide::Configuration::Rendering rendering
struct Divide::Configuration::Runtime runtime
struct Divide::Configuration::Debug debug
static NO_INLINE void d_printfn(const char *format, T &&... args)
static NO_INLINE void errorfn(const char *format, T &&... args)
static NO_INLINE void warnfn(const char *format, T &&... args)
U8 _maxRefreshRate
As returned by SDL_GetPixelFormatName.
static const OutputDisplayPropertiesContainer & GetDisplayModes(const size_t displayIndex) noexcept
static constexpr U8 g_maxDisplayOutputs
U16 width
The new width and height.
bool isFullScreen
Is the window that fired the event fullscreen?
DisplayWindow * parentWindow