Cogs.Core
Image360System.h
1#pragma once
2#include "Rendering/Common.h"
3#include "Rendering/IGraphicsDevice.h"
4
5#include "Renderer/IRenderer.h"
6#include "Resources/MeshStreamsLayout.h"
7#include "Systems/ComponentSystem.h"
8#include "Scene/GetBounds.h"
9#include "Scene/RayPick.h"
10
11#include "Image360.h"
12#include "Image360Component.h"
13
14namespace Cogs::Core
15{
16 struct Image360System;
17 struct Image360Data;
18
19 namespace Image360 {
20
21 struct Bounds final : public IGetBounds {
22 public:
23 explicit Bounds(Image360System* im360System);
24 void getBounds(Context* context, Cogs::Geometry::BoundingBox& bounds) override;
25 bool getBounds(Context* context, const Cogs::ComponentModel::Entity* entity, Cogs::Geometry::BoundingBox& bounds, bool ignoreVisibility) const override;
26
27 private:
28 Image360System* im360System = nullptr;
29 };
30
32 {
33 public:
34 void initialize(Context* context, IGraphicsDevice* device) override;
35 void release();
36 void handleEvent(uint32_t eventId, const DrawContext* renderingContext) override;
37 void generateCommands(const RenderTaskContext* renderingContext, RenderList* renderList) override;
38 void releaseRenderingResources(RendererExtensionData& im360Data);
39
40 Context* context = nullptr;
41 IGraphicsDevice* device = nullptr;
42 Image360System* im360System = nullptr;
43
45
46 // We defer releasing textures that we manage one frame to avoid releasing it while it is in use, which WebGPU doesn't like.
47 std::vector<Cogs::TextureHandle> texturesToRelease;
48
49 struct {
50 MeshStreamsLayout streamsLayout;
52 Cogs::BufferHandle paramBuffer;
53 } fullScreenTriangle;
54
55 // WebGL on VR headsets have an issue with copy/blits from texture arrays, so we use shader instead
56 struct {
57 struct {
63 } f;
64
65 struct {
71 } u;
72
78 } atlasBlit;
79
80 };
81
83 {
84 RayPickExtension(Image360System* im360System);
85
86 bool pickCamera(Context* context,
87 const CameraComponent& camera,
88 const glm::vec2& normPosition,
89 float /*rayLength*/,
90 float /*radius*/,
91 PickingFlags pickingFlags,
92 PicksReturned returnFlag,
93 const RayPicking::RayPickFilter& filter,
94 std::vector<RayPicking::RayPickHit>& hits) override;
95
96 Image360System* im360System = nullptr;
97 };
98
99 }
100
102 {
103 enum struct State {
104 Uninitialized,
105 Error,
106 WaitingForJson,
107 JsonParsed,
108 WaitingForBaseLevel,
109 Running
110 };
111 State state = State::Uninitialized;
112
113 std::string source;
114 uint32_t valueChannel = 0;
115 bool hasDepth = false;
116
117 MaterialInstanceHandle materialInstance;
118
119 Image360::Config config;
120 Image360::Fetcher fetcher;
121 Image360::Cache cache;
124 };
125
126 struct Image360System : public ComponentSystemWithDataPool<Image360Component, Image360Data>
127 {
129
130 Image360System(Memory::Allocator* allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
131
133
134 void initialize(Context* context) override;
135
136 void update(Context* context) override;
137
139 void destroyComponent(ComponentHandle component) override;
140
141 MaterialHandle material;
142 uint32_t instanceCounter = 1;
143
144 private:
145 Image360::RendererExtension* renderer = nullptr;
146 Image360::Bounds* bounds = nullptr;
147 Image360::RayPickExtension* picker = nullptr;
148 };
149
150
151}
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Interface for modules implementing custom picking.
Definition: RayPick.h:186
Defines an extension to the renderer, capable of doing custom rendering.
Definition: IRenderer.h:123
Represents a graphics device used to manage graphics resources and issue drawing commands.
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
void initialize(Context *context) override
Initialize the system.
ComponentHandle createComponent() override
void destroyComponent(ComponentHandle component) override
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
Definition: Bounds.cpp:33
bool pickCamera(Context *context, const CameraComponent &camera, const glm::vec2 &normPosition, float, float, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a normalized screen space position in the camera direction and return all hits.
void handleEvent(uint32_t eventId, const DrawContext *renderingContext) override
Called when rendering events occur.
void initialize(Context *context, IGraphicsDevice *device) override
Initialize the extension using the given context and device.
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:78