nCine::Backends::SdlGfxDevice class

SDL2-based graphics device.

Manages the application window and OpenGL context using the SDL2 library.

Base classes

class nCine::IGfxDevice
Represents the interface to the graphics device where everything is rendered.

Public static functions

static auto IsMainWindow(std::uint32_t windowId) -> bool
Returns true if the specified window ID refers to the main window.
static auto GetWindowHandle() -> SDL_Window*
Returns the SDL2 handle of the main window.
static auto GetGlContextHandle() -> SDL_GLContext
Returns the SDL2 OpenGL context handle.
static void QueryDrawableSize(SDL_Window* windowHandle, int fallbackWidth, int fallbackHeight, int& width, int& height)
Queries a window's drawable (pixel) size the way the active RHI backend measures it.
static auto IsAuxiliaryWindow(std::uint32_t windowId) -> bool
Returns true if the SDL window ID is one of the auxiliary windows of the application, see CreateAuxiliaryWindow().
static auto ToMainWindowPosition(std::uint32_t windowId, Vector2i position) -> Vector2i
Converts a position over a window of the application to one relative to the main window.
static auto IsOwnWindow(std::uint32_t windowId) -> bool
Returns true if the SDL window ID is the main window or an auxiliary window of the application.

Constructors, destructors, conversion operators

SdlGfxDevice(const WindowMode& windowMode, const ContextInfo& contextInfo, const DisplayMode& displayMode)
~SdlGfxDevice() override

Public functions

void SetSwapInterval(int interval) override
Sets the number of vertical blanks to occur before a buffer swap.
void SetResolution(bool fullscreen, int width = 0, int height = 0) override
Sets the screen resolution with two integers.
void Update() override
Updates the screen by swapping the back and front buffers.
void SetWindowPosition(int x, int y) override
Sets the position of the application window with two integers.
void SetWindowSize(int width, int height) override
Sets the window size with two integers.
void SetDrawableSize(int width, int height) override
Sets the pixel size of the drawable (the size the frame is rendered at) without touching the window.
void SetWindowTitle(StringView windowTitle) override
Sets the application window title.
void SetWindowIcon(StringView iconFilename) override
Sets the application window icon.
auto GetWindowPosition() const -> const Vector2i override
Returns the window position as a Vector2i object.
void FlashWindow() const override
Highlights the application window to notify the user.
auto GetWindowMonitorIndex() const -> unsigned int override
Returns the array index of the monitor associated with the window.
auto GetCurrentVideoMode(unsigned int monitorIndex) const -> const VideoMode& override
Returns the current video mode for the specified monitor.
auto SetVideoMode(unsigned int modeIndex) -> bool override
Sets the video mode used in full screen by the monitor that hosts the window.
auto SupportsAuxiliaryWindows() const -> bool override
Returns true if windows besides the main one can be made, see CreateAuxiliaryWindow().
auto CreateAuxiliaryWindow(const AuxiliaryWindowDesc& desc) -> std::unique_ptr<AuxiliaryWindow> override
Makes a hidden window besides the main one, nullptr if it can't be made, see AuxiliaryWindow.
auto GetGlobalMousePosition(Vector2i& position) const -> bool override
Returns the position of the pointer on the desktop in pixels, false if it isn't known.
auto GetWindowContentScale() const -> float override
Returns the scale of the display the main window is on, 1 for 100 %, see AuxiliaryWindow::GetContentScale().
auto GetGlobalMouseButtons(std::uint32_t& buttons) const -> bool override
Returns the mouse buttons held now as the system has them, false if it isn't known.
auto GetDesktopWorkArea(Vector2i point, Recti& area) const -> bool override
Returns the part of the display at a point of the desktop that windows may take, without the taskbar.
void SyncFullscreenState()
Follows a fullscreen change of the main window that the window system reports.

Protected functions

void SetResolutionInternal(int width, int height) override
void UpdateMonitors() override
Updates the array of connected monitors.

Function documentation

static bool nCine::Backends::SdlGfxDevice::IsMainWindow(std::uint32_t windowId)

Returns true if the specified window ID refers to the main window.

Parameters
windowId SDL2 window identifier to compare against the main window

static void nCine::Backends::SdlGfxDevice::QueryDrawableSize(SDL_Window* windowHandle, int fallbackWidth, int fallbackHeight, int& width, int& height)

Queries a window's drawable (pixel) size the way the active RHI backend measures it.

Confines the per-backend drawable-size query (SDL renderer output size on the software backend, SDL_GL_GetDrawableSize elsewhere) to one place; fallbackWidth / fallbackHeight are used when the query returns a non-positive size.

static Vector2i nCine::Backends::SdlGfxDevice::ToMainWindowPosition(std::uint32_t windowId, Vector2i position)

Converts a position over a window of the application to one relative to the main window.

A position over an auxiliary window can be outside of the main window then. A position over the main window stays as it is.

void nCine::Backends::SdlGfxDevice::SetSwapInterval(int interval) override

Sets the number of vertical blanks to occur before a buffer swap.

An interval of -1 will enable adaptive v-sync if available.

void nCine::Backends::SdlGfxDevice::SetWindowSize(int width, int height) override

Sets the window size with two integers.

void nCine::Backends::SdlGfxDevice::SetDrawableSize(int width, int height) override

Sets the pixel size of the drawable (the size the frame is rendered at) without touching the window.

Honoured only by a backend that renders the frame into an intermediate surface of its own and stretches it onto the display at present time (the sceGxm backend on PS Vita, see GxmDevice::ScreenWidth), where the surface is recreated at the new size and the application is notified through OnResizeWindow(). Everywhere else the drawable follows the window and this does nothing. Out-of-range sizes are clamped to what the display can show.

bool nCine::Backends::SdlGfxDevice::SetVideoMode(unsigned int modeIndex) override

Sets the video mode used in full screen by the monitor that hosts the window.

bool nCine::Backends::SdlGfxDevice::SupportsAuxiliaryWindows() const override

Returns true if windows besides the main one can be made, see CreateAuxiliaryWindow().

Only desktop systems where windows can be placed anywhere have them, with a graphics backend that can present into another window.

float nCine::Backends::SdlGfxDevice::GetWindowContentScale() const override

Returns the scale of the display the main window is on, 1 for 100 %, see AuxiliaryWindow::GetContentScale().

By default it's how many pixels the main window has for a unit of the desktop.

bool nCine::Backends::SdlGfxDevice::GetGlobalMouseButtons(std::uint32_t& buttons) const override

Returns the mouse buttons held now as the system has them, false if it isn't known.

Bits 0, 1 and 2 are the left, the right and the middle button. Unlike the events, it's never left behind when a release goes to a window of the application that was just shown or moved under the pointer.

bool nCine::Backends::SdlGfxDevice::GetDesktopWorkArea(Vector2i point, Recti& area) const override

Returns the part of the display at a point of the desktop that windows may take, without the taskbar.

The display nearest to the point if it's on none. In units of the desktop, as positions of windows are. Returns false if it isn't known.

void nCine::Backends::SdlGfxDevice::SyncFullscreenState()

Follows a fullscreen change of the main window that the window system reports.

Only a change of the reported state is taken over, so a request still pending in the window system is not undone by an event that arrives before it was confirmed.