nCine::IGfxDevice class

Represents the interface to the graphics device where everything is rendered.

Abstracts the platform window and OpenGL context: it owns the window mode, the chosen display mode and the context creation attributes, exposes the window/drawable resolution used to set up the viewport, and enumerates the connected monitors and their video modes. Concrete back-ends (SDL, GLFW, Qt5, Android, ...) implement the platform-specific operations such as resolution changes and buffer swapping.

Derived classes

class EglGfxDevice
The EGL-based graphics device.
class GlfwGfxDevice
GLFW-based graphics device.
class Qt5GfxDevice
Graphics device that wraps a Qt5 Qt5Widget.
class SdlGfxDevice
SDL2-based graphics device.
class UwpGfxDevice
The UWP graphics device.

Public types

struct WindowMode
Initial properties of the application window.
struct VideoMode
Video mode supported by a monitor.
struct Monitor
Connected monitor.
struct GLContextInfo
Attributes used to create an OpenGL context.

Public static variables

static std::uint32_t MaxMonitors constexpr
static std::uint32_t MaxVideoModes constexpr

Constructors, destructors, conversion operators

IGfxDevice(const WindowMode& windowMode, const GLContextInfo& glContextInfo, const DisplayMode& displayMode)
~IGfxDevice() virtual

Public functions

void setSwapInterval(int interval) pure virtual
Sets the number of vertical blanks to occur before a buffer swap.
auto isFullscreen() const -> bool
Returns true if the device renders in full screen.
void setResolution(bool fullscreen, int width = 0, int height = 0) pure virtual
Sets the screen resolution with two integers.
void setWindowPosition(int x, int y) pure virtual
Sets the position of the application window with two integers.
void setWindowPosition(Vector2i position)
Sets the position of the application window with a Vector2i object.
void setWindowTitle(StringView windowTitle) pure virtual
Sets the application window title.
void setWindowIcon(StringView iconFilename) pure virtual
Sets the application window icon.
auto width() const -> int
Returns the window or video mode width in screen coordinates.
auto height() const -> int
Returns the window or video mode height in screen coordinates.
auto resolution() const -> Vector2i
Returns the window or video mode resolution in screen coordinates as a Vector2i object.
auto screenRect() const -> Rectf
Returns the window or video mode resolution in screen coordinates as a Rectf object.
auto aspect() const -> float
Returns the window or video mode resolution aspect ratio.
void setWindowSize(int width, int height) pure virtual
Sets the window size with two integers.
auto windowPosition() const -> const Vector2i virtual
Returns the window position as a Vector2i object.
auto drawableWidth() const -> int
Returns the window width in pixels.
auto drawableHeight() const -> int
Returns the window height in pixels.
auto drawableResolution() const -> Vector2i
Returns the window resolution in pixels as a Vector2i object.
auto drawableScreenRect() const -> Rectf
Returns the window resolution in pixels as a Rectf object.
auto drawableAspect() const -> float
Returns the window drawable resolution aspect ratio.
void flashWindow() const virtual
Highlights the application window to notify the user.
auto glContextInfo() const -> const GLContextInfo&
Returns the OpenGL context creation attributes.
auto displayMode() const -> const DisplayMode&
Returns the display mode.
auto numMonitors() const -> unsigned int
Returns the number of connected monitors.
auto primaryMonitorIndex() const -> unsigned int virtual
Returns the array index of the primary monitor.
auto windowMonitorIndex() const -> unsigned int virtual
Returns the array index of the monitor associated with the window.
auto monitor(unsigned int index) const -> const Monitor&
Returns the specified monitor.
auto monitor() const -> const Monitor&
Returns the monitor that hosts the window.
auto currentVideoMode(unsigned int monitorIndex) const -> const VideoMode& pure virtual
Returns the current video mode for the specified monitor.
auto currentVideoMode() const -> const VideoMode&
Returns the current video mode for the monitor that hosts the window.
auto setVideoMode(unsigned int modeIndex) -> bool virtual
Sets the video mode used in full screen by the monitor that hosts the window.
auto windowScalingFactor() const -> float
Returns the scaling factor for the application window.

Protected functions

void initGLViewport()
Initializes the OpenGL viewport based on the drawable resolution.
void updateMonitors() virtual
Updates the array of connected monitors.
void setResolutionInternal(int width, int height) pure virtual

Protected static variables

static float DefaultDPI constexpr

Private functions

void setupGL() virtual
Sets up the initial OpenGL state for the scene graph.
void update() pure virtual
Updates the screen by swapping the back and front buffers.

Function documentation

void nCine::IGfxDevice::setSwapInterval(int interval) pure virtual

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::IGfxDevice::setWindowSize(int width, int height) pure virtual

Sets the window size with two integers.

int nCine::IGfxDevice::drawableWidth() const

Returns the window width in pixels.

It may differ from width() on HiDPI screens.

int nCine::IGfxDevice::drawableHeight() const

Returns the window height in pixels.

It may differ from height() on HiDPI screens.

bool nCine::IGfxDevice::setVideoMode(unsigned int modeIndex) virtual

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