CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RenderGraphSlot.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "RenderResource.hpp"
13
15
18
19namespace CeresEngine {
20
23 class Slot {
24 public:
26 enum class Type {
27 Input,
28 Output
29 };
30
31 protected:
34
37
38 public:
39 explicit Slot(RenderTask* task, const StringView name) : Slot(*task, name) {}
40 explicit Slot(RenderTask& task, StringView name);
42
43 public:
45 [[nodiscard]] RenderTask& getRenderTask() const { return mTask; }
46
48 [[nodiscard]] StringView getName() const { return mName; }
49
52
53 public:
55 [[nodiscard]] virtual Type getType() const = 0;
56
58 [[nodiscard]] bool isInput() const { return getType() == Type::Input; }
59
61 [[nodiscard]] const InputSlot& asInput() const;
62
64 [[nodiscard]] bool isOutput() const { return getType() == Type::Output; }
65
67 [[nodiscard]] const OutputSlot& asOutput() const;
68
69 public:
72 [[nodiscard]] virtual Connection* getConnection(Slot& slot) const = 0;
73
75 [[nodiscard]] bool isConnected(Slot& slot) const;
76
78 static ConnectionPtr connect(InputSlot& input, OutputSlot& output);
79
81 friend ConnectionPtr connect(InputSlot& input, OutputSlot& output) { return Slot::connect(input, output); }
82
84 static bool disconnect(InputSlot& input, OutputSlot& output);
85
87 friend bool disconnect(InputSlot& input, OutputSlot& output) { return Slot::disconnect(input, output); }
88
90
92 [[nodiscard]] virtual bool supports(Slot& slot) const;
93
94 protected:
97 [[nodiscard]] virtual bool shouldConnect(Slot& slot) const;
98
100 virtual void willConnect(Slot& slot);
101
103 virtual void didConnect(Connection& connection) {}
104
107 [[nodiscard]] virtual bool shouldDisconnect(Connection& connection) const;
108
110 virtual void willDisconnect(Connection& connection) {}
111
113 virtual void didDisconnect(Connection& slot) {}
114
115 public:
118
121 };
122
123 // ---------------------------------------------------------------------------------------------
124 // ---------------------------------------------------------------------------------------------
125
127 class InputSlot : public Slot {
128 public:
129 InputSlot(RenderTask* task, const StringView name) : InputSlot(*task, name) {}
132
133 public:
136
137 public:
139 [[nodiscard]] Connection* getConnection(Slot& slot) const override;
140
143
145 [[nodiscard]] bool supports(Slot& slot) const override;
146
148 [[nodiscard]] virtual const ConnectionPtr& getConnection() const = 0;
149
152
153 protected:
155 [[nodiscard]] bool shouldDisconnect(Connection& connection) const override;
156 };
157
159 class OutputSlot : public Slot {
160 public:
161 OutputSlot(RenderTask* task, const StringView name) : OutputSlot(*task, name) {}
164
165 public:
168
169 public:
171 [[nodiscard]] Connection* getConnection(Slot& slot) const override;
172
175
177 [[nodiscard]] bool supports(Slot& slot) const override;
178
180 [[nodiscard]] virtual const Vector<ConnectionPtr>& getConnections() const = 0;
181
182 protected:
184 [[nodiscard]] bool shouldDisconnect(Connection& connection) const override;
185 };
186
188 class Connection : public RefCounted<Connection> {
189 public:
190 enum class Status {
191 Connected,
193 };
194
195 private:
198
201
204
205 public:
206 explicit Connection(InputSlot& input, OutputSlot& output) : mInput(input), mOutput(output) {}
208
209 public:
211 InputSlot& getInput() const { return mInput; }
212
214 OutputSlot& getOutput() const { return mOutput; }
215
218
221
224
225 public:
228
229 protected:
230 friend class Slot;
233 };
234
235 [[nodiscard]] inline InputSlot& Slot::asInput() { return static_cast<InputSlot&>(*this); }
236 [[nodiscard]] inline const InputSlot& Slot::asInput() const { return static_cast<const InputSlot&>(*this); }
237 [[nodiscard]] inline OutputSlot& Slot::asOutput() { return static_cast<OutputSlot&>(*this); }
238 [[nodiscard]] inline const OutputSlot& Slot::asOutput() const { return static_cast<const OutputSlot&>(*this); }
239
240 // ---------------------------------------------------------------------------------------------
241 // ---------------------------------------------------------------------------------------------
242
244 class BasicInputSlot : public InputSlot {
245 private:
248
249 public:
251
252 public:
255
256 protected:
258 void didConnect(Connection& connection) override;
259
261 void didDisconnect(Connection& slot) override;
262 };
263
266 public:
269
270 public:
272
273 public:
276
277 protected:
279 void didConnect(Connection& connection) override;
280
282 void didDisconnect(Connection& slot) override;
283 };
284
285 // ---------------------------------------------------------------------------------------------
286 // ---------------------------------------------------------------------------------------------
287
291 template<typename P, typename RT> class TSlot : public P {
292 public:
293 using P::P;
294
295 public:
297 [[nodiscard]] RenderResourceType getResourceType() const final { return RT::resourceType; }
298 };
299
302 template<typename RT> class TInput final : public TSlot<BasicInputSlot, RT> {
303 public:
304 using TSlot<BasicInputSlot, RT>::TSlot;
305
306 public:
309 };
310
313 template<typename RT> class TOutput final : public TSlot<BasicOutputSlot, RT> {
314 public:
315 using TSlot<BasicOutputSlot, RT>::TSlot;
316
317 public:
320 };
321
324
327
330
333
334} // namespace CeresEngine
A basic input slot.
Definition RenderGraphSlot.hpp:244
ConnectionPtr mConnection
The connection that is connected to the input slot.
Definition RenderGraphSlot.hpp:247
void didConnect(Connection &connection) override
An internal method called after the slot is connected.
void didDisconnect(Connection &slot) override
An internal method called whenever the slot is disconnected.
const ConnectionPtr & getConnection() const final
Finds a connection to the given slot.
Definition RenderGraphSlot.hpp:254
A basic output slot.
Definition RenderGraphSlot.hpp:265
Vector< ConnectionPtr > mConnections
The connections that use this slot.
Definition RenderGraphSlot.hpp:268
void didDisconnect(Connection &slot) override
An internal method called whenever the slot is disconnected.
const Vector< ConnectionPtr > & getConnections() const final
A list of all connections to this output slot.
Definition RenderGraphSlot.hpp:275
void didConnect(Connection &connection) override
An internal method called after the slot is connected.
A class that describes the connection between an input and an output slot.
Definition RenderGraphSlot.hpp:188
InputSlot & mInput
The slot connected to the input end of the connection.
Definition RenderGraphSlot.hpp:197
Connection(InputSlot &input, OutputSlot &output)
Definition RenderGraphSlot.hpp:206
Status
Definition RenderGraphSlot.hpp:190
InputSlot & getInput() const
The slot connected to the input end of the connection.
Definition RenderGraphSlot.hpp:211
OutputSlot & mOutput
The slot connected to the output end of the connection.
Definition RenderGraphSlot.hpp:200
bool isConnected() const noexcept
Definition RenderGraphSlot.hpp:220
Status mStatus
A value that indicates the connection status.
Definition RenderGraphSlot.hpp:203
bool isDisconnected() const noexcept
Definition RenderGraphSlot.hpp:223
void disconnect()
Disconnects the connection.
OutputSlot & getOutput() const
The slot connected to the output end of the connection.
Definition RenderGraphSlot.hpp:214
Status getStatus() const noexcept
A value that indicates the connection status.
Definition RenderGraphSlot.hpp:217
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
A slot that inputs a resource. Can be connected to a single output.
Definition RenderGraphSlot.hpp:127
virtual const ConnectionPtr & getConnection() const =0
Gets the connection currently in use.
bool supports(Slot &slot) const override
Checks if this slot supports a connection to the given slot.
InputSlot(RenderTask &task, StringView name)
Type getType() const final
Definition RenderGraphSlot.hpp:135
InputSlot(RenderTask *task, const StringView name)
Definition RenderGraphSlot.hpp:129
Connection * getConnection(Slot &slot) const override
Finds a connection to the given slot.
bool shouldDisconnect(Connection &connection) const override
An internal method called whenever a new disconnection is being made.
ConnectionPtr connect(OutputSlot &output)
Connects the given output to this input slot.
OutputSlot * getConnectedSlot() const
Gets the output slot used in the current connection.
A slot that outputs a resource. Can be connected to multiple input slots.
Definition RenderGraphSlot.hpp:159
Type getType() const final
Definition RenderGraphSlot.hpp:167
bool shouldDisconnect(Connection &connection) const override
An internal method called whenever a new disconnection is being made.
ConnectionPtr connect(InputSlot &input)
Connects the given input to this output slot.
bool supports(Slot &slot) const override
Checks if this slot supports a connection to the given slot.
OutputSlot(RenderTask *task, const StringView name)
Definition RenderGraphSlot.hpp:161
virtual const Vector< ConnectionPtr > & getConnections() const =0
A list of all connections to this output slot.
Connection * getConnection(Slot &slot) const override
Finds a connection to the given slot.
OutputSlot(RenderTask &task, StringView name)
A simple reference counter base class.
Definition SmartPtr.hpp:438
Definition RenderTask.hpp:164
A render task slot.
Definition RenderGraphSlot.hpp:23
static ConnectionPtr connect(InputSlot &input, OutputSlot &output)
Connects an output slot into an input slot.
RenderTask & getRenderTask() const
The render task that owns this render graph slot.
Definition RenderGraphSlot.hpp:45
static bool disconnect(InputSlot &input, OutputSlot &output)
Disconnect the given slot from this slot.
virtual bool shouldConnect(Slot &slot) const
An internal method called whenever a new connection is being made.
bool isOutput() const
Returns true if the slot is an output slot, false otherwise.
Definition RenderGraphSlot.hpp:64
virtual RenderResourceType getResourceType() const =0
The type of resource accepted by the slot.
bool isInput() const
Returns true if the slot is an input slot, false otherwise.
Definition RenderGraphSlot.hpp:58
UInt32 disconnectAll()
virtual Connection * getConnection(Slot &slot) const =0
Finds a connection to the given slot.
virtual Type getType() const =0
virtual void willDisconnect(Connection &connection)
An internal method called before the slot is disconnected.
Definition RenderGraphSlot.hpp:110
RenderTask & mTask
The render task that owns this render graph slot.
Definition RenderGraphSlot.hpp:33
virtual void willConnect(Slot &slot)
An internal method called before the slot is connected.
virtual void didDisconnect(Connection &slot)
An internal method called whenever the slot is disconnected.
Definition RenderGraphSlot.hpp:113
virtual void didConnect(Connection &connection)
An internal method called after the slot is connected.
Definition RenderGraphSlot.hpp:103
const StringView mName
A human-readable name for the slot.
Definition RenderGraphSlot.hpp:36
StringView getName() const
A human-readable name for the slot.
Definition RenderGraphSlot.hpp:48
bool isConnected(Slot &slot) const
Checks if there's an active connection to the given slot.
OutputSlot & asOutput()
Definition RenderGraphSlot.hpp:237
virtual bool supports(Slot &slot) const
Checks if this slot supports a connection to the given slot.
Event< void(Connection &)> onConnect
An event triggered whenever the slot is connected to another.
Definition RenderGraphSlot.hpp:117
friend ConnectionPtr connect(InputSlot &input, OutputSlot &output)
Connects an output slot into an input slot.
Definition RenderGraphSlot.hpp:81
virtual bool shouldDisconnect(Connection &connection) const
An internal method called whenever a new disconnection is being made.
InputSlot & asInput()
Definition RenderGraphSlot.hpp:235
Event< void(Connection &)> onDisconnect
An event triggered whenever the slot is disconnected from another.
Definition RenderGraphSlot.hpp:120
Type
A enumeration of the types of slots.
Definition RenderGraphSlot.hpp:26
Slot(RenderTask &task, StringView name)
Slot(RenderTask *task, const StringView name)
Definition RenderGraphSlot.hpp:39
friend bool disconnect(InputSlot &input, OutputSlot &output)
Disconnect the given slot from this slot.
Definition RenderGraphSlot.hpp:87
Base template for the event class.
Definition Event.hpp:27
A type-safe input slot type.
Definition RenderGraphSlot.hpp:302
ConnectionPtr operator=(TSlot< BasicOutputSlot, RT > &slot)
Connects the given output to this input slot.
Definition RenderGraphSlot.hpp:308
A type-safe output slot type.
Definition RenderGraphSlot.hpp:313
ConnectionPtr operator=(TSlot< BasicInputSlot, RT > &slot)
Connects the given input to this output slot.
Definition RenderGraphSlot.hpp:319
A type-safe slot base class.
Definition RenderGraphSlot.hpp:291
RenderResourceType getResourceType() const final
The type of resource accepted by the slot.
Definition RenderGraphSlot.hpp:297
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::uint32_t UInt32
Definition DataTypes.hpp:23
RenderResourceType
Definition RenderResource.hpp:22
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25