Cogs.Core
RenderComponent.h
1#pragma once
2
3#include "../../Flags.h"
4
5#include "Foundation/ComponentModel/Component.h"
6
7namespace Cogs
8{
9 namespace Core
10 {
11 constexpr uint32_t NoObjectId = 0;
12
14 enum struct RenderFlags : uint32_t
15 {
17 None = 0,
18
20 SelfVisibility = 1 << 0,
22 ParentVisibility = 1 << 1,
25 SpecificVisibility = 1 << 2,
26
28 SelfPickable = 1 << 3,
30 ParentPickable = 1 << 4,
31
33 CastShadows = 1 << 5,
34
36 CustomMaterial = 1 << 6,
37
39 ForcePickable = 1 << 7,
40
42 DisableCulling = 1 << 8,
43
47 };
48
49 ENABLE_ENUM_FLAGS(RenderFlags);
50
52 enum struct RenderLayers : uint32_t
53 {
54 None = 0u,
55
56 Default = 1u << 0,
57 Ocean = 1u << 1,
58 Annotations = 1u << 2,
59 Sky = 1u << 3,
60 Overlay = 1u << 4,
61 Controllers = 1u << 5,
62 AllStandard = 0x0000003Fu,
63
64 Reserved0 = 1u << 6,
65 Reserved1 = 1u << 7,
66 Reserved2 = 1u << 8,
67 Reserved3 = 1u << 9,
68 Reserved4 = 1u << 10,
69 Reserved5 = 1u << 11,
70 AllReserved = 0x00000FC0u,
71
72 Custom0 = 1u << 12,
73 Custom1 = 1u << 13,
74 Custom2 = 1u << 14,
75 Custom3 = 1u << 15,
76 Custom4 = 1u << 16,
77 Custom5 = 1u << 17,
78 Custom6 = 1u << 18,
79 Custom7 = 1u << 19,
80 Custom8 = 1u << 20,
81 Custom9 = 1u << 21,
82 Custom10 = 1u << 22,
83 Custom11 = 1u << 23,
84 Custom12 = 1u << 24,
85 Custom13 = 1u << 25,
86 Custom14 = 1u << 26,
87 Custom15 = 1u << 27,
88 Custom16 = 1u << 28,
89 Custom17 = 1u << 29,
90 Custom18 = 1u << 30,
91 Custom19 = 1u << 31,
92 AllCustom = 0xFFFFF000u,
93
94 All = 0xFFFFFFFFu
95 };
96
97 ENABLE_ENUM_FLAGS(RenderLayers);
98
106 {
107 public:
109 static void registerType();
110
114 struct LodData
115 {
117 uint8_t selectedLod = 0;
119 uint8_t numLods = 0;
121 uint8_t currentLod = 0;
122 // Fractional component of the LoD represented as a normalized unsigned byte.
123 uint8_t lodFraction = 0;
124 } lod;
125
134 RenderLayers layer = RenderLayers::Default;
135
143 int32_t drawOrder = 0;
144
149
153 uint32_t objectId = NoObjectId;
154
161 constexpr void setRenderFlag(RenderFlags flag) { renderFlags |= flag; }
162
171 constexpr void setRenderFlag(RenderFlags flag, bool status) {
172 if (status) {
173 setRenderFlag(flag);
174 } else {
175 unsetRenderFlag(flag);
176 }
177 }
178
184 constexpr void unsetRenderFlag(RenderFlags flag) { renderFlags &= ~flag; }
185
193 constexpr bool isRenderFlagSet(RenderFlags flag) const { return (renderFlags & flag) == flag; }
194
202 constexpr bool isRenderFlagsSet(RenderFlags flags) const { return (renderFlags & flags) == flags; }
203
209 constexpr void setVisible(bool visible)
210 {
212 }
213
222 constexpr bool isVisibleInLayer(RenderLayers layerMask) const
223 {
224 return ((layerMask & this->layer) != RenderLayers::None) && isVisible();
225 }
226
235 constexpr bool isVisible() const
236 {
240 }
241
249 constexpr bool isPickable() const
250 {
252 }
253
255 constexpr bool castShadows() const
256 {
258 }
259
261 constexpr bool disableCulling() const
262 {
264 }
265
266 constexpr bool customMaterial() const
267 {
269 }
270
277 };
278 }
279}
280
281template<> inline Cogs::StringView getName<Cogs::Core::RenderFlags>() { return "RenderFlags"; }
282template<> inline Cogs::StringView getName<Cogs::Core::RenderLayers>() { return "RenderLayers"; }
283template<> inline Cogs::StringView getName<Cogs::Core::RenderComponent>() { return "RenderComponent"; }
284
Base class for Component instances.
Definition: Component.h:143
Base component for all rendering content.
static void registerType()
Register the type in the type system.
ComponentModel::ComponentHandle clipShapeComponent
Handle to the currently active clip component, if any.
constexpr bool isVisibleInLayer(RenderLayers layerMask) const
Check if the entity should be visible in the given layer mask.
RenderLayers layer
Layer mask used to determine visibility for a given camera viewport.
int32_t drawOrder
Draw order within a render bucke.
constexpr bool disableCulling() const
Get if the object should skip culling.
constexpr void unsetRenderFlag(RenderFlags flag)
Unset the given flag.
constexpr bool isVisible() const
Check if the entity is visible or not.
constexpr void setRenderFlag(RenderFlags flag)
Sets the given flag.
constexpr void setRenderFlag(RenderFlags flag, bool status)
Set the given flag to the given status.
RenderFlags renderFlags
Render flags used to control rendering behavior.
constexpr bool isRenderFlagSet(RenderFlags flag) const
Check if the given flag is currently set.
constexpr bool isRenderFlagsSet(RenderFlags flags) const
Check if the given combination of flags are set.
constexpr bool castShadows() const
Get if the object should cast shadows.
constexpr bool isPickable() const
Check if the entity is pickable or not.
constexpr void setVisible(bool visible)
Set the specific visibility.
uint32_t objectId
Object identifier passed to rendering commands.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
RenderFlags
Contains flags to describe rendering behavior.
@ ForcePickable
Ensure component is pickable though it is not rendered.
@ CastShadows
Casts shadows.
@ ParentVisibility
Parent visibility, used by the SceneSystem to toggle child entity visibility on/off.
@ CustomMaterial
Custom material set. Keeps legacy material component from changing the material instance.
@ ParentPickable
Parent pickable, used by the SceneSystem to toggle child entity pickable on/off.
@ Default
Default set of flags.
@ SelfVisibility
Self visibility, used by the SceneSystem to toggle entity visibility on/off.
@ DisableCulling
Disable culling and always force this component to be rendered.
@ SelfPickable
Self pickable, used by the SceneSystem to toggle entity pickable on/off.
RenderLayers
Contains common render layers.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
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
Lod data holding the LoD state of the entity this render component belongs to.
uint8_t numLods
Total number of LoDs available.
uint8_t currentLod
The assigned LoD of the current component.
uint8_t selectedLod
The selected LoD of the composite entity.