Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
foray::scene::Scene Class Reference

Provides registries and methods as the anchor of a component based scene. More...

#include <foray_scene.hpp>

Inheritance diagram for foray::scene::Scene:
foray::scene::Registry foray::scene::CallbackDispatcher foray::NoMoveDefaults

Public Member Functions

 Scene (core::Context *context)
 
NodeMakeNode (Node *parent=nullptr)
 Generates a new node and attaches it to the parent if it is set, root otherwise.
 
void Update (const base::FrameRenderInfo &renderInfo, base::CmdBufferIndex index)
 Advance scene state by invoking all NodeComponent update callbacks, followed by GlobalComponent update callbacks.
 
void Update (const base::FrameRenderInfo &renderInfo, VkCommandBuffer cmdBuffer)
 
void Draw (const base::FrameRenderInfo &renderInfo, VkPipelineLayout pipelineLayout, base::CmdBufferIndex index=base::PRIMARY_COMMAND_BUFFER)
 Draw the scene by invoking the Draw callbacks.
 
void Draw (const base::FrameRenderInfo &renderInfo, VkPipelineLayout pipelineLayout, VkCommandBuffer cmdBuffer)
 Draw the scene by invoking the Draw callbacks.
 
void HandleEvent (const osi::Event *event)
 Invokes event callbacks (NodeComponent, then GlobalComponent)
 
virtual void Destroy () override
 Cleans up all memory, GPU structures, etc...
 
virtual ~Scene ()
 
template<typename TComponent >
int32_t FindComponents (std::vector< TComponent * > &outcomponents)
 
template<typename TComponent >
int32_t FindNodesWithComponent (std::vector< Node * > &outnodes)
 
void UseDefaultCamera (bool invertAll=false)
 Adds a default camera to the scene (standard perspective + freecameracontroller) and selects it in the cameramanager.
 
void UpdateTlasManager ()
 Rebuilds the Tlas. If your project requires a Tlas this must be called after altering the scene.
 
void UpdateLightManager ()
 Updates lights. If your project requires punctual lights, this must be called after altering the scene.
 
- Public Member Functions inherited from foray::scene::Registry
 Registry ()
 
 Registry (CallbackDispatcher *root)
 
template<typename TComponent , typename... Args>
TComponentMakeComponent (Args &&... args)
 Instantiates a new componente.
 
template<typename TComponent >
void AddComponent (TComponent *component)
 Adds a manually instantiated component instance (initiate with new, Registry manages finalization)
 
template<typename TComponent >
void MoveComponent (TComponent *component)
 Moves a component registered to a different Registry to this.
 
template<typename TComponent >
bool HasComponent () const
 Test wether a component matching type TComponent is registered.
 
template<typename TComponent >
TComponentGetComponent ()
 Gets first component that can be cast to TComponent type.
 
template<typename TComponent >
const TComponentGetComponent () const
 Gets first component that can be cast to TComponent type.
 
template<typename TComponent >
int32_t GetComponents (std::vector< TComponent * > &out)
 Appends all components which can be cast to TComponent type to the out vector.
 
template<typename TComponent >
int32_t GetComponents (std::vector< const TComponent * > &out) const
 Appends all components which can be cast to TComponent type to the out vector.
 
bool RemoveDeleteComponent (Component *component)
 Removes and finalizes a component.
 
virtual ~Registry ()
 
RegistrySetCallbackDispatcher (CallbackDispatcher *rootRegistry)
 The root registry manages global callbacks invokable on the components.
 
- Public Member Functions inherited from foray::NoMoveDefaults
 NoMoveDefaults ()=default
 
 NoMoveDefaults (const NoMoveDefaults &other)=delete
 
 NoMoveDefaults (NoMoveDefaults &&other)=default
 
NoMoveDefaultsoperator= (const NoMoveDefaults &other)=delete
 
- Public Member Functions inherited from foray::scene::CallbackDispatcher
virtual void InvokeUpdate (SceneUpdateInfo &updateInfo)
 
virtual void InvokeDraw (SceneDrawInfo &renderInfo)
 
virtual void InvokeOnEvent (const osi::Event *event)
 
virtual void InvokeOnResized (VkExtent2D event)
 

Public Attributes

friend Node
 
- Public Attributes inherited from foray::scene::CallbackDispatcher
friend Registry
 

Protected Member Functions

void InitDefaultGlobals ()
 
- Protected Member Functions inherited from foray::scene::Registry
void Register (Component *component)
 
bool Unregister (Component *component)
 
