Nameless Engine
Loading...
Searching...
No Matches
ne::Renderer Class Referenceabstract

#include <Renderer.h>

Inheritance diagram for ne::Renderer:
ne::DirectXRenderer ne::VulkanRenderer

Classes

struct  LightsInFrustum
 
struct  MeshesInFrustum
 

Public Member Functions

 Renderer (const Renderer &)=delete
 
Rendereroperator= (const Renderer &)=delete
 
virtual std::vector< std::string > getSupportedGpuNames () const =0
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRenderResolutions () const =0
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRefreshRates () const =0
 
virtual RendererType getType () const =0
 
virtual std::string getUsedApiVersion () const =0
 
std::pair< std::recursive_mutex *, RenderSettings * > getRenderSettings ()
 
RenderStatisticsgetRenderStatistics ()
 
virtual std::string getCurrentlyUsedGpuName () const =0
 
size_t getTotalVideoMemoryInMb () const
 
size_t getUsedVideoMemoryInMb () const
 
virtual void waitForGpuToFinishWorkUpToThisPoint ()=0
 
std::pair< std::recursive_mutex, std::unique_ptr< ShaderConfiguration > > * getShaderConfiguration ()
 
virtual std::pair< unsigned int, unsigned int > getRenderTargetSize () const =0
 
WindowgetWindow () const
 
GameManagergetGameManager () const
 
ShaderManagergetShaderManager () const
 
PipelineManagergetPipelineManager () const
 
GpuResourceManagergetResourceManager () const
 
FrameResourcesManagergetFrameResourcesManager () const
 
ShaderCpuWriteResourceManagergetShaderCpuWriteResourceManager () const
 
ShaderTextureResourceManagergetShaderTextureResourceManager () const
 
LightingShaderResourceManagergetLightingShaderResourceManager () const
 
std::recursive_mutex * getRenderResourcesMutex ()
 
virtual GpuResourcegetDepthTextureNoMultisampling ()=0
 

Static Public Member Functions

static constexpr float getMinDepth ()
 
static constexpr float getMaxDepth ()
 
static std::variant< std::unique_ptr< Renderer >, Errorcreate (GameManager *pGameManager, std::optional< RendererType > preferredRenderer)
 

Protected Member Functions

 Renderer (GameManager *pGameManager)
 
std::optional< ErrorcompileEngineShaders () const
 
void updateFrameConstantsBuffer (FrameResource *pCurrentFrameResource, CameraProperties *pCameraProperties)
 
void resetGpuResourceManager ()
 
void resetPipelineManager ()
 
void resetFrameResourcesManager ()
 
void resetLightingShaderResourceManager ()
 
virtual std::variant< AntialiasingQuality, ErrorgetMaxSupportedAntialiasingQuality () const =0
 
void onFramebufferSizeChanged (int iWidth, int iHeight)
 
virtual void onFramebufferSizeChangedDerived (int iWidth, int iHeight)
 
void drawNextFrame ()
 
virtual void prepareRenderTargetForNextFrame ()
 
virtual void prepareForDrawingNextFrame (CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource)=0
 
virtual void drawShadowMappingPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, PipelineManager::GraphicsPipelineRegistry *pGraphicsPipelines)=0
 
virtual void drawMeshesDepthPrepass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines)=0
 
virtual void executeComputeShadersOnGraphicsQueue (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, ComputeExecutionStage stage)=0
 
virtual void drawMeshesMainPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vTransparentPipelines)=0
 
virtual void present (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex)=0
 
std::optional< ErroronRenderSettingsChanged (bool bShadowMapSizeChanged=false)
 
virtual std::optional< ErroronRenderSettingsChangedDerived ()=0
 
virtual void waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource)=0
 
virtual bool isInitialized () const =0
 
std::optional< ErrorinitializeRenderer ()
 
std::optional< ErrorinitializeResourceManagers ()
 
std::optional< ErrorclampSettingsToMaxSupported ()
 
std::optional< ErrorrecalculateLightTileFrustums ()
 
MeshesInFrustumgetMeshesInCameraFrustum (CameraProperties *pActiveCameraProperties, PipelineManager::GraphicsPipelineRegistry *pGraphicsPipelines)
 
void cullLightsOutsideCameraFrustum (CameraProperties *pActiveCameraProperties, size_t iCurrentFrameResourceIndex)
 
