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)
 
virtual ~RenderWindow () override
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual 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)
 
virtual void setClearColor (const RGBAColorFloat &color) override
 
virtual const RGBAColorFloatgetClearColor () const override
 
void setPosition (const glm::ivec2 &position)
 
const glm::ivec2 getPosition () const
 
SDL_Window * getNativeWindow () const
 
virtual uint getNumber () const override
 
math::Rect getRect () const
 
math::Rect getRectPixels () const
 
virtual void beginRendering () override
 
virtual void endRendering () override
 
virtual VkFormat getColorFormat () const override
 
virtual VkFormat getDepthFormat () const override
 
virtual VkSampleCountFlagBits getSampleCount () const override
 
virtual bool getSampleShadingEnabled () const override
 
virtual ECullWindingOrder getWindingOrder () const override
 
virtual VkRenderPass getRenderPass () const override
 
- 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...
 
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 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()

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()

virtual ~RenderWindow ( )
overridevirtual

Destroys all render resources

Member Function Documentation

◆ beginRendering()

virtual void beginRendering ( )
overridevirtual

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

Implements IRenderTarget.

◆ endRendering()

virtual 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()

virtual const RGBAColorFloat& getClearColor ( ) const
overridevirtual

Returns the window clear color.

Returns
the window clear color.

Implements IRenderTarget.

◆ getColorFormat()

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

Implements IRenderTarget.

◆ getDepthFormat()

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

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()

virtual uint getNumber ( ) const
overridevirtual
Returns
the hardware window number

Implements Window.

◆ getPosition()

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

◆ 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()

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

Implements IRenderTarget.

◆ getSampleCount()

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

Implements IRenderTarget.

◆ getSampleShadingEnabled()

virtual 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()

virtual ECullWindingOrder getWindingOrder ( ) const
overridevirtual
Returns
polygon winding order

Implements IRenderTarget.

◆ hide()

void hide ( )

Hides the window

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Creates window, connects to resize event.

Reimplemented from Object.

◆ isResizable()

bool isResizable ( ) const
Returns
if the window is resizable

◆ onDestroy()

virtual void onDestroy ( )
overridevirtual

Called when the window is detroyed.

Reimplemented from Object.

◆ setClearColor()

virtual 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)

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.

◆ mBorderless

bool mBorderless = false

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

◆ 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.