NAP
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
RenderService Class Reference

#include <renderservice.h>

Classes

struct  Pipeline
 

Public Types

using SortFunction = std::function< void(std::vector< RenderableComponentInstance * > &, const glm::mat4 &viewMatrix)>
 
using VulkanObjectDestructor = std::function< void(RenderService &)>
 
using RenderCommand = std::function< void(RenderService &)>
 

Public Member Functions

 RenderService (ServiceConfiguration *configuration)
 
virtual ~RenderService ()
 
void beginFrame ()
 
void endFrame ()
 
bool beginHeadlessRecording ()
 
void endHeadlessRecording ()
 
void queueHeadlessCommand (const RenderCommand &command)
 
void queueComputeCommand (const RenderCommand &command)
 
bool beginRecording (RenderWindow &renderWindow)
 
void endRecording ()
 
bool beginComputeRecording ()
 
void endComputeRecording ()
 
void renderObjects (IRenderTarget &renderTarget, CameraComponentInstance &camera, RenderMask renderMask=mask::all)
 
void renderObjects (IRenderTarget &renderTarget, CameraComponentInstance &camera, const SortFunction &sortFunction, RenderMask=mask::all)
 
void renderObjects (IRenderTarget &renderTarget, CameraComponentInstance &camera, const std::vector< RenderableComponentInstance * > &comps, RenderMask renderMask=mask::all)
 
void renderObjects (IRenderTarget &renderTarget, CameraComponentInstance &camera, const std::vector< RenderableComponentInstance * > &comps, const SortFunction &sortFunction, RenderMask renderMask=mask::all)
 
void renderObjects (IRenderTarget &renderTarget, const glm::mat4 &projection, const glm::mat4 &view, const std::vector< RenderableComponentInstance * > &comps, const SortFunction &sortFunction, RenderMask renderMask=mask::all)
 
void computeObjects (const std::vector< ComputeComponentInstance * > &comps)
 
std::vector< RenderableComponentInstance * > filterObjects (const std::vector< RenderableComponentInstance * > &comps, RenderMask renderMask)
 
bool addWindow (RenderWindow &window, utility::ErrorState &errorState)
 
void removeWindow (RenderWindow &window)
 
RenderWindowfindWindow (void *nativeWindow) const
 
RenderWindowfindWindow (uint id) const
 
int getDisplayCount () const
 
const DisplayfindDisplay (int index) const
 
const DisplayfindDisplay (const nap::RenderWindow &window) const
 
const DisplayListgetDisplays () const
 
void addEvent (WindowEventPtr windowEvent)
 
RenderableMesh createRenderableMesh (IMesh &mesh, MaterialInstance &materialInstance, utility::ErrorState &errorState)
 
Pipeline getOrCreatePipeline (const IRenderTarget &renderTarget, const IMesh &mesh, const MaterialInstance &materialInstance, utility::ErrorState &errorState)
 
Pipeline getOrCreateComputePipeline (const ComputeMaterialInstance &computeMaterialInstance, utility::ErrorState &errorState)
 
Pipeline getOrCreatePipeline (const IRenderTarget &renderTarget, const RenderableMesh &renderableMesh, utility::ErrorState &errorState)
 
void queueVulkanObjectDestructor (const VulkanObjectDestructor &function)
 
DescriptorSetCachegetOrCreateDescriptorSetCache (VkDescriptorSetLayout layout)
 
VmaAllocator getVulkanAllocator () const
 
bool isHeadlessCommandQueued () const
 
bool isComputeCommandQueued () const
 
bool isHeadless () const
 
VkCommandBuffer getCurrentCommandBuffer ()
 
RenderWindowgetCurrentRenderWindow ()
 
VkInstance getVulkanInstance () const
 
VkPhysicalDevice getPhysicalDevice () const
 
const VkPhysicalDeviceFeatures & getPhysicalDeviceFeatures () const
 
uint32 getPhysicalDeviceVersion () const
 
const VkPhysicalDeviceProperties & getPhysicalDeviceProperties () const
 
VkDevice getDevice () const
 
VkSampleCountFlagBits getMaxRasterizationSamples () const
 
glm::uvec3 getMaxComputeWorkGroupSize () const
 
bool getRasterizationSamples (ERasterizationSamples requestedSamples, VkSampleCountFlagBits &outSamples, nap::utility::ErrorState &errorState)
 
bool sampleShadingSupported () const
 
bool anisotropicFilteringSupported () const
 
bool getWideLinesSupported () const
 
bool getNonSolidFillSupported () const
 
bool getPolygonModeSupported (EPolygonMode mode)
 
bool getLargePointsSupported () const
 
bool getHighDPIEnabled () const
 
uint32 getAnisotropicSamples () const
 
VkFormat getDepthFormat () const
 