std::pair< std::mutex, FrameConstants > * getFrameConstants ()
 
std::atomic< size_t > * getDrawCallCounter ()
 

Static Protected Member Functions

static consteval unsigned int getRecommendedSwapChainBufferCount ()
 
static void getDirectionalLightNodeShadowMappingInfo (DirectionalLightNode *pNode, ShadowMapHandle *&pShadowMapHandle, unsigned int &iShadowPassLightInfoArrayIndex)
 
static void getSpotlightNodeShadowMappingInfo (SpotlightNode *pNode, ShadowMapHandle *&pShadowMapHandle, unsigned int &iShadowPassLightInfoArrayIndex)
 
static unsigned int getPointLightShadowPassLightInfoArrayIndex (PointLightNode *pNode, size_t iCubemapFaceIndex)
 
static ShadowMapHandlegetPointLightNodeShadowMapHandle (PointLightNode *pNode)
 

Private Member Functions

void calculateFrameStatistics ()
 
void updateResourcesForNextFrame (unsigned int iRenderTargetWidth, unsigned int iRenderTargetHeight, CameraProperties *pCameraProperties)
 
void onActiveCameraChanged ()
 
void updateTargetTimeToRenderFrame ()
 
void updateShaderConfiguration ()
 
void setupRenderStats ()
 
std::optional< ErrorinitializeRenderSettings ()
 

Static Private Member Functions

static std::unique_ptr< RenderercreateRenderer (GameManager *pGameManager, std::optional< RendererType > preferredRenderer)
 
static std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > createRenderer (RendererType type, GameManager *pGameManager, const std::vector< std::string > &vBlacklistedGpuNames)
 

Private Attributes

std::recursive_mutex mtxRwRenderResources
 
std::unique_ptr< GpuResourceManagerpResourceManager
 
std::unique_ptr< ShaderManagerpShaderManager
 
std::unique_ptr< PipelineManagerpPipelineManager
 
std::unique_ptr< FrameResourcesManagerpFrameResourcesManager
 
std::unique_ptr< ShaderCpuWriteResourceManagerpShaderCpuWriteResourceManager
 
std::unique_ptr< ShaderTextureResourceManagerpShaderTextureResourceManager
 
std::unique_ptr< LightingShaderResourceManagerpLightingShaderResourceManager
 
std::pair< std::recursive_mutex, std::unique_ptr< ShaderConfiguration > > mtxShaderConfiguration
 
std::pair< std::recursive_mutex, std::unique_ptr< RenderSettings > > mtxRenderSettings
 
MeshesInFrustum meshesInFrustumLastFrame
 
bool bIsWindowMinimized = false
 
std::pair< std::mutex, EnvironmentNode * > mtxSpawnedEnvironmentNode
 
std::pair< std::mutex, FrameConstantsmtxFrameConstants
 
RenderStatistics renderStats
 
GameManagerpGameManager = nullptr
 

Static Private Attributes

static constexpr unsigned int iRecommendedSwapChainBufferCount = 2
 
static constexpr float minDepth = 0.0F
 
static constexpr float maxDepth = 1.0F
 

Friends

class Window
 
class ShaderConfiguration
 
class RenderSettings
 
class EnvironmentNode
 
class CameraManager
 

Detailed Description

Defines a base class for renderers to implement.

Constructor & Destructor Documentation

◆ Renderer()

ne::Renderer::Renderer ( GameManager pGameManager)
protected

Constructor.

Parameters
pGameManagerpGameManager object that owns this renderer.

Member Function Documentation

◆ calculateFrameStatistics()

void ne::Renderer::calculateFrameStatistics ( )
private

Calculates some frame-related statistics.

Remarks
Must be called after a frame is finished drawing.

◆ clampSettingsToMaxSupported()

std::optional< Error > ne::Renderer::clampSettingsToMaxSupported ( )
protected

Called by derived class after they have created essential API objects (D3D device / Vulkan physical device) so that RenderSettings can query maximum supported settings and clamp the current values (if needed).

Warning
Must be called by derived classes after they have created essential API objects (D3D device / Vulkan physical device).
Returns
Error if something went wrong.

◆ compileEngineShaders()

std::optional< Error > ne::Renderer::compileEngineShaders ( ) const
protected

Compiles/verifies all essential shaders that the engine will use.

