Lysa  0.0
Lysa 3D Engine
Scene Class Reference

Detailed Description

Scene orchestrator.

  • Track nodes added to the scene (cameras, lights, mesh instances, environment).
  • Own GPU-side resources necessary for scene rendering (uniform buffers, descriptor sets).
  • Build and maintain per-pipeline instance data and indirect draw commands.
  • Perform frustum culling via compute pipelines and submit culled draws.
  • Manage shadow-map renderers and their images.

Thread-safety: unless stated otherwise, methods are intended to be called only from the render thread.

Classes

struct  InstanceIndexConstant
 
struct  PipelineData
 

Public Member Functions

 Scene (const SceneConfiguration &config, const RenderingConfiguration &renderingConfig, uint32 framesInFlight, const vireo::Viewport &viewport, const vireo::Rect &scissors)
 
auto getCurrentCamera () const
 
auto getViewport () const
 
auto getScissors () const
 
virtual void addNode (const std::shared_ptr< Node > &node)
 
virtual void removeNode (const std::shared_ptr< Node > &node)
 
virtual void activateCamera (const std::shared_ptr< Camera > &camera)
 
void update (const vireo::CommandList &commandList)
 
void compute (vireo::CommandList &commandList) const
 
void setInitialState (const vireo::CommandList &commandList) const
 
void drawOpaquesModels (vireo::CommandList &commandList, const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &pipelines) const
 
void drawTransparentModels (vireo::CommandList &commandList, const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &pipelines) const
 
void drawShaderMaterialModels (vireo::CommandList &commandList, const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &pipelines) const
 
void drawModels (vireo::CommandList &commandList, uint32 set, const std::map< pipeline_id, std::shared_ptr< vireo::Buffer >> &culledDrawCommandsBuffers, const std::map< pipeline_id, std::shared_ptr< vireo::Buffer >> &culledDrawCommandsCountBuffers, const std::map< pipeline_id, std::shared_ptr< FrustumCulling >> &frustumCullingPipelines) const
 
const auto & getPipelineIds () const
 
auto isMaterialsUpdated () const
 
void resetMaterialsUpdated ()
 
auto getDescriptorSet () const
 
auto getDescriptorSetOptional1 () const
 
auto getShadowMapRenderers () const
 
virtual ~Scene () = default
 
 Scene (Scene &) = delete
 
Scene & operator= (Scene &) = delete
 

Static Public Member Functions

static void createDescriptorLayouts ()
 
static void destroyDescriptorLayouts ()
 

Static Public Attributes

static constexpr uint32 MAX_SHADOW_MAPS {20}
 
static constexpr vireo::DescriptorIndex BINDING_SCENE {0}
 
static constexpr vireo::DescriptorIndex BINDING_MODELS {1}
 
static constexpr vireo::DescriptorIndex BINDING_LIGHTS {2}
 
static constexpr vireo::DescriptorIndex BINDING_SHADOW_MAPS {3}
 
static std::shared_ptr< vireo::DescriptorLayout > sceneDescriptorLayout {nullptr}
 
static constexpr vireo::DescriptorIndex BINDING_SHADOW_MAP_TRANSPARENCY_COLOR {0}
 
static std::shared_ptr< vireo::DescriptorLayout > sceneDescriptorLayoutOptional1 {nullptr}
 
static constexpr vireo::DescriptorIndex BINDING_INSTANCES {0}
 
static std::shared_ptr< vireo::DescriptorLayout > pipelineDescriptorLayout {nullptr}
 
static constexpr auto instanceIndexConstantDesc
 

Constructor & Destructor Documentation

Scene ( const SceneConfiguration config,
const RenderingConfiguration renderingConfig,
uint32  framesInFlight,
const vireo::Viewport &  viewport,
const vireo::Rect &  scissors 
)

Constructs a Scene for a given configuration and viewport/scissors.

Parameters
configScene high-level configuration (buffers sizes, features).
renderingConfigGlobal rendering configuration.
framesInFlightNumber of buffered frames.
viewportDefault viewport used for render passes.
scissorsDefault scissors rectangle.
virtual ~Scene ( )
virtualdefault
Scene ( Scene &  )
delete

Member Function Documentation

virtual void activateCamera ( const std::shared_ptr< Camera > &  camera)
virtual

Activates the provided camera as the current rendering viewpoint.

virtual void addNode ( const std::shared_ptr< Node > &  node)
virtual

Adds a node (camera, light, mesh instance, environment, etc.) to the scene.

void compute ( vireo::CommandList &  commandList) const

Executes compute workloads such as frustum culling.

static void createDescriptorLayouts ( )
static

Creates all static descriptor layouts used by scenes and pipelines.