VkCommandPool getCommandPool () const
 
VkImageAspectFlags getDepthAspectFlags () const
 
uint32 getQueueIndex () const
 
VkQueue getQueue () const
 
bool isComputeAvailable () const
 
Texture2DgetEmptyTexture2D () const
 
TextureCubegetEmptyTextureCube () const
 
Texture2DgetErrorTexture2D () const
 
TextureCubegetErrorTextureCube () const
 
RenderMask getRenderMask (const RenderTag &renderTag) const
 
RenderMask getRenderMask (const std::string &tagName)
 
MaterialgetOrCreateMaterial (rtti::TypeInfo shaderType, utility::ErrorState &error)
 
template<typename T >
MaterialgetOrCreateMaterial (utility::ErrorState &error)
 
int getCurrentFrameIndex () const
 
int getMaxFramesInFlight () const
 
void getFormatProperties (VkFormat format, VkFormatProperties &outProperties) const
 
bool isRenderingFrame () const
 
uint32 getVulkanVersion () const
 
uint32 getVulkanVersionMajor () const
 
uint32 getVulkanVersionMinor () const
 
bool initShaderCompilation (utility::ErrorState &error)
 
bool isInitialized () const
 
void waitForFence (int frameIndex)
 
int getRank (const nap::RenderLayer &layer) const
 
- Public Member Functions inherited from Service
UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

Public Attributes

nap::Signal< nap::RenderWindow & > windowAdded
 
nap::Signal< nap::RenderWindow & > windowRemoved
 

Protected Member Functions

virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
virtual bool init (nap::utility::ErrorState &errorState) override
 
virtual void preShutdown () override
 
virtual void shutdown () override
 
virtual void preResourcesLoaded () override
 
virtual void postResourcesLoaded () override
 
virtual void update (double deltaTime) override
 
- Protected Member Functions inherited from Service
virtual void registerObjectCreators (rtti::Factory &factory)
 
virtual void created ()
 
virtual void preUpdate (double deltaTime)
 
virtual void postUpdate (double deltaTime)
 
template<typename SERVICE_CONFIG >
SERVICE_CONFIG * getConfiguration ()
 
template<typename SERVICE_CONFIG >
const SERVICE_CONFIG * getConfiguration () const
 
std::string getIniFilePath () const
 
std::string getIniFilePath (const std::string &appendix) const
 

Description

Main interface for Vulkan Render (2D/3D) and Vulkan Compute operations.

This service initializes the Vulkan back-end and provides an interface to render objects to a specific target (screen or back-buffer). The service is shut down automatically on exit, and destroys all left over resources. When rendering geometry the service automatically sorts your selection based on the blend mode of the material. Opaque objects are rendered front to back, alpha blended objects are rendered back to front.

By default headless rendering is turned off. This means Vulkan is setup to display the result of a render operation in a nap::RenderWindow, next to a nap::RenderTarget. This requires a display device to be connected to the system. Enable headless rendering when you do NOT want to render to a window or when there is no display attached to the system. This in turn forbids the use of a nap::RenderWindow inside your application.

When headless rendering is enabled, the engine will be initialized without surface and swapchain support, which are required by a nap::RenderWindow to display images on screen. You can therefore only render to a nap::RenderTarget when Headless rendering is enabled.

Turn headless rendering on / off using the nap::RenderServiceConfiguration.

The service creates a Vulkan 1.0 instance by default, but applications may use Vulkan 1.1 and 1.2 functionality if required. Make sure to set the required major and minor Vulkan version accordingly using the RenderServiceConfiguration. The application will not start if the device does not support the selected (and therefore required) version of Vulkan.

The following Vulkan device extensions are always required: VK_KHR_MAINTENANCE1_EXTENSION. When rendering to a window, the VK_KHR_SWAPCHAIN_EXTENSION is also required. Additional extension can be specified using the nap::RenderServiceConfiguration.

The system will try to load the requested validation layers in debug mode only. Use the RenderServiceConfiguration to specify which layers the Vulkan loader should attempt to load. A warning is issued when the validation layer can't be located or loaded. Validation layers are disabled in release mode.

For more information on setting up validation layers refer to: https://vulkan.lunarg.com/doc/view/1.2.131.2/windows/layer_configuration.html

On initialization the service will try to choose a physical device based on the preferred GPU type. If no compatible GPU is found (even a not-preferred one) the system will fail to initialize. Most dedicated and integrated GPUs are supported.

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

Member Typedef Documentation

◆ RenderCommand

using RenderCommand = std::function<void(RenderService&)>

◆ SortFunction

using SortFunction = std::function<void(std::vector<RenderableComponentInstance*>&, const glm::mat4& viewMatrix)>

◆ VulkanObjectDestructor