void RegisterToRoot (Component *component)
 
void UnregisterFromRoot (Component *component)
 

Protected Attributes

core::ContextmContext
 
std::vector< std::unique_ptr< Node > > mNodeBuffer
 Buffer holding ownership of all nodes.
 
std::vector< Node * > mRootNodes
 All nodes directly attached to the root.
 
- Protected Attributes inherited from foray::scene::Registry
CallbackDispatchermCallbackDispatcher = nullptr
 All components attached to the registry.
 
std::vector< Component * > mComponents = {}
 
- Protected Attributes inherited from foray::scene::CallbackDispatcher
CallbackVector< Component::OnEventCallbackmOnEvent = {}
 
CallbackVector< Component::UpdateCallbackmUpdate = {}
 
CallbackVector< Component::DrawCallbackmDraw = {}
 
CallbackVector< Component::OnResizedCallbackmOnResized = {}
 

Detailed Description

Provides registries and methods as the anchor of a component based scene.

Remarks
Manages and owns all nodes
Inherits Registry, and functions as the component registry for all global components
Inherits CallbackDispatcher for managing callbacks used by node components, and as a way for nodes to link back to the global instance

Constructor & Destructor Documentation

◆ Scene()

foray::scene::Scene::Scene ( core::Context context)
explicit

◆ ~Scene()

virtual foray::scene::Scene::~Scene ( )
inlinevirtual

Member Function Documentation

◆ Destroy()

virtual void foray::scene::Scene::Destroy ( )
overridevirtual

Cleans up all memory, GPU structures, etc...

Reimplemented from foray::scene::Registry.

◆ Draw() [1/2]

void foray::scene::Scene::Draw ( const base::FrameRenderInfo renderInfo,
VkPipelineLayout  pipelineLayout,
base::CmdBufferIndex  index = base::PRIMARY_COMMAND_BUFFER 
)

Draw the scene by invoking the Draw callbacks.

◆ Draw() [2/2]

void foray::scene::Scene::Draw ( const base::FrameRenderInfo renderInfo,
VkPipelineLayout  pipelineLayout,
VkCommandBuffer  cmdBuffer 
)

Draw the scene by invoking the Draw callbacks.

◆ FindComponents()

template<typename TComponent >
int32_t foray::scene::Scene::FindComponents ( std::vector< TComponent * > &  outcomponents)

◆ FindNodesWithComponent()

template<typename TComponent >
int32_t foray::scene::Scene::FindNodesWithComponent ( std::vector< Node * > &  outnodes)

◆ HandleEvent()

void foray::scene::Scene::HandleEvent ( const osi::Event event)

Invokes event callbacks (NodeComponent, then GlobalComponent)

◆ InitDefaultGlobals()

void foray::scene::Scene::InitDefaultGlobals ( )
protected

◆ MakeNode()

Node * foray::scene::Scene::MakeNode ( Node parent = nullptr)

Generates a new node and attaches it to the parent if it is set, root otherwise.

◆ Update() [1/2]

void foray::scene::Scene::Update ( const base::FrameRenderInfo renderInfo,
base::CmdBufferIndex  index 
)

Advance scene state by invoking all NodeComponent update callbacks, followed by GlobalComponent update callbacks.

◆ Update() [2/2]

void foray::scene::Scene::Update ( const base::FrameRenderInfo renderInfo,
VkCommandBuffer  cmdBuffer 
)

◆ UpdateLightManager()

void foray::scene::Scene::UpdateLightManager ( )

Updates lights. If your project requires punctual lights, this must be called after altering the scene.

◆ UpdateTlasManager()

void foray::scene::Scene::UpdateTlasManager ( )

Rebuilds the Tlas. If your project requires a Tlas this must be called after altering the scene.

◆ UseDefaultCamera()

void foray::scene::Scene::UseDefaultCamera ( bool  invertAll = false)

Adds a default camera to the scene (standard perspective + freecameracontroller) and selects it in the cameramanager.

Member Data Documentation

◆ mContext

core::Context* foray::scene::Scene::mContext
protected

◆ mNodeBuffer

std::vector<std::unique_ptr<Node> > foray::scene::Scene::mNodeBuffer
protected

Buffer holding ownership of all nodes.

Remarks
Holds unique ptrs to be able to preserve pointers if the buffer is changed or moved. These pointers may be null-equivalent.

◆ mRootNodes

std::vector<Node*> foray::scene::Scene::mRootNodes
protected

All nodes directly attached to the root.

◆ Node

friend foray::scene::Scene::Node

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