Remarks
This is the last step in renderer initialization that is executed after the renderer was tested to support the hardware.
Returns
Error if something went wrong.

◆ create()

std::variant< std::unique_ptr< Renderer >, Error > ne::Renderer::create ( GameManager pGameManager,
std::optional< RendererType >  preferredRenderer 
)
static

Creates a new renderer.

Parameters
pGameManagerGame manager object that will own this renderer.
preferredRendererPreferred renderer to be used.
Returns
Error if no renderer could be created, otherwise created renderer.

◆ createRenderer() [1/2]

std::unique_ptr< Renderer > ne::Renderer::createRenderer ( GameManager pGameManager,
std::optional< RendererType >  preferredRenderer 
)
staticprivate

Creates a new renderer and nothing else.

This function is only used to pick a renderer including the specified preference without doing any renderer finalization.

Parameters
pGameManagerGame manager object that will own this renderer.
preferredRendererRenderer to prefer to create.
Returns
nullptr if no renderer could be created, otherwise created renderer.

◆ createRenderer() [2/2]

std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > ne::Renderer::createRenderer ( RendererType  type,
GameManager pGameManager,
const std::vector< std::string > &  vBlacklistedGpuNames 
)
staticprivate

Attempts to create a renderer of the specified type.

This function is only used to pick a renderer including the specified preference without doing any renderer finalization.

Parameters
typeType of the renderer to create.
pGameManagerGame manager object that will own this renderer.
vBlacklistedGpuNamesNames of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong.
Returns
Created renderer if successful, otherwise multiple values in a pair: error and a name of the GPU that the renderer tried to use (can be empty if failed before picking a GPU or if all supported GPUs are blacklisted).

◆ cullLightsOutsideCameraFrustum()

void ne::Renderer::cullLightsOutsideCameraFrustum ( CameraProperties pActiveCameraProperties,
size_t  iCurrentFrameResourceIndex 
)
protected

Culls all light nodes that are outside of active camera's frustum so that they will not be processed during the next submitted frame.

Parameters
pActiveCameraPropertiesProperties of the currently active camera.
iCurrentFrameResourceIndexIndex of the frame resource that will be used to submit the next frame.

◆ drawMeshesDepthPrepass()

virtual void ne::Renderer::drawMeshesDepthPrepass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vOpaquePipelines 
)
protectedpure virtual

Submits commands to draw meshes and the specified depth only (vertex shader only) pipelines.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
vOpaquePipelinesOpaque pipelines (depth pipeline will be retrieved from them).

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ drawMeshesMainPass()

virtual void ne::Renderer::drawMeshesMainPass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vOpaquePipelines,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vTransparentPipelines 
)
protectedpure virtual

Submits commands to draw meshes for main (color) pass.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
vOpaquePipelinesOpaque pipelines to draw.
vTransparentPipelinesTransparent pipelines to draw.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ drawNextFrame()

void ne::Renderer::drawNextFrame ( )
protected

Submits a new frame to the GPU.

◆ drawShadowMappingPass()

virtual void ne::Renderer::drawShadowMappingPass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
PipelineManager::GraphicsPipelineRegistry pGraphicsPipelines 
)
protectedpure virtual

Submits commands to draw world from the perspective of all spawned light sources to capture shadow maps.

Warning
Expects to be called after cullLightsOutsideCameraFrustum to capture shadow maps only for lights in frustum.
Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
pGraphicsPipelinesGraphics pipelines to draw.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ executeComputeShadersOnGraphicsQueue()

virtual void ne::Renderer::executeComputeShadersOnGraphicsQueue ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
ComputeExecutionStage  stage 
)
protectedpure virtual

Executes compute shaders of the specified stage.

Warning
Expects that mutex for compute shaders is locked.
Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
stageStage of compute shaders to execute.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getCurrentlyUsedGpuName()

virtual std::string ne::Renderer::getCurrentlyUsedGpuName ( ) const
pure virtual

Returns the name of the GPU that is being currently used.

Returns
Name of the GPU.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getDepthTextureNoMultisampling()

virtual GpuResource * ne::Renderer::getDepthTextureNoMultisampling ( )
pure virtual

Returns pointer to the texture resource that represents renderer's depth texture without multisampling (resolved resource).

