NAP
Public Types | Public Member Functions | Public Attributes | List of all members
RenderWindow Class Reference

#include <renderwindow.h>

Public Types

enum  EPresentationMode : int { Immediate, Mailbox, FIFO_Relaxed, FIFO }
 
- Public Types inherited from Window
using EventPtrList = std::vector< EventPtr >
 
using EventPtrConstIterator = utility::UniquePtrConstVectorWrapper< WindowEventPtrList, Event * >
 

Public Member Functions

 RenderWindow (Core &core)
 
 RenderWindow (Core &core, SDL_Window *windowHandle)
 
 ~RenderWindow () override
 
bool init (utility::ErrorState &errorState) override
 
void onDestroy () override
 
const glm::ivec2 getSize () const
 
int getWidth () const
 
int getWidthPixels () const
 
int getHeight () const
 
int getHeightPixels () const
 
const glm::ivec2 getBufferSize () const override
 
void show ()
 
void hide ()
 
const std::string & getTitle () const
 
void setTitle (std::string newTitle)
 
bool isResizable () const
 
void setFullscreen (bool value)
 
void toggleFullscreen ()
 
void setWidth (int width)
 
void setHeight (int height)
 
void setSize (const glm::ivec2 &size)
 
void setClearColor (const RGBAColorFloat &color) override
 
const RGBAColorFloatgetClearColor () const override
 
void setPosition (const glm::ivec2 &position) const
 
glm::ivec2 getPosition () const
 
float getPixelDensity () const
 
float getDisplayScale () const
 
void setAlwaysOnTop (bool onTop)
 
SDL_Window * getNativeWindow () const
 
bool isEmbedded () const
 
bool isMinimized () const
 
bool isHidden () const
 
bool isOccluded () const
 
uint getNumber () const override
 
math::Rect getRect () const
 
math::Rect getRectPixels () const
 
float getRatio () const
 
void beginRendering () override
 
void endRendering () override
 
VkFormat getColorFormat () const override
 
VkFormat getDepthFormat () const override
 
VkSampleCountFlagBits getSampleCount () const override
 
bool getSampleShadingEnabled () const override
 
ECullWindingOrder getWindingOrder () const override
 
VkRenderPass getRenderPass () const override
 
VkImageLayout getFinalLayout () const override
 
int getDisplayIndex () const
 
- Public Member Functions inherited from Window
void addEvent (WindowEventPtr inEvent)
 
void processEvents ()
 
EventPtrConstIterator getEvents () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

bool mSampleShading = true
 Property: 'SampleShading' Reduces texture aliasing when enabled, at higher computational cost. More...
 
int mWidth = 512
 Property: 'Width' window horizontal resolution. More...
 
int mHeight = 512
 Property: 'Height' window vertical resolution. More...
 
bool mBorderless = false
 Property: 'Borderless' if the window has any borders. More...
 
bool mResizable = true
 Property: 'Resizable' if the window is resizable. More...
 
bool mVisible = true
 Property: 'Visible' if the render window is visible on screen. More...
 
bool mAlwaysOnTop = false
 Property: 'AlwaysOnTop' Brings the window to the front and keeps it above the rest. More...
 
EPresentationMode mMode = EPresentationMode::Immediate
 Property: 'Mode' the image presentation mode to use. More...
 
std::string mTitle = ""
 Property: 'Title' window title. More...
 
RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 1.0f }
 Property: 'ClearColor' background clear color. More...
 
ERasterizationSamples mRequestedSamples = ERasterizationSamples::Four
 Property: 'Samples' The number of samples used during Rasterization. For even better results enable 'SampleShading'. More...
 
int mAddedSwapImages = 1
 Property: 'AdditionalSwapImages' number of additional swapchain images to create, added to minimum specified by hardware. More...
 
bool mClear = true
 Property: 'Clear' whether to clear the render window at the start of each render pass. More...
 
bool mRestorePosition = true
 Property: 'RestorePosition' if window position is restored from previous session. More...
 
bool mRestoreSize = true
 Property: 'RestoreSize' if window size is restored from previous session
More...
 
- Public Attributes inherited from Window
Signal< const WindowEvent & > mWindowEvent
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Vulkan render window that can be declared in JSON.

Multiple presentation (display) modes are available to choose from. The selected presentation mode controls how the rendered images are presented to screen: in sync, out of sync or tied to the refresh rate of the monitor. It is however possible that the selected presentation mode is not supported by the graphics hardware, if that's the case the window will revert to FIFO_KRH, which is the presentation mode every vulkan compatible device must support. A warning is issued if the selected presentation mode is unavailable.

In order to improve performance, consider lowering the sample count and disable sample based shading. If sample based shading is requested but not supported, it is disabled and a warning is issued. If the requested multi-sample count exceeds what is supported by the hardware, the highest available sample count is picked and a warning is issued.

Initialization will fail when the nap::RenderService is configured to run headless. When headless rendering is enabled, the engine is initialized without surface and swapchain support, which are required by a nap::RenderWindow to display images on screen.

