Cogs.Core
SubMeshRenderSystem.h
1#pragma once
2
3#include "Systems/ComponentSystem.h"
4#include "Components/Core/SubMeshRenderComponent.h"
5#include "Services/TaskManager.h"
6#include "Scene/RayPick.h"
7
8#include "Foundation/Geometry/BoundingBox.hpp"
9
10namespace Cogs::Core
11{
12 class Context;
13 class SubMeshRenderSystem;
14
16 {
17 glm::mat4 localToWorld;
18
19 uint16_t localBoundsGeneration = 0;
20 uint16_t worldBoundsGeneration = 0;
21 uint8_t meshBoundsGeneration = 0;
22
23 uint32_t cullingIndex = (uint32_t)-1;
24
25 uint32_t flags = 0;
26
29 };
30
31 struct SubMeshLocalBounds : public Geometry::BoundingBox
32 {
33
34 };
35
36 struct SubMeshWorldBounds : public Geometry::BoundingBox
37 {
38
39 };
40
42 {
43 explicit SubMeshPicker(SubMeshRenderSystem* system) : system(system) {}
44
45 private:
46 bool pickImpl(Context* context,
47 const glm::mat4& worldPickMatrix,
48 const glm::mat4& rawViewProjection,
49 const glm::mat4& viewMatrix,
50 const RayPicking::RayPickFilter& filter,
51 PickingFlags pickingFlags,
52 PicksReturned returnFlag,
53 std::vector<RayPicking::RayPickHit>& hits) override;
54
55 SubMeshRenderSystem* system = nullptr;
56 };
57
61 class SubMeshRenderSystem : public ComponentSystemWithDataPools<SubMeshRenderComponent, SubMeshRenderData, SubMeshLocalBounds, SubMeshWorldBounds>
62 {
64 public:
65 SubMeshRenderSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPools(allocator, capacity) {}
66
67 void initialize(Context * context) override;
68 void update(Context * context) override;
69 void postUpdate(Context * context) override;
70 void cleanup(Context * context) override;
71
73 void destroyComponent(ComponentHandle component) override;
74
75 TaskId getTaskGroup() const { return geometryGroup; }
76
77 Geometry::BoundingBox & getLocalBounds(const SubMeshRenderComponent * component)
78 {
79 return this->getData<SubMeshLocalBounds>(component);
80 }
81
82 Geometry::BoundingBox & getWorldBounds(const SubMeshRenderComponent * component)
83 {
84 return this->getData<SubMeshWorldBounds>(component);
85 }
86
87 void setBounds(const SubMeshRenderComponent * component, Geometry::BoundingBox & box, const glm::mat4 & worldTransform)
88 {
89 getWorldBounds(component) = box;
90 auto & data = getData<SubMeshRenderData>(component);
91 data.localToWorld = worldTransform;
92 data.flags = 1;
93 }
94
95 void initializeCulling(struct CullingSource * cullData);
96
97 private:
98 bool needsPost = true;
99 TaskId geometryGroup = NoTask;
100
101 std::unique_ptr<SubMeshPicker> picker;
102 };
103}
Context * context
Pointer to the Context instance the system lives in.
void postUpdate()
Perform post update logic in the system.
void update()
Updates the system state to that of the current frame.
Component system template with multiple parallel structures per component stored in separate pools si...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Base class for picking meshes.
Definition: RayPick.h:172
Renders a mesh with flexible submesh usage.
The submesh render system handles SubMeshRenderComponents.
void initialize(Context *context) override
Initialize the system.
void destroyComponent(ComponentHandle component) override
Destroy the component held by the given handle.
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
ComponentHandle createComponent() override
Create a new component instance.
Base allocator implementation.
Definition: Allocator.h:30
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
PicksReturned
  * Options for returning picking hits.
Definition: PickingFlags.h:40
PickingFlags
Options for COGS picking.
Definition: PickingFlags.h:12
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67
static ComponentHandle Empty()
Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().
Definition: Component.h:119
bool pickImpl(Context *context, const glm::mat4 &worldPickMatrix, const glm::mat4 &rawViewProjection, const glm::mat4 &viewMatrix, const RayPicking::RayPickFilter &filter, PickingFlags pickingFlags, PicksReturned returnFlag, std::vector< RayPicking::RayPickHit > &hits) override
Each mesh rendering system should implement this function that goes through all components and calls ...
Task id struct used to identify unique Task instances.
Definition: TaskManager.h:20