Warning
If MSAA is enabled this function will return one resource (pointer to a separate depth resolved resource), if it's disabled it will return the other resource (pointer to depth texture). So it may be a good idea to query this pointer every time you need it instead of saving it and reusing it because every frame this pointer may change (due to other reasons such as render target resize and etc).
Please note that it's only safe to call this function inside of the drawNextFrame function (because returned pointer will not be changed during this function), if you need to use depth texture in your game code create an issue and I will add a GameInstance callback that will be called each frame inside of the drawNextFrame so you can use this function.
Returns
Pointer to depth texture.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getDirectionalLightNodeShadowMappingInfo()

void ne::Renderer::getDirectionalLightNodeShadowMappingInfo ( DirectionalLightNode pNode,
ShadowMapHandle *&  pShadowMapHandle,
unsigned int &  iShadowPassLightInfoArrayIndex 
)
staticprotected

Returns information needed to capture/update a shadow map for a specific node.

Parameters
pNodeDirectional light to update its shadow map.
pShadowMapHandleShadow map handle of the specified light.
iShadowPassLightInfoArrayIndexIndex into the array of shadow pass light infos.

◆ getDrawCallCounter()

std::atomic< size_t > * ne::Renderer::getDrawCallCounter ( )
inlineprotected

Returns counter for draw calls.

Remarks
Must be used by derived classes to increment draw call counter.
Automatically resets in calculateFrameStatistics.
Returns
Draw call counter.

◆ getFrameConstants()

std::pair< std::mutex, FrameConstants > * ne::Renderer::getFrameConstants ( )
inlineprotected

Returns frame constants.

Returns
Frame constants.

◆ getFrameResourcesManager()

FrameResourcesManager * ne::Renderer::getFrameResourcesManager ( ) const

Returns frame resources manager.

Warning
Do not delete (free) returned pointer.
Returns
Frame resources manager.

◆ getGameManager()

GameManager * ne::Renderer::getGameManager ( ) const

Game manager object that owns this renderer.

Warning
Do not delete (free) returned pointer.
Returns
Game manager object.

◆ getLightingShaderResourceManager()

LightingShaderResourceManager * ne::Renderer::getLightingShaderResourceManager ( ) const

Returns manager that controls GPU resources of lighting shader resources.

Warning
Do not delete (free) returned pointer.
Returns
Manager.

◆ getMaxDepth()

static constexpr float ne::Renderer::getMaxDepth ( )
inlinestaticconstexpr

Returns the maximum value for depth.

Returns
Maximum depth value.

◆ getMaxSupportedAntialiasingQuality()

virtual std::variant< AntialiasingQuality, Error > ne::Renderer::getMaxSupportedAntialiasingQuality ( ) const
protectedpure virtual

Returns the maximum anti-aliasing quality that can be used on the picked GPU (getCurrentlyUsedGpuName).

Remarks
Note that the maximum supported AA quality can differ depending on the used GPU/renderer.
Returns
Error if something went wrong, otherwise DISABLED if AA is not supported or the maximum supported AA quality.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getMeshesInCameraFrustum()

Renderer::MeshesInFrustum * ne::Renderer::getMeshesInCameraFrustum ( CameraProperties pActiveCameraProperties,
PipelineManager::GraphicsPipelineRegistry pGraphicsPipelines 
)
protected

Iterates over all meshes and returns only meshes inside of the camera's frustum (and their pipelines).

Warning
Do not delete (free) returned pointer.
Remarks
This function is expected to be called only once per frame.
Parameters
pActiveCameraPropertiesProperties of the currently active camera.
pGraphicsPipelinesGraphics pipelines.
Returns
Pipelines, material and meshes inside camera's frustum.

◆ getMinDepth()

static constexpr float ne::Renderer::getMinDepth ( )
inlinestaticconstexpr

Returns the minimum value for depth.

Returns
Minimum depth value.

◆ getPipelineManager()

PipelineManager * ne::Renderer::getPipelineManager ( ) const

Returns pipeline manager used to store graphics and compute pipelines.

Warning
Do not delete (free) returned pointer.
Returns
Pipeline manager.

◆ getPointLightNodeShadowMapHandle()

ShadowMapHandle * ne::Renderer::getPointLightNodeShadowMapHandle ( PointLightNode pNode)
staticprotected

Returns shadow map handle of the specified point light node.

Parameters
pNodePoint light node.
Returns
Shadow map handle.

◆ getPointLightShadowPassLightInfoArrayIndex()