Inheritance diagram for RenderWindow:
[legend]
Collaboration diagram for RenderWindow:
[legend]

Member Enumeration Documentation

◆ EPresentationMode

enum EPresentationMode : int
strong

The various image presentation modes. Controls the way in which images are presented to screen.

Enumerator
Immediate 

The new image immediately replaces the display image, screen tearing may occur.

Mailbox 

The new image replaces the one image waiting in the queue, becoming the first to be displayed. No screen tearing occurs. Could result in not-shown images. CPU not synced to display refresh rate.

FIFO_Relaxed 

Every image is presented in order. No screen tearing occurs when drawing faster than monitor refresh rate. CPU synced to display refresh rate.

FIFO 

Every image is presented in order. No screen tearing occurs, also when drawing slower then monitor refresh rate. CPU synced to display refresh rate.

Constructor & Destructor Documentation

◆ RenderWindow() [1/2]

RenderWindow ( Core core)

This constructor is called when creating the render window using the resource manager Every render window needs to be aware of it's render service

◆ RenderWindow() [2/2]

RenderWindow ( Core core,
SDL_Window *  windowHandle 
)

This constructor is called when creating the render window using napkin

◆ ~RenderWindow()

~RenderWindow ( )
override

Destroys all render resources

Member Function Documentation

◆ beginRendering()

void beginRendering ( )
overridevirtual

Starts a render pass. Only call this when recording is enabled.

Implements IRenderTarget.

◆ endRendering()

void endRendering ( )
overridevirtual

Ends a render pass. Always call this after beginRendering().

Implements IRenderTarget.

◆ getBufferSize()

const glm::ivec2 getBufferSize ( ) const
overridevirtual

Returns the width and height of this window in pixels.

Returns
the width and height of this window in pixels.

Implements IRenderTarget.

◆ getClearColor()

const RGBAColorFloat& getClearColor ( ) const
overridevirtual

Returns the window clear color.

Returns
the window clear color.

Implements IRenderTarget.

◆ getColorFormat()

VkFormat getColorFormat ( ) const
overridevirtual
Returns
swapchain format used to render to window.

Implements IRenderTarget.

◆ getDepthFormat()

VkFormat getDepthFormat ( ) const
overridevirtual
Returns
depth format used by window.

Implements IRenderTarget.

◆ getDisplayIndex()

int getDisplayIndex ( ) const
Returns
display index

◆ getDisplayScale()

float getDisplayScale ( ) const

Get the current content display scale relative to a window's pixel size.

This is a combination of the window pixel density and the display content scale, and is the expected scale for displaying content in this window. For example, if a 3840x2160 window had a display scale of 2.0, the user expects the content to take twice as many pixels and be the same physical size as if it were being displayed in a 1920x1080 window with a display scale of 1.0.

Returns
window display scale, 0.0f if call fails

◆ getFinalLayout()

VkImageLayout getFinalLayout ( ) const
overridevirtual
Returns
layout of the texture when render pass ends

Implements IRenderTarget.

◆ getHeight()

int getHeight ( ) const

Returns the height of the window, in screen coordinates. Note that on high DPI monitors this is not the same as the pixel count. To get the height in pixels use the size of the backbuffer using getHeightPixels().

Returns
the height of the window in pixels

◆ getHeightPixels()

int getHeightPixels ( ) const

Returns the height of this window in pixels.

Returns
the width of the window in pixels.

◆ getNativeWindow()

SDL_Window* getNativeWindow ( ) const
Returns
the hardware window handle, nullptr if undefined

◆ getNumber()

uint getNumber ( ) const
overridevirtual
Returns
the hardware window number

Implements Window.

◆ getPixelDensity()

float getPixelDensity ( ) const

Get the current pixel density, this is a ratio of pixel size to window size.

For example, if the window is 1920x1080 and it has a high density back buffer of 3840x2160 pixels, it would have a pixel density of 2.0.

◆ getPosition()

glm::ivec2 getPosition ( ) const
Returns
the window position in pixel coordinates

◆ getRatio()

float getRatio ( ) const
Returns
render window ratio, height over width

◆ getRect()

math::Rect getRect ( ) const

Creates a rectangle based on the current width and height of the render window. Note that the returned dimensions of the rectangle can differ from the actual size in pixels on a high dpi monitor. To obtain a rectangle that contains the actual size of the window in pixels use: getRectPixels

Returns
the window as a rectangle

◆ getRectPixels()

math::Rect getRectPixels ( ) const

Creates a rectangle based on the current width and height of the render window in pixels.

Returns
the window as rectangle

◆ getRenderPass()

VkRenderPass getRenderPass ( ) const
overridevirtual
Returns
render pass associated with this window.

Implements IRenderTarget.

◆ getSampleCount()

VkSampleCountFlagBits getSampleCount ( ) const
overridevirtual
Returns
used number of samples when rendering to the window.

Implements IRenderTarget.

◆ getSampleShadingEnabled()