using VulkanObjectDestructor = std::function<void(RenderService&)>

Constructor & Destructor Documentation

◆ RenderService()

RenderService ( ServiceConfiguration configuration)

Creates the service together with the provided configuration settings.

Parameters
configurationrender engine configuration.

◆ ~RenderService()

virtual ~RenderService ( )
virtual

Member Function Documentation

◆ addEvent()

void addEvent ( WindowEventPtr  windowEvent)

Add a window event that is processed later, ownership is transferred here. The window number in the event is used to find the right render window to forward the event to.

Parameters
windowEventthe window event to add.

◆ addWindow()

bool addWindow ( RenderWindow window,
utility::ErrorState errorState 
)

Add a new window as target to the render engine.

Parameters
windowthe window to add as a valid render target
errorStatecontains the error message if the window could not be added

◆ anisotropicFilteringSupported()

bool anisotropicFilteringSupported ( ) const

Returns if anisotropic filtering is supported

Returns
if anisotropic filtering is supported

◆ beginComputeRecording()

bool beginComputeRecording ( )

Starts a compute operation. Records any queued compute render commands. Call this when you want to start recording general purpose computate operations to the compute queue. Always call RenderService::endComputeRecording() afterwards, on success. Must be called before any (headless) rendering has been recorded in the current frame.

mRenderService->beginFrame();
if (mRenderService->beginComputeRecording())
{
...
mRenderService->endComputeRecording();
}
...
mRenderService->endFrame();
Returns
if the compute record operation started successfully.

◆ beginFrame()

void beginFrame ( )

Tells the system you are about to render a new frame. The system might wait until all commands issued previously, associated with the same frame handle (fence), have been processed. Multiple frames are in flight at the same time, but if the graphics load is heavy, the system might wait here to ensure resources are available. Pending upload requests are executed. Previously issued download requests are checked for completion. Queued resources that are out of scope are destroyed.

Call this function at the beginning of the render loop, before any RenderService::beginRecording() calls. Make sure to call RenderService::endFrame() after all recording operations are finished, at the end of the render loop.

mRenderService->beginFrame();
if (mRenderService->beginRecording(*mRenderWindow))
{
...
mRenderService->endRecording();
}
mRenderService->endFrame();

◆ beginHeadlessRecording()

bool beginHeadlessRecording ( )

Starts a headless render operation. Records any queued headless render commands. Call this when you want to render objects to a render-target instead of a render window. Make sure to call RenderService::endHeadlessRecording() afterwards.

mRenderService->beginFrame();
if (mRenderService->beginHeadlessRecording())
{
...
mRenderService->endHeadlessRecording();
}
mRenderService->endFrame();
Returns
if the headless record operation started successfully.

◆ beginRecording()

bool beginRecording ( RenderWindow renderWindow)

Starts a window render operation. Call this when you want to render geometry to a render window. Always call RenderService::endRecording() afterwards, on success.

mRenderService->beginFrame();
if (mRenderService->beginRecording(*mRenderWindow))
{
...
mRenderService->endRecording();
}
mRenderService->endFrame();
Returns
if the window record operation started successfully.

◆ computeObjects()

void computeObjects ( const std::vector< ComputeComponentInstance * > &  comps)

Calls onCompute() on a specific set of compute component instances, in the order specified.

Parameters
compsthe compute components to call onCompute

◆ createRenderableMesh()

RenderableMesh createRenderableMesh ( IMesh mesh,
MaterialInstance materialInstance,
utility::ErrorState errorState 
)

Creates a renderable mesh, that represents the coupling between a mesh and material, that can be rendered to screen. Internally the renderable mesh manages a vertex array object that is issued by the render service. This function should be called from on initialization of components that work with meshes and materials: ie: all types of RenderableComponent. The result should be validated by calling RenderableMesh.isValid(). Invalid mesh / material representations can't be rendered together.

Parameters
meshThe mesh that is used in the mesh-material combination.
materialInstanceThe material instance that is used in the mesh-material combination.
errorStateIf this function returns an invalid renderable mesh, the error state contains error information.
Returns
A RenderableMesh object that can be used in setMesh calls. Check isValid on the object to see if creation succeeded or failed.

◆ endComputeRecording()

void endComputeRecording ( )

Ends a compute operation, submits the recorded compute command buffer to the compute queue. Always call this function after a successful call to nap::RenderService::beginComputeRecording().

mRenderService->beginFrame();
if (mRenderService->beginComputeRecording(*mRenderWindow))
{
...
mRenderService->endComputeRecording();
}
...
mRenderService->endFrame();

◆ endFrame()

void endFrame ( )

Tells the system you finished rendering into the frame. Always call this at the end of the render() loop, after RenderService::beginFrame(). Failure to properly end the frame will result in a system freeze. Any pending download requests are pushed onto the command buffer.

