10#include "evan/ADeviceBackend.hpp"
11#include "evan/DeviceContext.hpp"
12#include "evan/ASwapchainContext.hpp"
14#include "evan/Frame.hpp"
16#include "evan/FrameStats.hpp"
18#include "evan/RenderSettings.hpp"
19#include "evan/RessourceManager.hpp"
21#include "evan/GPUShader.hpp"
22#include "evan/GPUVertex.hpp"
23#include "evan/GPUMesh.hpp"
25#include "evan/RenderObject.hpp"
27#include <utility/graphic/scissor.hpp>
28#include <utility/graphic/view.hpp>
30#include <utility/logging/loggable.hpp>
31#include <utility/logging/default_logger.hpp>
62 protected utility::logging::Loggable<Renderer,
63 utility::logging::DefaultLogger>
99 Renderer(std::shared_ptr<DeviceContext> deviceContext,
348 _cullingEnabled = enabled;
358 return _cullingEnabled;
381 return _maxDrawDistance;
404 _mergeIdenticalRuns = enabled;
414 return _mergeIdenticalRuns;
429 _indirectDrawingEnabled = enabled;
439 return _indirectDrawingEnabled;
452 BlendMode blendMode = BlendMode::Opaque;
462 if (shaderID !=
other.shaderID) {
463 return shaderID <
other.shaderID;
465 return static_cast<int>(blendMode)
466 <
static_cast<int>(
other.blendMode);
505 _opaqueSortMode =
mode;
515 return _opaqueSortMode;
519 std::map<PipelineVariant, VkPipeline>
526 std::map<uint32_t, VkPipelineLayout>
625 std::map<size_t, std::shared_ptr<RenderObject>>
_objects;
639 std::optional<utility::graphic::ScissorRect>
_scissor;
653 void updateUniformBuffer(
const utility::graphic::ViewF &view,
665 void updateMultiviewUniformBuffer(
666 const std::vector<utility::graphic::ViewF> &views,
685 void recordCommandBuffer(
688 std::span<const utility::graphic::ViewF> views);
698 void reportStatsIfDue();
783 std::vector<std::shared_ptr<GPUMesh>> getMeshes()
const;
785 std::shared_ptr<RessourceManager>
801 bool _cullingEnabled =
true;
806 float _maxDrawDistance = 0.0f;
813 bool _mergeIdenticalRuns =
false;
818 bool _indirectDrawingEnabled =
false;
826 std::map<uint32_t, BlendMode> _shaderBlendModes;
831 OpaqueSortMode _opaqueSortMode = OpaqueSortMode::FrontToBack;
Represents the context for managing the swapchain in the rendering system.
Represents the device context for the engine, managing Vulkan-related resources and operations.
Frame class representing a single frame of rendering in the Vulkan application.
The Renderer class is responsible for managing the graphics pipeline, descriptor sets,...
void resetStats() noexcept
Starts a new statistics window.
std::shared_ptr< RenderObject > getObject(size_t objectID) const
Retrieves a render object from the renderer's registry.
bool isInstancingEnabled() const
Checks whether identical meshes are merged into one draw.
void destroy(VkDevice device)
Destroys the Renderer and releases associated resources.
BlendMode getShaderBlendMode(uint32_t shaderID) const
Retrieves the blend mode used for a shader.
size_t _nextObjectID
A counter to generate unique object IDs for the registered render objects. Incremented each time a ne...
const FrameStats & getStats() const noexcept
Retrieves the frame statistics of this renderer.
std::map< PipelineVariant, VkPipeline > _pipelines
std::shared_ptr< DeviceContext > _deviceContext
The device context used to create this renderer's resources.
Renderer(std::shared_ptr< DeviceContext > deviceContext, VkRenderPass renderPass, VkSampleCountFlagBits msaaSamples, std::size_t perFrameSlotCount, std::shared_ptr< RessourceManager > ressourceManager)
Constructs a Renderer object.
bool isIndirectDrawingEnabled() const
Checks whether indirect drawing is enabled.
Error drawFrame(const DeviceContext &deviceContext, ASwapchainContext &swapchainContext)
Draws a frame by recording command buffers and submitting them to the graphics queue.
void setIndirectDrawingEnabled(bool enabled)
Enables or disables indirect drawing.
static bool viewOwnsInFlightFence(std::size_t viewIndex, std::size_t viewCount) noexcept
Whether the view at viewIndex carries the in-flight fence for a submission group of viewCount views.
bool updateObject(std::shared_ptr< RenderObject > object, size_t objectID)
Updates a render object in the renderer's object registry.
float getMaxDrawDistance() const
Retrieves the maximum draw distance.
void clearScissor(void)
Clear the active scissor rectangle (restore the full extent).
FrameStats _stats
Frame statistics window (CPU phases, counters, GPU passes).
static VkRect2D clampScissor(const utility::graphic::ScissorRect &rect, VkExtent2D extent)
Clamp a scissor rectangle to a render target extent.
void setInstancingEnabled(bool enabled)
Enables or disables merging of identical meshes.
uint32_t _timestampValidBits
Number of valid bits in a GPU timestamp, cached at construction.
void setShaderBlendMode(uint32_t shaderID, BlendMode blendMode)
Overrides the blend mode used for a shader.
VkDescriptorPool getDescriptorPool() const
Retrieves the Vulkan descriptor pool associated with the Renderer.
std::map< uint32_t, VkPipelineLayout > _pipelineLayouts
bool removeObject(size_t objectID)
Removes a render object from the renderer's registry.
void setMaxDrawDistance(float maxDistance)
Sets the maximum draw distance for distance culling.
const std::vector< VkBuffer > getUniformBuffers() const
Retrieves the Vulkan descriptor set layout associated with the Renderer.
std::optional< utility::graphic::ScissorRect > _scissor
The active scissor rectangle, in framebuffer pixels.
VkDescriptorPool _descriptorPool
Vulkan descriptor pool used for allocating descriptor sets.
OpaqueSortMode getOpaqueSortMode() const
Retrieves the ordering strategy used for opaque draws.
void setOpaqueSortMode(OpaqueSortMode mode)
Sets the ordering strategy used for opaque draws.
std::vector< std::shared_ptr< Frame > > _frames
A collection of frames used for rendering.
uint32_t _currentFrameIndex
The index of the current frame being rendered.
VkDescriptorSetLayout _descriptorSetLayout
Vulkan descriptor set layout used for rendering operations.
void setScissor(const utility::graphic::ScissorRect &rect)
Set the scissor (clip) rectangle applied when recording.
std::map< size_t, std::shared_ptr< RenderObject > > _objects
The registry of render objects owned by the renderer.
void setCullingEnabled(bool enabled)
Enables or disables frustum and distance culling.
float _timestampPeriod
Nanoseconds per GPU timestamp tick, cached at construction.
size_t addObject(std::shared_ptr< RenderObject > object)
Registers a render object in the renderer's object registry.
bool isCullingEnabled() const
Checks whether culling is currently enabled.
VkDescriptorSetLayout getDescriptorSetLayout() const
Retrieves the Vulkan descriptor set layout associated with the Renderer.
Per-frame instrumentation data (CPU phases and counters).
void resetWindow() noexcept
Starts a new report window.
Identifies one graphics pipeline variant.
bool operator<(const PipelineVariant &other) const
Orders variants so they can be stored in a std::map.
Small result wrapper used by helpers that must return both a status and a value (e....