unsigned int ne::Renderer::getPointLightShadowPassLightInfoArrayIndex ( PointLightNode pNode,
size_t  iCubemapFaceIndex 
)
staticprotected

Returns information needed to capture/update a shadow map for a specific node.

Parameters
pNodePoint light to update its shadow map.
iCubemapFaceIndexIndex of the cubemap to get matrix index.
Returns
Index into the array of shadow pass light infos.

◆ getRecommendedSwapChainBufferCount()

static consteval unsigned int ne::Renderer::getRecommendedSwapChainBufferCount ( )
inlinestaticprotected

Returns the number of swap chain buffers/images that we prefer to use.

Remarks
Frame resources expect that the number of swap chain images is equal to the number of frame resources because frame resources store synchronization objects such as fences and semaphores that expect one swap chain image per frame resource. If your renderer wants to use other number swap chain images you would might to implement a custom logic that will make sure everything is synchronized. For example, if you want to have less swap chain images than there is frame resources then you will need to store something like a pair of "swap chain image" - "frame resource" and each frame check if some swap chain image is used by some frame resource or not and wait if it's being used.
Returns
The recommended number of swap chain buffers/images that will work without any additional logic.

◆ getRenderResourcesMutex()

std::recursive_mutex * ne::Renderer::getRenderResourcesMutex ( )

Returns mutex that is used when reading or writing to GPU resources that may be used by the GPU.

Remarks
This mutex is generally locked when the renderer is submitting a new frame.
Usually after locking this mutex you would use waitForGpuToFinishWorkUpToThisPoint before actually starting to write/modify GPU resources.
Do not delete (free) returned pointer.
Returns
Mutex.

◆ getRenderSettings()

std::pair< std::recursive_mutex *, RenderSettings * > ne::Renderer::getRenderSettings ( )

Returns render settings that can be configured.

Remarks
Do not delete (free) returned pointer.
Returns
Non-owning pointer to render settings.

◆ getRenderStatistics()

RenderStatistics * ne::Renderer::getRenderStatistics ( )

Returns various statistics about rendering (such as FPS).

Remarks
Do not delete (free) returned pointer.
Returns
Statistics.

◆ getRenderTargetSize()

virtual std::pair< unsigned int, unsigned int > ne::Renderer::getRenderTargetSize ( ) const
pure virtual

Returns size of the render target (size of the underlying render image).

Returns
Render image size in pixels (width and height).

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getResourceManager()

GpuResourceManager * ne::Renderer::getResourceManager ( ) const

Returns GPU resource manager.

Warning
Do not delete (free) returned pointer.
Returns
GPU resource manager.

◆ getShaderConfiguration()

std::pair< std::recursive_mutex, std::unique_ptr< ShaderConfiguration > > * ne::Renderer::getShaderConfiguration ( )

Returns the current shader configuration (shader settings, represented by a bunch of predefined macros).

Must be used with mutex.

Returns
Do not delete (free) returned pointer. Shader configuration.

◆ getShaderCpuWriteResourceManager()

ShaderCpuWriteResourceManager * ne::Renderer::getShaderCpuWriteResourceManager ( ) const

Returns manager of shader resources with CPU write access.

Warning
Do not delete (free) returned pointer.
Returns
Manager.

◆ getShaderManager()

ShaderManager * ne::Renderer::getShaderManager ( ) const

Returns shader manager used to compile shaders.

Warning
Do not delete (free) returned pointer.
Returns
Shader manager.

◆ getShaderTextureResourceManager()

ShaderTextureResourceManager * ne::Renderer::getShaderTextureResourceManager ( ) const

Returns manager of shader resources that reference textures.

Warning
Do not delete (free) returned pointer.
Returns
Manager.

◆ getSpotlightNodeShadowMappingInfo()

void ne::Renderer::getSpotlightNodeShadowMappingInfo ( SpotlightNode pNode,
ShadowMapHandle *&  pShadowMapHandle,
unsigned int &  iShadowPassLightInfoArrayIndex 
)
staticprotected

Returns information needed to capture/update a shadow map for a specific node.

Parameters
pNodeSpotlight to update its shadow map.
pShadowMapHandleShadow map handle of the specified light.
iShadowPassLightInfoArrayIndexIndex into the array of shadow pass light infos.

◆ getSupportedGpuNames()

virtual std::vector< std::string > ne::Renderer::getSupportedGpuNames ( ) const
pure virtual