mRenderService->beginFrame();
if (mRenderService->beginRecording(*mRenderWindow))
{
...
mRenderService->endRecording();
}
mRenderService->endFrame();

◆ endHeadlessRecording()

void endHeadlessRecording ( )

Ends a headless render operation, submits the recorded command buffer to the queue. Always call this function after a successful call to nap::RenderService::beginHeadlessRecording().

mRenderService->beginFrame();
if (mRenderService->beginHeadlessRecording())
{
...
mRenderService->endHeadlessRecording();
}
mRenderService->endFrame();

◆ endRecording()

void endRecording ( )

Ends a window render operation, submits the recorded command buffer to the queue. Always call this function after a successful call to nap::RenderService::beginRecording().

mRenderService->beginFrame();
if (mRenderService->beginRecording(*mRenderWindow))
{
...
mRenderService->endRecording();
}
mRenderService->endFrame();

◆ filterObjects()

std::vector<RenderableComponentInstance*> filterObjects ( const std::vector< RenderableComponentInstance * > &  comps,
RenderMask  renderMask 
)

Filters list of renderable components with the specified render mask.

Parameters
compsthe render components to filter
renderMaskthe render mask used to filter
Returns
a list of filtered objects

◆ findDisplay() [1/2]

const Display* findDisplay ( const nap::RenderWindow window) const

Returns the display that contains the center of the window.

Returns
display that contains the center of the window, nullptr if not found

◆ findDisplay() [2/2]

const Display* findDisplay ( int  index) const

Find a display based on the index provided. Note that changes to display configuration are not considered when application is running.

Parameters
indexthe number of the display to find
Returns
the display, nullptr if not found

◆ findWindow() [1/2]

RenderWindow* findWindow ( uint  id) const

Find a RenderWindow based on a window number.

Parameters
idthe number of the window to find.
Returns
the window, nullptr if not found

◆ findWindow() [2/2]

RenderWindow* findWindow ( void *  nativeWindow) const

Find a RenderWindowResource by its native handle

Parameters
nativeWindowthe native window handle (i.e. the SDL_Window pointer)
Returns
the render window associated with the native window

◆ getAnisotropicSamples()

uint32 getAnisotropicSamples ( ) const

Returns the (system default) number of anisotropic filter samples. The output is always 1 when anisotropic filtering is not supported.

Returns
system default number of max anisotropic filter samples.

◆ getCommandPool()

VkCommandPool getCommandPool ( ) const

Returns a handle to the Vulkan command pool object. Command pools are opaque objects that command buffer memory is allocated from.

Returns
handle to the Vulkan command pool object.

◆ getCurrentCommandBuffer()

VkCommandBuffer getCurrentCommandBuffer ( )

Returns the command buffer that is being recorded. Every window records into it's own command buffer. All headless render operations share the same command buffer. The current command buffer is set after nap::beginHeadlessRecording() or nap::beginRecording(RenderWindow&) and only valid until the recording operation is ended.

Returns
the command buffer that is being recorded.

◆ getCurrentFrameIndex()

int getCurrentFrameIndex ( ) const

Returns the index of the frame that is currently rendered. This index controls which command buffer is recorded and is therefore capped to the max number of images in flight.

Returns
index of the currently rendered frame.

◆ getCurrentRenderWindow()

RenderWindow* getCurrentRenderWindow ( )

Returns the window that is being rendered to, only valid between a successfull call to: RenderService::beginRecording() and RenderService::endRecording().

Returns
the window currently being rendered to, nullptr if not set.

◆ getDependentServices()

virtual void getDependentServices ( std::vector< rtti::TypeInfo > &  dependencies)
overrideprotectedvirtual

Register dependencies, render module depends on scene

Reimplemented from Service.

◆ getDepthAspectFlags()

VkImageAspectFlags getDepthAspectFlags ( ) const
Returns
flags that specify which depth aspects of an image are included in a view.

◆ getDepthFormat()

VkFormat getDepthFormat ( ) const

Returns the selected and currently in use depth format.

Returns
the currently selected and in use depth format.

◆ getDevice()

VkDevice getDevice ( ) const

Returns the handle to the logical Vulkan device, represents the hardware together with the extensions, selected queue and features enabled for it.

Returns
The logical Vulkan device.

◆ getDisplayCount()

int getDisplayCount ( ) const

Returns the total number of displays. Note that changes to display configuration are not considered when application is running.

Returns
total number of displays

◆ getDisplays()

const DisplayList& getDisplays ( ) const
Returns
all available displays

◆ getEmptyTexture2D()

Texture2D& getEmptyTexture2D ( ) const

Returns an empty 2D texture that is available on the GPU for temporary binding or storage.

Returns
empty texture that is available on the GPU.

