Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_scene.hpp
Go to the documentation of this file.
1#pragma once
2#include "../as/foray_tlas.hpp"
3#include "../osi/foray_osi_declares.hpp"
5#include "foray_node.hpp"
6#include "foray_registry.hpp"
9
10namespace foray::scene {
11
16 class Scene : public Registry, public CallbackDispatcher
17 {
18 public:
19 friend Node;
20
22
24 Node* MakeNode(Node* parent = nullptr);
25
30 void Draw(const base::FrameRenderInfo& renderInfo, VkPipelineLayout pipelineLayout, base::CmdBufferIndex index = base::PRIMARY_COMMAND_BUFFER);
35
37 virtual void Destroy() override;
38
39 inline virtual ~Scene() { Destroy(); }
40
43 FORAY_PROPERTY_V(Context)
44
45 template <typename TComponent>
46 int32_t FindComponents(std::vector<TComponent*>& outcomponents);
47
48 template <typename TComponent>
49 int32_t FindNodesWithComponent(std::vector<Node*>& outnodes);
50
52 void UseDefaultCamera(bool invertAll = false);
57
58 protected:
62 std::vector<std::unique_ptr<Node>> mNodeBuffer;
63
65 std::vector<Node*> mRootNodes;
66
68 };
69
70 template <typename TComponent>
71 int32_t Scene::FindComponents(std::vector<TComponent*>& outnodes)
72 {
73 int32_t found = 0;
75 {
76 found += rootnode->FindComponentsRecursive<TComponent>(outnodes);
77 }
78 return found;
79 }
80
81 template <typename TComponent>
82 int32_t Scene::FindNodesWithComponent(std::vector<Node*>& outnodes)
83 {
84 int32_t found = 0;
86 {
87 if(rootnode->HasComponent<TComponent>())
88 {
89 found++;
90 outnodes.push_back(rootnode);
91 }
92 found += rootnode->FindChildrenWithComponent<TComponent>(outnodes);
93 }
94 return found;
95 }
96} // namespace foray::scene
Context used for render processes. This object is rebuilt for every frame. /.
Definition foray_framerenderinfo.hpp:14
Base class for operating system events.
Definition foray_event.hpp:13
Type maintaining callback lists for event distribution.
Definition foray_callbackdispatcher.hpp:12
A scene node. Extends the registry with hierarchical information.
Definition foray_node.hpp:8
Manages a type identified list of components.
Definition foray_registry.hpp:12
int32_t GetComponents(std::vector< TComponent * > &out)
Appends all components which can be cast to TComponent type to the out vector.
Definition foray_registry.hpp:145
Provides registries and methods as the anchor of a component based scene.
Definition foray_scene.hpp:17
friend Node
Definition foray_scene.hpp:19
virtual ~Scene()
Definition foray_scene.hpp:39
void UpdateLightManager()
Updates lights. If your project requires punctual lights, this must be called after altering the scen...
Node * MakeNode(Node *parent=nullptr)
Generates a new node and attaches it to the parent if it is set, root otherwise.
virtual void Destroy() override
Cleans up all memory, GPU structures, etc...
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.
int32_t FindNodesWithComponent(std::vector< Node * > &outnodes)
Definition foray_scene.hpp:82
void Update(const base::FrameRenderInfo &renderInfo, VkCommandBuffer cmdBuffer)
Scene(core::Context *context)
std::vector< std::unique_ptr< Node > > mNodeBuffer
Buffer holding ownership of all nodes.
Definition foray_scene.hpp:62
void UseDefaultCamera(bool invertAll=false)
Adds a default camera to the scene (standard perspective + freecameracontroller) and selects it in th...
int32_t FindComponents(std::vector< TComponent * > &outcomponents)
Definition foray_scene.hpp:71
core::Context * mContext
Definition foray_scene.hpp:59
void HandleEvent(const osi::Event *event)
Invokes event callbacks (NodeComponent, then GlobalComponent)
void Update(const base::FrameRenderInfo &renderInfo, base::CmdBufferIndex index)
Advance scene state by invoking all NodeComponent update callbacks, followed by GlobalComponent updat...
void UpdateTlasManager()
Rebuilds the Tlas. If your project requires a Tlas this must be called after altering the scene.
std::vector< Node * > mRootNodes
All nodes directly attached to the root.
Definition foray_scene.hpp:65
#define FORAY_PROPERTY_V(member)
Getter+Setter shorthand for value types.
Definition foray_basics.hpp:81
#define FORAY_PROPERTY_R(member)
Getter+Setter shorthand for reference types.
Definition foray_basics.hpp:86
int32_t CmdBufferIndex
Definition foray_inflightframe.hpp:17
Definition foray_animation.hpp:8
Non owning context object.
Definition foray_context.hpp:16