static void destroyDescriptorLayouts ( )
static

Destroys static descriptor layouts created by createDescriptorLayouts().

void drawModels ( vireo::CommandList &  commandList,
uint32  set,
const std::map< pipeline_id, std::shared_ptr< vireo::Buffer >> &  culledDrawCommandsBuffers,
const std::map< pipeline_id, std::shared_ptr< vireo::Buffer >> &  culledDrawCommandsCountBuffers,
const std::map< pipeline_id, std::shared_ptr< FrustumCulling >> &  frustumCullingPipelines 
) const

Common draw helper that dispatches indirect draws per pipeline using culled lists.

Parameters
commandListCommand buffer to record into.
setDescriptor set index to bind for the pipelines family.
culledDrawCommandsBuffersPer-pipeline indirect commands buffer.
culledDrawCommandsCountBuffersPer-pipeline commands count buffer.
frustumCullingPipelinesPer-pipeline frustum culling compute pipelines.
void drawOpaquesModels ( vireo::CommandList &  commandList,
const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &  pipelines 
) const

Issues draw calls for opaque models using the supplied pipelines map.

Parameters
commandListCommand buffer to record into.
pipelinesMap of material/pipeline identifiers to pipelines.
void drawShaderMaterialModels ( vireo::CommandList &  commandList,
const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &  pipelines 
) const

Issues draw calls for models driven by shader materials/special passes.

void drawTransparentModels ( vireo::CommandList &  commandList,
const std::unordered_map< uint32, std::shared_ptr< vireo::GraphicPipeline >> &  pipelines 
) const

Issues draw calls for transparent models.

auto getCurrentCamera ( ) const
inline

Returns the currently active camera (may be null).

auto getDescriptorSet ( ) const
inline

Returns the main descriptor set containing scene resources.

auto getDescriptorSetOptional1 ( ) const
inline

Returns the optional descriptor set (transparency color for shadows).

const auto& getPipelineIds ( ) const
inline

Returns the mapping of pipeline identifiers to their materials.

auto getScissors ( ) const
inline

Returns the default scissors rectangle for this scene.

auto getShadowMapRenderers ( ) const
inline

Returns a view over the shadow map renderers values.

auto getViewport ( ) const
inline

Returns the default viewport for this scene.

auto isMaterialsUpdated ( ) const
inline

True when materials set changed and pipelines/descriptors must be refreshed.

Scene& operator= ( Scene &  )
delete
virtual void removeNode ( const std::shared_ptr< Node > &  node)
virtual

Removes a node previously added to the scene.

void resetMaterialsUpdated ( )
inline

Resets the materials updated flag after processing.

void setInitialState ( const vireo::CommandList &  commandList) const

Writes initial GPU state required before issuing draw calls.

void update ( const vireo::CommandList &  commandList)

Updates CPU/GPU scene state (uniforms, lights, instances, descriptors).

Member Data Documentation

constexpr vireo::DescriptorIndex BINDING_INSTANCES {0}
staticconstexpr

Descriptor binding for per-instance buffer used by pipelines.

constexpr vireo::DescriptorIndex BINDING_LIGHTS {2}
staticconstexpr

Descriptor binding for lights buffer.

constexpr vireo::DescriptorIndex BINDING_MODELS {1}
staticconstexpr

Descriptor binding for per-model/instance data buffer.

constexpr vireo::DescriptorIndex BINDING_SCENE {0}
staticconstexpr

Descriptor binding for SceneData uniform buffer.

constexpr vireo::DescriptorIndex BINDING_SHADOW_MAP_TRANSPARENCY_COLOR {0}
staticconstexpr

Optional descriptor binding: transparency color for shadow maps.

constexpr vireo::DescriptorIndex BINDING_SHADOW_MAPS {3}
staticconstexpr

Descriptor binding for shadow maps array.

constexpr auto instanceIndexConstantDesc
staticconstexpr
Initial value:
vireo::PushConstantsDesc {
.stage = vireo::ShaderStage::VERTEX,
.size = sizeof(InstanceIndexConstant),
}
constexpr uint32 MAX_SHADOW_MAPS {20}
staticconstexpr

Maximum number of shadow maps supported by the scene.

std::shared_ptr<vireo::DescriptorLayout> pipelineDescriptorLayout {nullptr}
inlinestatic

Shared descriptor layout for pipeline-local resources.

std::shared_ptr<vireo::DescriptorLayout> sceneDescriptorLayout {nullptr}
inlinestatic

Shared descriptor layout for the main scene set.

std::shared_ptr<vireo::DescriptorLayout> sceneDescriptorLayoutOptional1 {nullptr}
inlinestatic

Optional descriptor layout (set used when transparency color is needed).