Looks for video adapters (GPUs) that support this renderer.

Remarks
Note that returned array might differ depending on the used renderer.
Returns
Empty array if no GPU supports used renderer, otherwise array with GPU names that can be used for this renderer.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getSupportedRefreshRates()

virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > ne::Renderer::getSupportedRefreshRates ( ) const
pure virtual

Returns a list of supported screen refresh rates (pairs of numerator and denominator).

Remarks
The list of supported refresh rates depends on the currently used GPU, so if changing used GPU this list might return different values.
Returns
Error if something went wrong, otherwise refresh rates.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getSupportedRenderResolutions()

virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > ne::Renderer::getSupportedRenderResolutions ( ) const
pure virtual

Returns a list of supported render resolution (pairs of width and height).

Returns
Error if something went wrong, otherwise render resolutions.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getTotalVideoMemoryInMb()

size_t ne::Renderer::getTotalVideoMemoryInMb ( ) const

Returns total video memory (VRAM) size in megabytes.

Remarks
If integrated GPU is used this function might return shared video memory (includes both dedicated VRAM and system RAM).
Returns
Total video memory size in megabytes.

◆ getType()

virtual RendererType ne::Renderer::getType ( ) const
pure virtual

Returns renderer's type.

Returns
Renderer's type.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getUsedApiVersion()

virtual std::string ne::Renderer::getUsedApiVersion ( ) const
pure virtual

Returns API version or a feature level that the renderer uses.

For example DirectX renderer will return used feature level and Vulkan renderer will return used Vulkan API version.

Returns
Used API version.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ getUsedVideoMemoryInMb()

size_t ne::Renderer::getUsedVideoMemoryInMb ( ) const

Returns the amount of video memory (VRAM) that is currently being used by the renderer.

Remarks
Does not return global (system-wide) used VRAM size, only VRAM used by the renderer (i.e. only VRAM used by this application).
Returns
Size of the video memory used by the renderer in megabytes.

◆ getWindow()

Window * ne::Renderer::getWindow ( ) const

Returns the window that we render to.

Warning
Do not delete (free) returned pointer.
Returns
Window we render to.

◆ initializeRenderer()

std::optional< Error > ne::Renderer::initializeRenderer ( )
protected

Initializes some essential parts of the renderer (such as RenderSettings).

Warning
Must be called by derived classes in the beginning of their initialization.
Returns
Error if something went wrong.

◆ initializeRenderSettings()

std::optional< Error > ne::Renderer::initializeRenderSettings ( )
private

Initializes mtxRenderSettings.

Returns
Error if something went wrong.

◆ initializeResourceManagers()

std::optional< Error > ne::Renderer::initializeResourceManagers ( )
protected

Initializes various resource managers.

Warning
Must be called by derived classes after base initialization (for ex. in DirectX after device and video adapter were created).
Returns
Error if something went wrong.

◆ isInitialized()

virtual bool ne::Renderer::isInitialized ( ) const
protectedpure virtual

Tells whether the renderer is initialized or not.

Initialized renderer means that the hardware supports it and it's safe to use renderer functionality such as onRenderSettingsChanged.

Returns
Whether the renderer is initialized or not.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ onActiveCameraChanged()

void ne::Renderer::onActiveCameraChanged ( )
private

Called by camera manager after active camera was changed.

◆ onFramebufferSizeChanged()

void ne::Renderer::onFramebufferSizeChanged ( int  iWidth,
int  iHeight 
)
protected

Called when the framebuffer size was changed.

Parameters
iWidthNew width of the framebuffer (in pixels).
iHeightNew height of the framebuffer (in pixels).

◆ onFramebufferSizeChangedDerived()

virtual void ne::Renderer::onFramebufferSizeChangedDerived ( int  iWidth,
int  iHeight 
)
inlineprotectedvirtual

Called when the framebuffer size was changed.

Parameters
iWidthNew width of the framebuffer (in pixels).
iHeightNew height of the framebuffer (in pixels).

Reimplemented in ne::VulkanRenderer.

◆ onRenderSettingsChanged()

std::optional< Error > ne::Renderer::onRenderSettingsChanged ( bool  bShadowMapSizeChanged = false)
protected

Called after some render setting is changed to recreate internal resources to match the current settings.

