CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Renderable.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 "SceneObject.hpp"
11
14
17
23
24namespace CeresEngine {
25
27
30 struct CE_SCRIPT_EXPORT() RenderableComponent final : public Component<RenderableComponent> {
32 struct Accessor;
33
36
39
43
46 RenderableComponent() noexcept = default;
47
48 // Destroys the renderable component.
49 ~RenderableComponent() noexcept final = default;
50
51 public: // Reflection
54 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
55 CE_REFL_DATA(mesh);
56 CE_REFL_DATA(materials);
57 CE_REFL_DATA(rendererSettings);
58 }
59 };
60
62 struct CE_SCRIPT_EXPORT() RenderableComponent::Accessor : public Component<RenderableComponent>::Accessor {
63 using Component<RenderableComponent>::Accessor::Accessor;
64
66 [[nodiscard]] const HMesh& getMesh() const;
67
69 void setMesh(HMesh mesh);
70
72 [[nodiscard]] const RenderableMaterialVector& getMaterials() const;
73
76
78 [[nodiscard]] const HMaterial& getMaterial(UInt32 index) const;
79
81 void setMaterial(UInt32 index, HMaterial material);
82
84 void setMaterial(HMaterial material);
85
87 [[nodiscard]] const RendererRenderableSettings& getRendererSettings() const;
88
90 void setRendererSettings(const RendererRenderableSettings& rendererSettings);
91
93 template<CInvocable<RendererRenderableSettings&> Func> decltype(auto) updateRendererSettings(Func&& func) noexcept {
94 RendererRenderableSettings settings = getRendererSettings();
95 const ScopeExit commitSettings([&]() { setRendererSettings(settings); });
96 return func(settings);
97 }
98
99 public: // Reflection
102 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
103 CE_REFL_DATA_GETSET(mesh, getMesh, setMesh);
104 CE_REFL_DATA_GETSET(materials, getMaterials, setMaterials);
105 CE_REFL_DATA_GETSET(rendererSettings, getRendererSettings, setRendererSettings);
106 }
107 };
108
109 class CE_SCRIPT_EXPORT() Renderable final : public TSceneObject<RenderableComponent> {
110 public:
111 using TSceneObject::TSceneObject;
112 };
113
114} // namespace CeresEngine
115
118
121
124
#define CE_EXTERN_COMPONENT(T)
Definition Component.hpp:600
#define CE_ENTITY_OBJECT_HASH(T)
Definition Entity.hpp:784
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFLECTABLE_STRUCT
Definition IReflectable.hpp:47
#define CE_REFL_DATA_GETSET(N, G, S)
Definition Macros.hpp:549
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Renderable.hpp:109
The SceneObject template class is a helper class that EntityObjects might choose to use to provide so...
Definition SceneObject.hpp:323
Definition Application.hpp:19
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
SmallVector< HMaterial, 10 > RenderableMaterialVector
Definition Renderable.hpp:26
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
A class that describes access to a RenderableComponent.
Definition Renderable.hpp:62
void setMaterial(HMaterial material)
The material to render the component with. One material per sub mesh.
const RendererRenderableSettings & getRendererSettings() const
A set of settings that should be used by renderer when rendering the renderable.
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition Renderable.hpp:102
const HMesh & getMesh() const
The mesh to render the component with.
const HMaterial & getMaterial(UInt32 index) const
The material to render the component with. One material per sub mesh.
void setMesh(HMesh mesh)
The mesh to render the component with.
const RenderableMaterialVector & getMaterials() const
The material to render the component with. One material per sub mesh.
void setRendererSettings(const RendererRenderableSettings &rendererSettings)
A set of settings that should be used by renderer when rendering the renderable.
void setMaterial(UInt32 index, HMaterial material)
The material to render the component with. One material per sub mesh.
decltype(auto) updateRendererSettings(Func &&func) noexcept
A set of settings that should be used by renderer when rendering the renderable.
Definition Renderable.hpp:93
void setMaterials(RenderableMaterialVector materials)
The material to render the component with. One material per sub mesh.
A component that represents an object that can be rendered by a renderer.
Definition Renderable.hpp:30
RendererRenderableSettings rendererSettings
A set of settings that should be used by renderer when rendering the renderable.
Definition Renderable.hpp:42
HMesh mesh
The mesh to render the component with.
Definition Renderable.hpp:35
RenderableMaterialVector materials
The material to render the component with. One material per sub mesh.
Definition Renderable.hpp:38
A structure that holds renderer-specific settings for a Renderable.
Definition RendererRenderableSettings.hpp:15
Definition ScopeExit.hpp:15