◆ getEmptyTextureCube()

TextureCube& getEmptyTextureCube ( ) const

Returns an error cube texture that can be bound to materials to signal an application warning or error.

Returns
the error cube texture.

◆ getErrorTexture2D()

Texture2D& getErrorTexture2D ( ) const

Returns an error 2D texture that can be bound to materials to signal an application warning or error.

Returns
the error 2D texture.

◆ getErrorTextureCube()

TextureCube& getErrorTextureCube ( ) const

Returns an empty cube texture that is available on the GPU for temporary binding or storage.

Returns
empty texture that is available on the GPU.

◆ getFormatProperties()

void getFormatProperties ( VkFormat  format,
VkFormatProperties &  outProperties 
) const

Returns the physical device properties for the requested Vulkan format.

Returns
physical device properties for the requested Vulkan format.

◆ getHighDPIEnabled()

bool getHighDPIEnabled ( ) const

Configurable setting. When enabled fonts and general scaling is adjusted for high dpi monitors.

Returns
if high dpi mode is enabled

◆ getLargePointsSupported()

bool getLargePointsSupported ( ) const

Returns if rendering large points is supported.

Returns
if rendering large points is supported.

◆ getMaxComputeWorkGroupSize()

glm::uvec3 getMaxComputeWorkGroupSize ( ) const

Returns the max compute shader workgroup size.

Returns
the max compute shader workgroup size.

◆ getMaxFramesInFlight()

int getMaxFramesInFlight ( ) const

Returns the max number of frames in flight. If there is only 1 frame in flight the application will stall until it is rendered. Having multiple frames in flight at once allows the render engine to start on a new frame without having to wait on the previous one to finish.

Increasing the number of frames in flight does however have a negative impact on resource usage, because every frame requires its own unique set of command buffers, descriptor sets etc. 2 is therefore a good number, where 3 offers only, in most situations, a slight increase in performance. This however greatly depends on the application GPU and CPU load.

◆ getMaxRasterizationSamples()

VkSampleCountFlagBits getMaxRasterizationSamples ( ) const

Returns the max number of hardware supported rasterization samples.

Returns
the max number of rasterization samples supported by the hardware.

◆ getNonSolidFillSupported()

bool getNonSolidFillSupported ( ) const

Returns if point and wire-frame rasterization fill modes are supported.

Returns
if point and wire-frame rasterization fill modes are supported

◆ getOrCreateComputePipeline()

Pipeline getOrCreateComputePipeline ( const ComputeMaterialInstance computeMaterialInstance,
utility::ErrorState errorState 
)

Returns a Vulkan compute pipeline for the given compute material. Internally pipelines are cached, a new compute pipeline is created when a new compute material is encountered. Because of this, initial frames are slower to render, until all compute materials are cached and returned from the pool. Pipeline creation is considered to be a heavy operation, take this into account when designing your application.

Use this function inside nap::ComputeComponentInstance::onCompute() to find the right pipeline before dispatching a compute shader.

RenderService::Pipeline pipeline = mRenderService->getOrCreateComputePipeline(compute_material_instance, error_state);
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline.mPipeline);
Parameters
computeMaterialInstancethe compute material instance
errorStatecontains the error if the pipeline can't be created
Returns
new or cached compute pipeline.

◆ getOrCreateDescriptorSetCache()

DescriptorSetCache& getOrCreateDescriptorSetCache ( VkDescriptorSetLayout  layout)

Returns a descriptor set cache based on the given layout. The cache is used to acquire descriptor sets.

Parameters
layoutthe descriptor set layout to create the cache for.
Returns
descriptor set cache for the given layout.

◆ getOrCreateMaterial() [1/2]

Material* getOrCreateMaterial ( rtti::TypeInfo  shaderType,
utility::ErrorState error 
)

Returns an existing or new material for the given type of shader that can be shared. This only works for hard coded shader types that can be initialized without input arguments. If initialization or creation fails, the result is cached but invalid. Use the material as a template for a material instance.

mRenderService->getOrCreateMaterial(RTTI_OF(nap::FontShader), error);
Parameters
shaderTypetype of shader to get material for.
errorcontains the error if the material could not be created or initialized.
Returns
new or existing material for the given shader type, nullptr if creation or initialization failed.

◆ getOrCreateMaterial() [2/2]

Material* getOrCreateMaterial ( utility::ErrorState error)

Returns an existing or new material for the given type of shader T that can be shared. This only works for hard coded shader types that can be initialized without input arguments. If initialization or creation fails, the result is cached but invalid. Use the material as a template for a material instance.

mRenderService->getOrCreateMaterial<nap::FontShader>(error);
Parameters
errorcontains the error if the material could not be created or initialized.
Returns
new or existing material for the given shader type, nullptr if creation or initialization failed.

