CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RendererEnvironment.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"
12
15
17
23
24namespace CeresEngine {
25
27
31 Skybox,
32
34 Baked,
35
38 Probe
39 };
40
45 None = 0,
46
48 Component = (1u << 1u),
49
51 UniformBuffer = (1u << 2u),
52
54 Flags = (1u << 3u),
55
57 All = 0xFFFF,
58 };
59
63
64
144
149
206
211
212 private:
216
217 public:
220
224
225 public:
232
233 public:
235
242 template<typename... Args> ObjectType& create(Args&&... args) {
243 const RendererObjectID objectID = RendererObjectID(mEnvironments.size());
244
245 ObjectType* const object = mEnvironments.emplace_back(ce_unique_new<RendererSkyboxEnvironment>(*this, std::forward<Args>(args)...)).get();
246 CE_ASSERT(object != nullptr);
247
248 // NOTE: Directly setting the ID as nothing should be
249 // subscribing to the ID change event yet.
250 notifyChangeID(*object, objectID);
251 // object->mID = objectID;
252
253 return *object;
254 }
255
260 void destroy(const ObjectType& object) {
261 const RendererObjectID objectID = object.mID;
262 std::swap(mEnvironments[objectID], mEnvironments.back());
263 notifyChangeID(*mEnvironments[objectID], objectID);
264
265 mEnvironments.pop_back();
266 }
267
268 private: // Environment interface
270
273 void markAsDirty(RendererEnvironment* const environment);
274 };
275
276} // namespace CeresEngine
#define CE_FLAGS_OPERATORS(Enum)
Defines global operators for a Flags<Enum, Storage> implementation.
Definition Flags.hpp:216
#define CE_ASSERT(...)
Definition Macros.hpp:323
#define CE_DECL_RENDERER_OBJECT(T)
Definition RendererObject.hpp:25
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUBufferObject.hpp:562
Definition GPUBufferObject.hpp:221
A class that represents a environment inside the renderer.
Definition RendererEnvironment.hpp:67
void markAsDirty(const RendererEnvironmentDirtyFlags &flags=RendererEnvironmentDirtyFlag::All) noexcept
GPUImagePtr prefilterRadianceMap(RendererContext &context, const GPUImagePtr &environmentMap)
Generates a specular pre-filtered reflection map using environmentMap as a base.
EnvironmentComponent mComponent
A copy of the latest environment component.
Definition RendererEnvironment.hpp:73
GPUImagePtr equirectangularToCubeMap(RendererContext &context, const GPUImagePtr &environmentMap)
virtual const GPUUniformBuffer & getUniformBuffer() const =0
The uniform buffer storing the environment GPU parameters used by the renderer.
RendererEnvironment(RendererEnvironmentManager &manager, RendererScene &scene)
Creates a new RendererEnvironment.
bool isDirty() const noexcept
Definition RendererEnvironment.hpp:139
virtual ~RendererEnvironment()
Destroys the renderer environment and releases any renderer (and RenderAPI)-related resources.
virtual RendererEnvironmentType getType() const noexcept=0
Determines the type of environment.
GPUImagePtr prefilterIrradianceMap(RendererContext &context, const GPUImagePtr &environmentMap)
Generates a diffuse irradiance map for the given environmentMap.
void synchronize(const EnvironmentComponent &component)
Update the renderer environment with data from a transform and the component.
virtual void prepare(RendererContext &context)
Prepares the environment for the rendering of the current frame.
A manager that controls all environments currently registered with the renderer.
Definition RendererEnvironment.hpp:209
ObjectType & create(Args &&... args)
Creates a new renderer object by calling it's constructor.
Definition RendererEnvironment.hpp:242
Vector< UPtr< RendererSkyboxEnvironment > > mEnvironments
A vector of all registered environments.
Definition RendererEnvironment.hpp:215
void destroy(const ObjectType &object)
Destroys an existing renderer object by calling it's destructor and releasing it's memory.
Definition RendererEnvironment.hpp:260
void markAsDirty(RendererEnvironment *const environment)
Marks the given environment as dirty.
Async prepare(RendererContext &context)
Prepares the environments for the rendering of the current frame.
RendererEnvironmentManager(Renderer &renderer)
Creates a new instance of the RendererEnvironmentManager.
friend class RendererEnvironment
Definition RendererEnvironment.hpp:269
~RendererEnvironmentManager()
Destroys the RendererEnvironmentManager and releases all environments objects managed by it.
The CeresEngine renderer.
Definition Renderer.hpp:35
void notifyChangeID(RendererObject &object, const RendererObjectID newID) noexcept
Method called whenever the RendererObject ID changes.
Definition RendererObject.hpp:126
A class that represents a scene inside the renderer.
Definition RendererScene.hpp:34
A base class for all renderer scene object managers.
Definition RendererSceneObject.hpp:68
The implementation for skybox environment type.
Definition RendererEnvironment.hpp:151
GPUDynamicUniformBuffer< RendererSkyboxEnvironmentParams > mUniformBuffer
The uniform buffer storing the environment GPU parameters used by the renderer.
Definition RendererEnvironment.hpp:170
RendererTexturePtr mRadianceMap
The (specular) radiance map for the skybox texture.
Definition RendererEnvironment.hpp:166
const RendererTexturePtr & getSkyboxTexture() const noexcept
A texture that represents the scene sky.
Definition RendererEnvironment.hpp:198
const RendererTexturePtr & getRadianceMap() const noexcept
The (specular) radiance map for the skybox texture.
Definition RendererEnvironment.hpp:204
const RendererTexturePtr & getIrradianceMap() const noexcept
The (diffuse) irradiance map for the skybox texture.
Definition RendererEnvironment.hpp:201
RendererSkyboxEnvironment(RendererEnvironmentManager &manager, RendererScene &scene)
Creates a new RendererSkyboxEnvironment.
RendererTexturePtr mOriginalSkyboxTexture
Definition RendererEnvironment.hpp:156
RendererTexturePtr mSkyboxTexture
A texture that represents the scene sky.
Definition RendererEnvironment.hpp:160
const GPUUniformBuffer & getUniformBuffer() const final
The uniform buffer storing the environment GPU parameters used by the renderer.
Definition RendererEnvironment.hpp:195
void prepare(RendererContext &context) override
Prepares the environment for the rendering of the current frame.
~RendererSkyboxEnvironment() override
Destroys the renderer environment and releases any renderer (and RenderAPI)-related resources.
RendererEnvironmentType getType() const noexcept final
Determines the type of environment.
Definition RendererEnvironment.hpp:192
RendererTexturePtr mIrradianceMap
The (diffuse) irradiance map for the skybox texture.
Definition RendererEnvironment.hpp:163
Template class to help implement sub-classes of RendererSceneObject.
Definition RendererSceneObject.hpp:47
Definition Application.hpp:19
RendererEnvironmentDirtyFlag
Flags that can be either set by the renderer or by the user to customize the behavior of the mesh.
Definition RendererEnvironment.hpp:43
@ None
Special value that represents a clean (i.e. non-dirty) object.
@ All
Special value that represents a dirty object with all parts dirty.
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
@ UniformBuffer
Uniform buffer (or constant buffer) resource.
RendererEnvironmentType
Enumeration that determines the type of renderer environment.
Definition RendererEnvironment.hpp:29
@ Baked
Indicates that the environment a baked environment map.
@ Skybox
Indicates that the environment is a simple skybox.
@ Probe
Indicates that the environment is captured dynamically on the scene using a probe.
std::uint32_t UInt32
Definition DataTypes.hpp:23
@ All
Specifies all shader stages.
UInt32 RendererObjectID
A type-alias for a type that uniquely identifies a RendererObject.
Definition RendererObject.hpp:35
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
The Environment component.
Definition Environment.hpp:23
Wrapper around an enum that allows simple use of bitwise logic operations.
Definition Flags.hpp:19
A structure that contains context given by the renderer to render it's objects.
Definition Renderer.hpp:252
A structure that mirrors the GPU uniform data for the skybox environment.
Definition RendererEnvironment.hpp:146
UInt32 prefilteredMipLevels
Definition RendererEnvironment.hpp:147