Parameters
bShadowMapSizeChangedtrue if shadow map size was changed, false otherwise.
Returns
Error if something went wrong.

◆ onRenderSettingsChangedDerived()

virtual std::optional< Error > ne::Renderer::onRenderSettingsChangedDerived ( )
protectedpure virtual

Called from onRenderSettingsChanged after some render setting is changed to recreate internal resources to match the current settings.

Returns
Error if something went wrong.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ prepareForDrawingNextFrame()

virtual void ne::Renderer::prepareForDrawingNextFrame ( CameraProperties pCameraProperties,
FrameResource pCurrentFrameResource 
)
protectedpure virtual

Setups everything for render commands to be recorded (resets command buffers and etc.).

Warning
Expects that render resources mutex is locked.
Remarks
When this function is called this means that the current frame resource is no longer used by the GPU.
Parameters
pCameraPropertiesCamera properties to use.
pCurrentFrameResourceFrame resource of the frame being submitted.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ prepareRenderTargetForNextFrame()

virtual void ne::Renderer::prepareRenderTargetForNextFrame ( )
inlineprotectedvirtual

Called before prepareForDrawingNextFrame to do early frame preparations.

Remarks
It's expected that render target's size will not change after this function is finished and before a new frame is submitted.

Reimplemented in ne::VulkanRenderer.

◆ present()

virtual void ne::Renderer::present ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex 
)
protectedpure virtual

Does the final frame rendering logic to present the frame on the screen.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ recalculateLightTileFrustums()

std::optional< Error > ne::Renderer::recalculateLightTileFrustums ( )
protected

Notifies pLightingShaderResourceManager to recalculate grid of frustums for light culling process.

Returns
Error if something went wrong.

◆ resetFrameResourcesManager()

void ne::Renderer::resetFrameResourcesManager ( )
protected

Sets nullptr to frame resources manager's unique ptr to force destroy it (if exists).

Warning
Avoid using this function. Only use it if you need a special destruction order in your renderer.

◆ resetGpuResourceManager()

void ne::Renderer::resetGpuResourceManager ( )
protected

Sets nullptr to resource manager's unique ptr to force destroy it (if exists).

Warning
Avoid using this function. Only use it if you need a special destruction order in your renderer.

◆ resetLightingShaderResourceManager()

void ne::Renderer::resetLightingShaderResourceManager ( )
protected

Sets nullptr to lighting shader resource manager's unique ptr to force destroy it (if exists).

Warning
Avoid using this function. Only use it if you need a special destruction order in your renderer.

◆ resetPipelineManager()

void ne::Renderer::resetPipelineManager ( )
protected

Sets nullptr to pipeline manager's unique ptr to force destroy it (if exists).

Warning
Avoid using this function. Only use it if you need a special destruction order in your renderer.

◆ setupRenderStats()

void ne::Renderer::setupRenderStats ( )
private

Initializes renderStats to be used.

◆ updateFrameConstantsBuffer()

void ne::Renderer::updateFrameConstantsBuffer ( FrameResource pCurrentFrameResource,
CameraProperties pCameraProperties 
)
protected

Takes the current frame resource and updates frame data constant buffer that it stores (by copying new (up to date) constants to it).

Remarks
Expected to be called by derived renderers only when they know that frame resources are not being used by the GPU.
Parameters
pCurrentFrameResourceCurrent frame resource.
pCameraPropertiesCamera properties to use.

◆ updateResourcesForNextFrame()

void ne::Renderer::updateResourcesForNextFrame ( unsigned int  iRenderTargetWidth,
unsigned int  iRenderTargetHeight,
CameraProperties pCameraProperties 
)
private