◆ getOrCreatePipeline() [1/2]

Pipeline getOrCreatePipeline ( const IRenderTarget renderTarget,
const IMesh mesh,
const MaterialInstance materialInstance,
utility::ErrorState errorState 
)

Returns a Vulkan pipeline for the given render target, mesh and material combination. Internally pipelines are cached, a new pipeline is created when a new combination is encountered. Because of this, initial frames are slower to render, until all combinations are cached and returned from the pool. Pipeline creation is considered to be a heavy operation, take this into account when designing your application.

Use this function inside nap::RenderableComponentInstance::onDraw() to find the right pipeline before rendering.

RenderService::Pipeline pipeline = mRenderService->getOrCreatePipeline(target, mesh, mat_instance, error_state);
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.mPipeline);
Parameters
renderTargettarget that is rendered too.
meshthe mesh that is drawn.
materialInstancethe material applied to the mesh.
errorStatecontains the error if the pipeline can't be created
Returns
new or cached pipeline.

◆ getOrCreatePipeline() [2/2]

Pipeline getOrCreatePipeline ( const IRenderTarget renderTarget,
const RenderableMesh renderableMesh,
utility::ErrorState errorState 
)

Returns a Vulkan pipeline for the given render target and Renderable-mesh combination. Internally pipelines are cached, a new pipeline is created when a new combination is encountered. Because of this initial frames are slower to render, until all combinations are cached and returned from the pool. Pipeline creation is considered to be a heavy operation, take this into account when designing your application.

Use this function inside nap::RenderableComponentInstance::onDraw() to find the right pipeline before rendering.

RenderService::Pipeline pipeline = mRenderService->getOrCreatePipeline(target, render_mesh, error_state);
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.mPipeline);
Parameters
renderTargettarget that is rendered too.
renderableMeshthe mesh / material combination that is rendered
errorStatecontains the error if the pipeline can't be created
Returns
new or cached pipeline.

◆ getPhysicalDevice()

VkPhysicalDevice getPhysicalDevice ( ) const

Returns the physical device (GPU) that is used for all render operations. Multiple physical devices are not supported.

Returns
Selected Vulkan hardware (GPU) device

◆ getPhysicalDeviceFeatures()

const VkPhysicalDeviceFeatures& getPhysicalDeviceFeatures ( ) const

Returns all supported physical device (GPU) features.

Returns
all supported hardware features

◆ getPhysicalDeviceProperties()

const VkPhysicalDeviceProperties& getPhysicalDeviceProperties ( ) const

All physical device hardware properties.

Returns
all hardware properties

◆ getPhysicalDeviceVersion()

uint32 getPhysicalDeviceVersion ( ) const

Returns the Vulkan api version, as supported by the physical device. Note that this is not the same as the api version used by the render engine. The physical device needs to support the min required api version requested by the render engine, but could be higher.

Returns
the version of Vulkan supported by the device

◆ getPolygonModeSupported()

bool getPolygonModeSupported ( EPolygonMode  mode)

Checks if the selected polygon mode is supported by current selected device.

Parameters
modethe mode to check.

◆ getQueue()

VkQueue getQueue ( ) const

Returns the selected queue, used to execute recorded command buffers. The queue must support Graphics and Transfer operations.

Returns
the queue that is used to execute recorded command buffers.

◆ getQueueIndex()

uint32 getQueueIndex ( ) const

Returns the index of the selected queue family.

Returns
the main queue index.

◆ getRank()

int getRank ( const nap::RenderLayer layer) const

Returns the rank of the given layer in the render chain. Asserts and returns RenderChain::invalidRank if the rank is not registered. The rank controls the order in which objects are rendered.

Parameters
layerthe layer to get the rank index for
Returns
the rank index of the given layer in the render chain, -1 if rank is not registered

◆ getRasterizationSamples()

bool getRasterizationSamples ( ERasterizationSamples  requestedSamples,
VkSampleCountFlagBits &  outSamples,
nap::utility::ErrorState errorState 
)

Returns max supported rasterization samples based on the requested number of samples. The output is automatically clamped if the requested number of samples exceeds the hardware limit.

Returns
if requested number of samples is supported by hardware.
Parameters
requestedSamplesrequested number of samples.
outSamplessupported number of samples.
errorStatecontains the error if requested number of samples is not supported by the hardware.

◆ getRenderMask() [1/2]

RenderMask getRenderMask ( const RenderTag renderTag) const

Returns the render mask for the given tag.

Returns
The render mask associated with the given tag.

◆ getRenderMask() [2/2]

RenderMask getRenderMask ( const std::string &  tagName)

Returns the render mask for the given render tag name, 0 if no match is found.

