Nameless Engine
|
#include <Renderer.h>
Classes | |
struct | LightsInFrustum |
struct | MeshesInFrustum |
Static Public Member Functions | |
static constexpr float | getMinDepth () |
static constexpr float | getMaxDepth () |
static std::variant< std::unique_ptr< Renderer >, Error > | create (GameManager *pGameManager, std::optional< RendererType > preferredRenderer) |
Protected Member Functions | |
Renderer (GameManager *pGameManager) | |
std::optional< Error > | compileEngineShaders () const |
void | updateFrameConstantsBuffer (FrameResource *pCurrentFrameResource, CameraProperties *pCameraProperties) |
void | resetGpuResourceManager () |
void | resetPipelineManager () |
void | resetFrameResourceManager () |
void | resetLightingShaderResourceManager () |
virtual std::variant< std::optional< AntialiasingQuality >, Error > | getMaxSupportedAntialiasingQuality () 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, 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< Error > | onRenderSettingsChanged (bool bShadowMapSizeChanged=false) |
virtual std::optional< Error > | onRenderSettingsChangedDerived ()=0 |
virtual void | waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource)=0 |
virtual bool | isInitialized () const =0 |
std::optional< Error > | initializeRenderer () |
std::optional< Error > | initializeResourceManagers () |
std::optional< Error > | clampSettingsToMaxSupported () |
std::optional< Error > | recalculateLightTileFrustums () |
MeshesInFrustum * | getMeshesInCameraFrustum (CameraProperties *pActiveCameraProperties, 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 ShadowMapHandle * | getPointLightNodeShadowMapHandle (PointLightNode *pNode) |
Private Member Functions | |
void | calculateFrameStatistics () |
void | updateResourcesForNextFrame (unsigned int iRenderTargetWidth, unsigned int iRenderTargetHeight, CameraProperties *pCameraProperties) |
void | onActiveCameraChanged () |
void | recalculateTargetFrameTimeFromFpsLimitSetting () |
void | setupRenderStats () |
std::optional< Error > | initializeRenderSettings () |
Static Private Member Functions | |
static std::unique_ptr< Renderer > | createRenderer (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< GpuResourceManager > | pResourceManager |
std::unique_ptr< ShaderManager > | pShaderManager |
std::unique_ptr< PipelineManager > | pPipelineManager |
std::unique_ptr< FrameResourceManager > | pFrameResourceManager |
std::unique_ptr< ShaderCpuWriteResourceBindingManager > | pShaderCpuWriteResourceManager |
std::unique_ptr< ShaderTextureResourceBindingManager > | pShaderTextureResourceManager |
std::unique_ptr< LightingShaderResourceManager > | pLightingShaderResourceManager |
std::unique_ptr< GlobalShaderResourceBindingManager > | pGlobalShaderResourceBindingManager |
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, FrameConstants > | mtxFrameConstants |
RenderStatistics | renderStats |
GameManager * | pGameManager = 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 | RenderSettings |
class | EnvironmentNode |
class | CameraManager |
Defines a base class for renderers to implement.
|
protected |
Constructor.
pGameManager | pGameManager object that owns this renderer. |
|
private |
Calculates some frame-related statistics.
|
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).
|
protected |
Compiles/verifies all essential shaders that the engine will use.
|
static |
Creates a new renderer.
pGameManager | Game manager object that will own this renderer. |
preferredRenderer | Preferred renderer to be used. |
|
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.
pGameManager | Game manager object that will own this renderer. |
preferredRenderer | Renderer to prefer to create. |
nullptr
if no renderer could be created, otherwise created renderer.
|
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.
type | Type of the renderer to create. |
pGameManager | Game manager object that will own this renderer. |
vBlacklistedGpuNames | Names of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong. |
|
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.
pActiveCameraProperties | Properties of the currently active camera. |
iCurrentFrameResourceIndex | Index of the frame resource that will be used to submit the next frame. |
|
protectedpure virtual |
Submits commands to draw meshes and the specified depth only (vertex shader only) pipelines.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
vOpaquePipelines | Opaque pipelines (depth pipeline will be retrieved from them). |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protectedpure virtual |
Submits commands to draw meshes for main (color) pass.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
vOpaquePipelines | Opaque pipelines to draw. |
vTransparentPipelines | Transparent pipelines to draw. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protected |
Submits a new frame to the GPU.
|
protectedpure virtual |
Submits commands to draw world from the perspective of all spawned light sources to capture shadow maps.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
pGraphicsPipelines | Graphics pipelines to draw. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protectedpure virtual |
Executes compute shaders of the specified stage.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
stage | Stage of compute shaders to execute. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
pure virtual |
Returns the name of the GPU that is being currently used.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
pure virtual |
Returns pointer to the texture resource that represents renderer's depth texture without multisampling (resolved resource).
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.Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
staticprotected |
Returns information needed to capture/update a shadow map for a specific node.
pNode | Directional light to update its shadow map. |
pShadowMapHandle | Shadow map handle of the specified light. |
iShadowPassLightInfoArrayIndex | Index into the array of shadow pass light infos. |
|
inlineprotected |
Returns counter for draw calls.
|
inlineprotected |
Returns frame constants.
FrameResourceManager * ne::Renderer::getFrameResourceManager | ( | ) | const |
Returns frame resource manager.
GameManager * ne::Renderer::getGameManager | ( | ) | const |
Game manager object that owns this renderer.
GlobalShaderResourceBindingManager * ne::Renderer::getGlobalShaderResourceBindingManager | ( | ) | const |
Returns manager responsible for creating global shader resource bindings.
LightingShaderResourceManager * ne::Renderer::getLightingShaderResourceManager | ( | ) | const |
Returns manager that controls GPU resources of lighting shader resources.
|
inlinestaticconstexpr |
Returns the maximum value for depth.
|
protectedpure virtual |
Returns the maximum anti-aliasing quality that can be used on the picked GPU (getCurrentlyUsedGpuName).
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protected |
Iterates over all meshes and returns only meshes inside of the camera's frustum (and their pipelines).
pActiveCameraProperties | Properties of the currently active camera. |
pGraphicsPipelines | Graphics pipelines. |
|
inlinestaticconstexpr |
Returns the minimum value for depth.
PipelineManager * ne::Renderer::getPipelineManager | ( | ) | const |
Returns pipeline manager used to store graphics and compute pipelines.
|
staticprotected |
Returns shadow map handle of the specified point light node.
pNode | Point light node. |
|
staticprotected |
Returns information needed to capture/update a shadow map for a specific node.
pNode | Point light to update its shadow map. |
iCubemapFaceIndex | Index of the cubemap to get matrix index. |
|
inlinestaticprotected |
Returns the number of swap chain buffers/images that we prefer to use.
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.
std::pair< std::recursive_mutex *, RenderSettings * > ne::Renderer::getRenderSettings | ( | ) |
Returns render settings that can be configured.
RenderStatistics * ne::Renderer::getRenderStatistics | ( | ) |
Returns various statistics about rendering (such as FPS).
|
pure virtual |
Returns size of the render target (size of the underlying render image).
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
GpuResourceManager * ne::Renderer::getResourceManager | ( | ) | const |
Returns GPU resource manager.
ShaderCpuWriteResourceBindingManager * ne::Renderer::getShaderCpuWriteResourceManager | ( | ) | const |
Returns manager of shader resources with CPU write access.
ShaderManager * ne::Renderer::getShaderManager | ( | ) | const |
Returns shader manager used to compile shaders.
ShaderTextureResourceBindingManager * ne::Renderer::getShaderTextureResourceManager | ( | ) | const |
Returns manager of shader resources that reference textures.
|
staticprotected |
Returns information needed to capture/update a shadow map for a specific node.
pNode | Spotlight to update its shadow map. |
pShadowMapHandle | Shadow map handle of the specified light. |
iShadowPassLightInfoArrayIndex | Index into the array of shadow pass light infos. |
|
pure virtual |
Looks for video adapters (GPUs) that support this renderer.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
pure virtual |
Returns a list of supported screen refresh rates (pairs of numerator and denominator).
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
pure virtual |
Returns a list of supported render resolution (pairs of width and height).
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
size_t ne::Renderer::getTotalVideoMemoryInMb | ( | ) | const |
Returns total video memory (VRAM) size in megabytes.
|
pure virtual |
Returns renderer's type.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
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.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
size_t ne::Renderer::getUsedVideoMemoryInMb | ( | ) | const |
Returns the amount of video memory (VRAM) that is currently being used by the renderer.
Window * ne::Renderer::getWindow | ( | ) | const |
Returns the window that we render to.
|
protected |
Initializes some essential parts of the renderer (such as RenderSettings).
|
private |
Initializes mtxRenderSettings.
|
protected |
Initializes various resource managers.
|
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.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
private |
Called by camera manager after active camera was changed.
|
protected |
Called when the framebuffer size was changed.
iWidth | New width of the framebuffer (in pixels). |
iHeight | New height of the framebuffer (in pixels). |
|
inlineprotectedvirtual |
Called when the framebuffer size was changed.
iWidth | New width of the framebuffer (in pixels). |
iHeight | New height of the framebuffer (in pixels). |
Reimplemented in ne::VulkanRenderer.
|
protected |
Called after some render setting is changed to recreate internal resources to match the current settings.
bShadowMapSizeChanged | true if shadow map size was changed, false otherwise. |
|
protectedpure virtual |
Called from onRenderSettingsChanged after some render setting is changed to recreate internal resources to match the current settings.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protectedpure virtual |
Setups everything for render commands to be recorded (resets command buffers and etc.).
pCameraProperties | Camera properties to use. |
pCurrentFrameResource | Frame resource of the frame being submitted. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
inlineprotectedvirtual |
Called before prepareForDrawingNextFrame to do early frame preparations.
Reimplemented in ne::VulkanRenderer.
|
protectedpure virtual |
Does the final frame rendering logic to present the frame on the screen.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
protected |
Notifies pLightingShaderResourceManager to recalculate grid of frustums for light culling process.
|
private |
Looks for FPS limit setting in RenderSettings and updates renderer's target time to render a frame.
|
protected |
Sets nullptr
to frame resource manager's unique ptr to force destroy it (if exists).
|
protected |
Sets nullptr
to resource manager's unique ptr to force destroy it (if exists).
|
protected |
Sets nullptr
to lighting shader resource manager's unique ptr to force destroy it (if exists).
|
protected |
Sets nullptr
to pipeline manager's unique ptr to force destroy it (if exists).
|
private |
Initializes renderStats to be used.
|
protected |
Takes the current frame resource and updates frame data constant buffer that it stores (by copying new (up to date) constants to it).
pCurrentFrameResource | Current frame resource. |
pCameraProperties | Camera properties to use. |
|
private |
Updates internal resources (frame constants, shader resources, camera's aspect ratio and etc.) for the next frame.
iRenderTargetWidth | Width (in pixels) of the image that will be used for the next frame. |
iRenderTargetHeight | Height (in pixels) of the image that will be used for the next frame. |
pCameraProperties | Camera properties to use. |
|
protectedpure virtual |
Blocks the current thread until the GPU is finished using the specified frame resource.
pFrameResource | Frame resource to wait for. |
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
pure virtual |
Blocks the current thread until the GPU finishes executing all queued graphics commands up to this point.
Implemented in ne::DirectXRenderer, and ne::VulkanRenderer.
|
private |
true
if framebuffer size is zero, false
otherwise.
|
staticconstexprprivate |
The number of buffers/images in swap chain that we prefer to use.
|
staticconstexprprivate |
Maximum value for depth.
|
private |
Meshes that were in camera's frustum last frame.
|
staticconstexprprivate |
Minimum value for depth.
|
private |
Up to date frame-global constant data.
|
private |
Render setting object that configures the renderer. Must be used with mutex.
|
private |
Lock when reading or writing to render resources. Usually used with waitForGpuToFinishWorkUpToThisPoint.
|
private |
Spawned environment node which parameters are used in the rendering.
|
private |
Stores frame-specific GPU resources.
|
private |
Do not delete (free) this pointer. Game manager object that owns this renderer.
|
private |
Manages all global bindings.
|
private |
Stores data of all spawned light sources that is used in shaders.
|
private |
Used to store various graphics and compute pipelines.
|
private |
Used to create various GPU resources.
|
private |
Stores all shader resources with CPU write access.
|
private |
Used to compile shaders.
|
private |
Stores all shader resources that reference textures.
|
private |
Various statistics about rendering.