bool getSampleShadingEnabled ( ) const
overridevirtual
Returns
if sample based shading is enabled when rendering to the window.

Implements IRenderTarget.

◆ getSize()

const glm::ivec2 getSize ( ) const

Returns the width and height of this window, in screen coordinates. Note that on high DPI monitors this is not the same as the pixel count. To get the width and height in pixels use getBufferSize().

Returns
the size of this window in pixels, ie: the drawable / buffer size

◆ getTitle()

const std::string& getTitle ( ) const
Returns
the window title

◆ getWidth()

int getWidth ( ) const

Returns the width of the window, in screen coordinates. Note that on high DPI monitors this is not the same as the pixel count. To get the width in pixels use the size of the backbuffer using getWidthPixels().

Returns
the width of the window

◆ getWidthPixels()

int getWidthPixels ( ) const

Returns the width of this window in pixels.

Returns
the width of the window in pixels.

◆ getWindingOrder()

ECullWindingOrder getWindingOrder ( ) const
overridevirtual
Returns
polygon winding order

Implements IRenderTarget.

◆ hide()

void hide ( )

Hides the window

◆ init()

bool init ( utility::ErrorState errorState)
overridevirtual

Creates window, connects to resize event.

Reimplemented from Object.

◆ isEmbedded()

bool isEmbedded ( ) const
Returns
if this window is embedded into another application

◆ isHidden()

bool isHidden ( ) const

When hidden, the window is not mapped onto the desktop nor shown in the taskbar.

Returns
if the window is hidden

◆ isMinimized()

bool isMinimized ( ) const
Returns
if the window is minimized

◆ isOccluded()

bool isOccluded ( ) const
Returns
ff the window is behind another window or desktop element.

◆ isResizable()

bool isResizable ( ) const
Returns
if the window is resizable

◆ onDestroy()

void onDestroy ( )
overridevirtual

Called when the window is destroyed.

Reimplemented from Object.

◆ setAlwaysOnTop()

void setAlwaysOnTop ( bool  onTop)

Moves the window to the front and keeps it there

Parameters
ifthe window is moved to the front and kept there.

◆ setClearColor()

void setClearColor ( const RGBAColorFloat color)
overridevirtual

Sets the window clear color.

Parameters
colorthe new clear color

Implements IRenderTarget.

◆ setFullscreen()

void setFullscreen ( bool  value)

Turns full screen on / off This is the windowed full screen mode, game is not supported

Parameters
valueif the window is set to fill the screen or not

◆ setHeight()

void setHeight ( int  height)

Sets the height of the window, in screen coordinates.

Parameters
heightthe new window height, in screen coordinates.

◆ setPosition()

void setPosition ( const glm::ivec2 &  position) const

Sets the position of the window on screen

Parameters
positionthe new screen position in pixel coordinates

◆ setSize()

void setSize ( const glm::ivec2 &  size)

Set the size of the window, in screen coordinates.

Parameters
sizethe new window size, in screen coordinates.

◆ setTitle()

void setTitle ( std::string  newTitle)

Sets the window title

◆ setWidth()

void setWidth ( int  width)

Sets the width of the window, in screen coordinates.

Parameters
widththe new width of the window, in screen coordinates.

◆ show()

void show ( )

Shows the window and gives it input focus. This call also makes sure the window is on top of other windows.

◆ toggleFullscreen()

void toggleFullscreen ( )

Toggles full screen on / off

Member Data Documentation

◆ mAddedSwapImages

int mAddedSwapImages = 1

Property: 'AdditionalSwapImages' number of additional swapchain images to create, added to minimum specified by hardware.

◆ mAlwaysOnTop

bool mAlwaysOnTop = false

Property: 'AlwaysOnTop' Brings the window to the front and keeps it above the rest.

◆ mBorderless

bool mBorderless = false

Property: 'Borderless' if the window has any borders.

◆ mClear

bool mClear = true

Property: 'Clear' whether to clear the render window at the start of each render pass.

◆ mClearColor

RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 1.0f }

Property: 'ClearColor' background clear color.

◆ mHeight

int mHeight = 512

Property: 'Height' window vertical resolution.

◆ mMode

Property: 'Mode' the image presentation mode to use.

◆ mRequestedSamples

Property: 'Samples' The number of samples used during Rasterization. For even better results enable 'SampleShading'.

◆ mResizable

bool mResizable = true

Property: 'Resizable' if the window is resizable.

◆ mRestorePosition

bool mRestorePosition = true

Property: 'RestorePosition' if window position is restored from previous session.

◆ mRestoreSize

bool mRestoreSize = true

Property: 'RestoreSize' if window size is restored from previous session

◆ mSampleShading

bool mSampleShading = true

Property: 'SampleShading' Reduces texture aliasing when enabled, at higher computational cost.

◆ mTitle

std::string mTitle = ""

Property: 'Title' window title.

◆ mVisible

bool mVisible = true

Property: 'Visible' if the render window is visible on screen.

◆ mWidth

int mWidth = 512

Property: 'Width' window horizontal resolution.