Parameters
tagNamename of the render tag
Returns
The render mask for the associated tag name, 0 if there is no match.

◆ getVulkanAllocator()

VmaAllocator getVulkanAllocator ( ) const
Returns
main Vulkan allocator

◆ getVulkanInstance()

VkInstance getVulkanInstance ( ) const

Returns the Vulkan runtime instance.

Returns
Vulkan runtime instance.

◆ getVulkanVersion()

uint32 getVulkanVersion ( ) const

Returns the api version used to create the Vulkan instance. Note that the physical device is required to support at least that version.

Returns
The api version used to create the Vulkan instance.

◆ getVulkanVersionMajor()

uint32 getVulkanVersionMajor ( ) const

Returns the major api version used to create the Vulkan instance. The vulkan instance is created using a combination of the major and minor api version. Note that the physical device is required to support at least that version.

Returns
Vulkan major api version

◆ getVulkanVersionMinor()

uint32 getVulkanVersionMinor ( ) const

Returns the minor api version used to create the Vulkan instance. The vulkan instance is created using a combination of the major and minor api version. Note that the physical device is required to support at least that version.

Returns
Vulkan minor api version

◆ getWideLinesSupported()

bool getWideLinesSupported ( ) const

Returns if wide line rendering is supported, if so you can use a line width higher than 1.

Returns
if wide line rendering is supported.

◆ init()

virtual bool init ( nap::utility::ErrorState errorState)
overrideprotectedvirtual

Initialize the renderer, the service owns the renderer.

Parameters
errorStatecontains the error message if the service could not be initialized
Returns
if the service has been initialized successfully

Reimplemented from Service.

◆ initShaderCompilation()

bool initShaderCompilation ( utility::ErrorState error)

Initializes GLSL shader compilation and linking. Don't call this in your application! Only required by external processes that want to use the nap render interface.

Parameters
errorcontains the error if initialization fails
Returns
if shader compiler and linker initialized successfully

◆ isComputeAvailable()

bool isComputeAvailable ( ) const

Returns true if the selected device has compute capability, else returns false.

Returns
if the selected device has compute capability

◆ isComputeCommandQueued()

bool isComputeCommandQueued ( ) const
Returns
whether there are compute render commands in the queue

◆ isHeadless()

bool isHeadless ( ) const

Returns if the render engine runs headless. This allows you to render images without any display device. This in turn means that when enabled it is not possible to display (present) images to a window.

Returns
if the render engine runs headless.

◆ isHeadlessCommandQueued()

bool isHeadlessCommandQueued ( ) const
Returns
whether there are headless render commands in the queue

◆ isInitialized()

bool isInitialized ( ) const

Returns if the render service is running, a non operational render service is in an undefined state and can therefore not be queried

Returns
if the render service is initialized and therefore running

◆ isRenderingFrame()

bool isRenderingFrame ( ) const

Returns if the render service is currently recording (rendering) a frame. Returns true in between start and end frame calls, otherwise false. If that is the case, certain operations are not allowed. For example: data upload / download operations to and from the GPU are forbidden.

Returns
if the render service is currently recording a frame.

◆ postResourcesLoaded()

virtual void postResourcesLoaded ( )
overrideprotectedvirtual

Invoked when the resource manager is about to load resources.

Reimplemented from Service.

◆ preResourcesLoaded()

virtual void preResourcesLoaded ( )
overrideprotectedvirtual

Invoked when the resource manager is about to load resources.

Reimplemented from Service.

◆ preShutdown()

virtual void preShutdown ( )
overrideprotectedvirtual

Waits for the device to be idle and deletes queued resources.

Reimplemented from Service.

◆ queueComputeCommand()

void queueComputeCommand ( const RenderCommand command)

Queues a compute render command with priority in the subsequent frame. The queue is handled the next time RenderService::beginComputeRecording is called.

mRenderService->queueComputeCommand([](RenderService&){});
Parameters
commandthe command to queue, ownership is transferred

◆ queueHeadlessCommand()

void queueHeadlessCommand ( const RenderCommand command)

Queues a headless render command with priority in the subsequent frame. The queue is handled the next time RenderService::beginHeadlessRecording is called.

mRenderService->queueHeadlessCommand([](RenderService&){});
Parameters
commandthe command to queue, ownership is transferred

◆ queueVulkanObjectDestructor()

void queueVulkanObjectDestructor ( const VulkanObjectDestructor function)

Queues a function that destroys Vulkan resources when appropriate. Certain Vulkan resources, including buffers, image buffers etc. might still be in use when the NAP resource is destroyed. It is therefore necessary to queue their destruction, instead of deleting them immediately. Make sure that all resources are captured by copy, instead of reference.

mRenderService->queueVulkanObjectDestructor([buffers = mRenderBuffers](RenderService& service)
{
for (const BufferData& buffer : buffers)
{
destroyBuffer(service.getVulkanAllocator(), buffer);
}
});

