nCine  2025.04.r498-9d36345
A cross-platform 2D game engine
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
ncine::IGfxDevice Class Referenceabstract

It represents the interface to the graphics device where everything is rendered. More...

#include <IGfxDevice.h>

Collaboration diagram for ncine::IGfxDevice:
Collaboration graph
[legend]

Classes

struct  GLContextInfo
 Contains the attributes to create an OpenGL context. More...
 
struct  Monitor
 A structure representing a connected monitor. More...
 
struct  VideoMode
 A structure representing a video mode supported by a monitor. More...
 
struct  WindowMode
 A structure used to initialize window properties. More...
 

Public Member Functions

 IGfxDevice (const WindowMode &windowMode, const GLContextInfo &glContextInfo, const DisplayMode &displayMode)
 
virtual void setSwapInterval (int interval)=0
 Sets the number of vertical blanks to occur before a buffer swap. More...
 
bool isFullScreen () const
 Returns true if the device renders in full screen.
 
virtual void setFullScreen (bool fullScreen)=0
 Sets the full screen flag of the window.
 
bool isResizable () const
 Returns true if the window is resizable.
 
virtual int windowPositionX () const
 Returns the window horizontal position.
 
virtual int windowPositionY () const
 Returns the window vertical position.
 
virtual const Vector2i windowPosition () const
 Returns the window position as a Vector2i object.
 
virtual void setWindowPosition (int x, int y)=0
 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.
 
int width () const
 Returns the window or video mode width in screen coordinates.
 
int height () const
 Returns the window or video mode height in screen coordinates.
 
Vector2i resolution () const
 Returns the window or video mode resolution in screen coordinates as a Vector2i object.
 
Rectf screenRect () const
 Returns the window or video mode resolution in screen coordinates as a Rectf object.
 
float aspect () const
 Returns the window or video mode resolution aspect ratio.
 
virtual void setWindowSize (int width, int height)=0
 Sets the window size with two integers. More...
 
void setWindowSize (Vector2i size)
 Sets the window size with a Vector2i object. More...
 
int drawableWidth () const
 Returns the window width in pixels. More...
 
int drawableHeight () const
 Returns the window height in pixels. More...
 
Vector2i drawableResolution () const
 Returns the window resolution in pixels as a Vector2i object.
 
Rectf drawableScreenRect () const
 Returns the window resolution in pixels as a Rectf object.
 
float drawableAspect () const
 Returns the window drawable resolution aspect ratio.
 
virtual void setWindowTitle (const char *windowTitle)=0
 Sets the application window title.
 
virtual void setWindowIcon (const char *windowIconFilename)=0
 Sets the application window icon.
 
virtual void flashWindow () const
 Highlights the application window to notify the user.
 
const GLContextInfoglContextInfo () const
 Returns the OpenGL context creation attributes.
 
const DisplayModedisplayMode () const
 Returns display mode.
 
unsigned int numMonitors () const
 Returns the number of connected monitors.
 
virtual unsigned int primaryMonitorIndex () const
 Returns the array index of the primary monitor. More...
 
virtual unsigned int windowMonitorIndex () const
 Returns the array index of the monitor associated with the window.
 
const Monitormonitor (unsigned int index) const
 Returns the specified monitor.
 
const Monitormonitor () const
 Returns the monitor that hosts the window.
 
virtual const VideoModecurrentVideoMode (unsigned int monitorIndex) const =0
 Returns the current video mode for the specified monitor.
 
const VideoModecurrentVideoMode () const
 Returns the current video mode for the monitor that hosts the window.
 
virtual bool setVideoMode (unsigned int modeIndex)
 Sets the video mode that will be used in full screen by the monitor that hosts the window. More...
 
float windowScalingFactor () const
 Returns the scaling factor for application window.
 

Static Public Attributes

static const unsigned int MaxMonitors = 4
 
static const unsigned int MaxVideoModes = 128
 

Protected Member Functions

void initWindowScaling (const WindowMode &windowMode)
 Scales the window size by the display factor before creating it for the first time.
 
void initGLViewport ()
 Inits the OpenGL viewport based on the drawable resolution.
 
int containingMonitorIndex (int x, int y, int width, int height) const
 Returns the monitor index that contains the center of the specified rectangle, or -1 if its center is outside the virtual screen. More...
 
int containingMonitorIndex (const Recti &rect) const
 Returns the monitor index that contains the center of the specified rectangle as a Recti object, or -1 if its center is outside the virtual screen. More...
 