Updates internal resources (frame constants, shader resources, camera's aspect ratio and etc.) for the next frame.

Remarks
Waits before frame resource for the new frame will not be used by the GPU so it's safe to work with frame resource after calling this function.
Parameters
iRenderTargetWidthWidth (in pixels) of the image that will be used for the next frame.
iRenderTargetHeightHeight (in pixels) of the image that will be used for the next frame.
pCameraPropertiesCamera properties to use.

◆ updateShaderConfiguration()

void ne::Renderer::updateShaderConfiguration ( )
private

Updates the current shader configuration (settings) based on the current value from getShaderConfiguration.

Remarks
Flushes the command queue and recreates pipelines' internal resources so that they will use new shader configuration.

◆ updateTargetTimeToRenderFrame()

void ne::Renderer::updateTargetTimeToRenderFrame ( )
private

Looks for FPS limit setting in RenderSettings and updates renderer's target time to render a frame.

◆ waitForGpuToFinishUsingFrameResource()

virtual void ne::Renderer::waitForGpuToFinishUsingFrameResource ( FrameResource pFrameResource)
protectedpure virtual

Blocks the current thread until the GPU is finished using the specified frame resource.

Remarks
Generally the current frame resource will be passed and so the current frame resource mutex will be locked at the time of calling and until the function is not finished it will not be unlocked.
Parameters
pFrameResourceFrame resource to wait for.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

◆ waitForGpuToFinishWorkUpToThisPoint()

virtual void ne::Renderer::waitForGpuToFinishWorkUpToThisPoint ( )
pure virtual

Blocks the current thread until the GPU finishes executing all queued graphics commands up to this point.

Remarks
Typically used while getRenderResourcesMutex is locked.

Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.

Member Data Documentation

◆ bIsWindowMinimized

bool ne::Renderer::bIsWindowMinimized = false
private

true if framebuffer size is zero, false otherwise.

◆ iRecommendedSwapChainBufferCount

constexpr unsigned int ne::Renderer::iRecommendedSwapChainBufferCount = 2
staticconstexprprivate

The number of buffers/images in swap chain that we prefer to use.

◆ maxDepth

constexpr float ne::Renderer::maxDepth = 1.0F
staticconstexprprivate

Maximum value for depth.

◆ meshesInFrustumLastFrame

MeshesInFrustum ne::Renderer::meshesInFrustumLastFrame
private

Meshes that were in camera's frustum last frame.

◆ minDepth

constexpr float ne::Renderer::minDepth = 0.0F
staticconstexprprivate

Minimum value for depth.

◆ mtxFrameConstants

std::pair<std::mutex, FrameConstants> ne::Renderer::mtxFrameConstants
private

Up to date frame-global constant data.

◆ mtxRenderSettings

std::pair<std::recursive_mutex, std::unique_ptr<RenderSettings> > ne::Renderer::mtxRenderSettings
private

Render setting object that configures the renderer. Must be used with mutex.

◆ mtxRwRenderResources

std::recursive_mutex ne::Renderer::mtxRwRenderResources
private

Lock when reading or writing to render resources. Usually used with waitForGpuToFinishWorkUpToThisPoint.

◆ mtxShaderConfiguration

std::pair<std::recursive_mutex, std::unique_ptr<ShaderConfiguration> > ne::Renderer::mtxShaderConfiguration
private

A bunch of shader macros that match renderer's configuration (render settings). Must be used with mutex.

◆ mtxSpawnedEnvironmentNode

std::pair<std::mutex, EnvironmentNode*> ne::Renderer::mtxSpawnedEnvironmentNode
private

Spawned environment node which parameters are used in the rendering.

◆ pFrameResourcesManager

std::unique_ptr<FrameResourcesManager> ne::Renderer::pFrameResourcesManager
private

Stores frame-specific GPU resources.

◆ pGameManager

GameManager* ne::Renderer::pGameManager = nullptr
private

Do not delete (free) this pointer. Game manager object that owns this renderer.

◆ pLightingShaderResourceManager

std::unique_ptr<LightingShaderResourceManager> ne::Renderer::pLightingShaderResourceManager
private

Stores data of all spawned light sources that is used in shaders.

◆ pPipelineManager

std::unique_ptr<PipelineManager> ne::Renderer::pPipelineManager
private

Used to store various graphics and compute pipelines.

◆ pResourceManager

std::unique_ptr<GpuResourceManager> ne::Renderer::pResourceManager
private

Used to create various GPU resources.

◆ pShaderCpuWriteResourceManager

std::unique_ptr<ShaderCpuWriteResourceManager> ne::Renderer::pShaderCpuWriteResourceManager
private

Stores all shader resources with CPU write access.

◆ pShaderManager

std::unique_ptr<ShaderManager> ne::Renderer::pShaderManager
private

Used to compile shaders.

◆ pShaderTextureResourceManager

std::unique_ptr<ShaderTextureResourceManager> ne::Renderer::pShaderTextureResourceManager
private

Stores all shader resources that reference textures.

◆ renderStats

RenderStatistics ne::Renderer::renderStats
private

Various statistics about rendering.


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