◆ removeWindow()

void removeWindow ( RenderWindow window)

Remove a window as a valid target from the render engine.

Parameters
windowthe window to remove from the render service

◆ renderObjects() [1/5]

void renderObjects ( IRenderTarget renderTarget,
CameraComponentInstance camera,
const SortFunction sortFunction,
RenderMask  = mask::all 
)

Renders all available nap::RenderableComponent(s) in the scene to a specific renderTarget. The objects to render are sorted using the provided sort function. Components that can't be rendered with the given camera are omitted.

Parameters
renderTargetthe target to render to
camerathe camera used for rendering all the available components
sortFunctionThe function used to sort the components to render

◆ renderObjects() [2/5]

void renderObjects ( IRenderTarget renderTarget,
CameraComponentInstance camera,
const std::vector< RenderableComponentInstance * > &  comps,
const SortFunction sortFunction,
RenderMask  renderMask = mask::all 
)

Renders a specific set of objects to a specific renderTarget using an optional mask The objects to render are sorted using the provided sort function. Components that can't be rendered with the given camera are omitted.

Parameters
renderTargetthe target to render to
camerathe camera used for rendering all the available components
compsthe components to render to renderTarget
sortFunctionThe function used to sort the components to render
renderMaskoptional component filter mask

◆ renderObjects() [3/5]

void renderObjects ( IRenderTarget renderTarget,
CameraComponentInstance camera,
const std::vector< RenderableComponentInstance * > &  comps,
RenderMask  renderMask = mask::all 
)

Renders a specific set of objects to a specific renderTarget using an optional mask The objects to render are sorted using the default sort function (front-to-back for opaque objects, back-to-front for transparent objects) The sort function is provided by the render service itself, using the default NAP DepthSorter.

Parameters
renderTargetthe target to render to
camerathe camera used for rendering all the available components
compsthe components to render to renderTarget
renderMaskoptional component filter mask

◆ renderObjects() [4/5]

void renderObjects ( IRenderTarget renderTarget,
CameraComponentInstance camera,
RenderMask  renderMask = mask::all 
)

Renders all available nap::RenderableComponent(s) in the scene to a specific renderTarget. The objects to render are sorted using the default sort function (front-to-back for opaque objects, back-to-front for transparent objects). The sort function is provided by the render service itself, using the default NAP DepthSorter. Components that can't be rendered with the given camera are omitted.

Parameters
renderTargetthe target to render to
camerathe camera used for rendering all the available components
renderMaskthe objects to include

◆ renderObjects() [5/5]

void renderObjects ( IRenderTarget renderTarget,
const glm::mat4 &  projection,
const glm::mat4 &  view,
const std::vector< RenderableComponentInstance * > &  comps,
const SortFunction sortFunction,
RenderMask  renderMask = mask::all 
)

Renders a specific set of objects to a specific renderTarget using a specific projection and view matrix and optional mask. The objects to render are sorted using the provided sort function. Components that can't be rendered with the given camera are omitted.

Parameters
renderTargetthe target to render to
projectionthe camera projection matrix
viewthe camera view matrix
compsthe components to render to renderTarget
sortFunctionThe function used to sort the components to render
renderMaskoptional component filter mask

◆ sampleShadingSupported()

bool sampleShadingSupported ( ) const

Returns if sample shading is supported and enabled, reduces texture aliasing at computational cost.

Returns
if sample shading is supported.

◆ shutdown()

virtual void shutdown ( )
overrideprotectedvirtual

Shuts down the renderer, local Vulkan resources are destroyed.

Reimplemented from Service.

◆ update()

virtual void update ( double  deltaTime)
overrideprotectedvirtual

Process all received window events.

Parameters
deltaTimetime in seconds in between frames.

Reimplemented from Service.

◆ waitForFence()

void waitForFence ( int  frameIndex)

Wait for the fence belonging to the specified frame index. This ensures that, after the wait, all resources for that frame are no longer in use. You normally don't need to use this as all synchronization is handled for you. This function is only used by RenderWindow to ensure that the current swap chain image is no longer in use.

Parameters
frameIndexThe index of the frame to wait for

Member Data Documentation

◆ windowAdded

Called when a new window is added to the system

◆ windowRemoved

nap::Signal<nap::RenderWindow&> windowRemoved

Called just before a window is removed from the system

nap::icon::error
constexpr const char * error
Definition: imguiservice.h:55
nap::FontShader
Definition: fontshader.h:40
nap::utility::destroyBuffer
void NAPAPI destroyBuffer(VmaAllocator allocator, BufferData &buffer)
nap::RenderService::RenderService
RenderService(ServiceConfiguration *configuration)