int containingMonitorIndex (const WindowMode &windowMode) const
 Returns the monitor index that contains the center of the specified rectangle as a WindowMode object, or -1 if its center is outside the virtual screen. More...
 
int containingMonitorIndex (int x, int y) const
 Returns the monitor index that contains the specified point, or -1 if the point is outside the virtual screen.
 
int containingMonitorIndex (const Vector2i &point) const
 Returns the monitor index that contains the specified point as a Vector2i object, or -1 if the point is outside the virtual screen.
 
virtual void updateMonitors ()
 Updates the array of connected monitors.
 

Protected Attributes

int width_
 Window width in screen coordinates.
 
int height_
 Window height in screen coordinates.
 
int drawableWidth_
 Window width in pixels (for HiDPI screens)
 
int drawableHeight_
 Window height in pixels (for HiDPI screens)
 
bool isFullScreen_
 Whether rendering occurs in full screen.
 
bool isResizable_
 Whether the window is resizable.
 
GLContextInfo glContextInfo_
 OpenGL context creation attributes.
 
DisplayMode displayMode_
 Display properties.
 
Monitor monitors_ [MaxMonitors]
 
unsigned int numMonitors_
 
VideoMode currentVideoMode_
 Used as a cache to avoid searching the current video mode in a monitor's array.
 
bool backendScalesWindowSize_
 A flag indicating if the backend is responsible for scaling the window size. More...
 
float previousScalingFactor_
 The window scaling factor from last frame.
 

Static Protected Attributes

static const float DefaultDpi = 96.0f
 The default value used for a monitor DPI when the real vaue cannot be queried.
 

Friends

class Application
 

Detailed Description

It represents the interface to the graphics device where everything is rendered.

Member Function Documentation

◆ containingMonitorIndex() [1/3]

int ncine::IGfxDevice::containingMonitorIndex ( const Recti rect) const
inlineprotected

Returns the monitor index that contains the center of the specified rectangle as a Recti object, or -1 if its center is outside the virtual screen.

Note
The special WindowPositionIgnore value can be used for the x and y variables

◆ containingMonitorIndex() [2/3]

int ncine::IGfxDevice::containingMonitorIndex ( const WindowMode windowMode) const
inlineprotected

Returns the monitor index that contains the center of the specified rectangle as a WindowMode object, or -1 if its center is outside the virtual screen.

Note
The special WindowPositionIgnore value can be used for the x and y variables

◆ containingMonitorIndex() [3/3]

int ncine::IGfxDevice::containingMonitorIndex ( int  x,
int  y,
int  width,
int  height 
) const
protected

Returns the monitor index that contains the center of the specified rectangle, or -1 if its center is outside the virtual screen.

Note
The special WindowPositionIgnore value can be used for the x and y variables

◆ drawableHeight()

int ncine::IGfxDevice::drawableHeight ( ) const
inline

Returns the window height in pixels.

It may differs from height() on HiDPI screens

◆ drawableWidth()

int ncine::IGfxDevice::drawableWidth ( ) const
inline

Returns the window width in pixels.

It may differs from width() on HiDPI screens

◆ primaryMonitorIndex()

virtual unsigned int ncine::IGfxDevice::primaryMonitorIndex ( ) const
inlinevirtual

Returns the array index of the primary monitor.

Note
This is usually the monitor where elements like the task bar or global menu bar are located.

◆ setSwapInterval()

virtual 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

◆ setVideoMode()

virtual bool ncine::IGfxDevice::setVideoMode ( unsigned int  modeIndex)
inlinevirtual

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

Note
Call this method before enabling full screen.

◆ setWindowSize() [1/2]

virtual void ncine::IGfxDevice::setWindowSize ( int  width,
int  height 
)
pure virtual

Sets the window size with two integers.

Note
If the application is in full screen this method will have no effect.

◆ setWindowSize() [2/2]

void ncine::IGfxDevice::setWindowSize ( Vector2i  size)
inline

Sets the window size with a Vector2i object.

Note
If the application is in full screen this method will have no effect.

Member Data Documentation

◆ backendScalesWindowSize_

bool ncine::IGfxDevice::backendScalesWindowSize_
protected

A flag indicating if the backend is responsible for scaling the window size.

Note
Uses SDL_HINT_WINDOWS_DPI_SCALING on SDL >= 2.24.0 and GLFW_SCALE_TO_MONITOR on GLFW

The documentation for this class was generated from the following files: