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
43 bool isReady();
44
45 Context* context = nullptr;
46 IGraphicsDevice* device = nullptr;
47 Image360System* im360System = nullptr;
48
50
51 // We defer releasing textures that we manage one frame to avoid releasing it while it is in use, which WebGPU doesn't like.
52 std::vector<Cogs::TextureHandle> texturesToRelease;
53
54 struct {
55 MeshStreamsLayout streamsLayout;
57 Cogs::BufferHandle paramBuffer;
58 } fullScreenTriangle;
59
60 // WebGL on VR headsets have an issue with copy/blits from texture arrays, so we use shader instead
68 };
69
70 struct {
73
79 } atlasBlit;
80
81 };
82
84 {
85 RayPickExtension(Image360System* im360System);
86
87 bool pickCamera(Context* context,
88 const CameraComponent& camera,
89 const glm::vec2& normPosition,
90 float /*rayLength*/,
91 float /*radius*/,
92 PickingFlags pickingFlags,
93 PicksReturned returnFlag,
94 const RayPicking::RayPickFilter& filter,
95 std::vector<RayPicking::RayPickHit>& hits) override;
96
97 Image360System* im360System = nullptr;
98 };
99
100 }
101
103 {
104 enum struct State {
105 Uninitialized,
106 Error,
107 WaitingForJson,
108 JsonParsed,
109 WaitingForRendererReady,
110 WaitingForBaseLevel,
111 Running
112 };
113 State state = State::Uninitialized;
114
115 std::string source;
116 uint32_t valueChannel = 0;
117 bool hasDepth = false;
118
119 MaterialInstanceHandle materialInstance;
120
121 Image360::Config config;
122 Image360::Fetcher fetcher;
123 Image360::Cache cache;
126 };
127
128 struct Image360System : public ComponentSystemWithDataPool<Image360Component, Image360Data>
129 {
131
132 Image360System(Memory::Allocator* allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
133
135
136 void initialize(Context* context) override;
137
138 void update(Context* context) override;
139
141 void destroyComponent(ComponentHandle component) override;
142
143 MaterialHandle material;
144 uint32_t instanceCounter = 1;
145
146 private:
147 Image360::RendererExtension* renderer = nullptr;
148 Image360::Bounds* bounds = nullptr;
149 Image360::RayPickExtension* picker = nullptr;
150 };
151
152
153}
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:188
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
ResourceStatus
Status of an asynchronously loaded resource, such as an effect or a pipeline.
Definition: Common.h:198
@ Pending
The resource is still loading.
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