10#include <glm/gtc/type_ptr.hpp>
16 static inline std::string
_debugName =
"PointLightsBuffer";
27 static_assert(
sizeof(
GPUPointLight) == 48,
"GPUPointLight must be 48 bytes for proper GPU alignment.");
30 std::array<GPUPointLight, Utils::MAX_POINT_LIGHTS>
lights;
36 "PointLightsData size does not match expected GPU requirements.");
80 uint32_t skippedCount = 0;
88 const glm::vec3 &position = transform.
GetPosition();
89 const glm::vec3 &color = light.
color;
91 data.lights[index].position = {position.x, position.y, position.z};
92 data.lights[index].intensity = light.
intensity;
93 data.lights[index].color = {color.x, color.y, color.z};
94 data.lights[index].radius = light.
radius;
95 data.lights[index].falloff = light.
falloff;
100 if (skippedCount > 0)
102 Log::Warning(fmt::format(
"Maximum number of point lights ({}) reached. {} light(s) skipped.",
119 bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform;
123 return context.
GetDevice()->createBuffer(bufferDesc);
~PointLightsBuffer() override
Definition PointLightsBuffer.hpp:40
static std::string _debugName
Definition PointLightsBuffer.hpp:16
bool _isCreated
Definition PointLightsBuffer.hpp:127
PointLightsBuffer()=default
const wgpu::Buffer & GetBuffer() const override
Definition PointLightsBuffer.hpp:109
bool IsCreated(Engine::Core &core) const override
Definition PointLightsBuffer.hpp:65
void Destroy(Engine::Core &core) override
Definition PointLightsBuffer.hpp:54
wgpu::Buffer _CreateBuffer(const Graphic::Resource::DeviceContext &context)
Definition PointLightsBuffer.hpp:116
void Update(Engine::Core &core) override
Definition PointLightsBuffer.hpp:67
wgpu::Buffer _buffer
Definition PointLightsBuffer.hpp:126
std::string_view GetDebugName() const
Definition PointLightsBuffer.hpp:111
void Create(Engine::Core &core) override
Definition PointLightsBuffer.hpp:42
static uint32_t GPUSize()
Definition PointLightsBuffer.hpp:113
void Destroy()
Definition PointLightsBuffer.hpp:56
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
TResource & GetResource()
Get a reference of a resource.
Definition Core.inl:14
Registry & GetRegistry()
Get the entt::registry that contains all components. It should be used to update component through sy...
Definition Core.hpp:50
Definition UpdateBufferError.hpp:7
Definition AGPUBuffer.hpp:7
Definition AmbientLight.cpp:6
static constexpr size_t MAX_POINT_LIGHTS
Definition PointLights.hpp:8
void Warning(const T &msg) noexcept
Definition Logger.hpp:49
constexpr DefaultFlag Default
Definition webgpu.hpp:78
StringView(const std::string_view &cpp)
Definition webgpu.hpp:618
Definition PointLightsBuffer.hpp:18
std::array< float, 3 > position
Definition PointLightsBuffer.hpp:19
std::array< float, 3 > _padding
Definition PointLightsBuffer.hpp:24
std::array< float, 3 > color
Definition PointLightsBuffer.hpp:21
float falloff
Definition PointLightsBuffer.hpp:23
float radius
Definition PointLightsBuffer.hpp:22
float intensity
Definition PointLightsBuffer.hpp:20
Definition PointLightsBuffer.hpp:29
uint32_t count
Definition PointLightsBuffer.hpp:31
std::array< float, 3 > _padding
Definition PointLightsBuffer.hpp:32
std::array< GPUPointLight, Utils::MAX_POINT_LIGHTS > lights
Definition PointLightsBuffer.hpp:30
Definition DeviceContext.hpp:7
auto & GetDevice()
Definition DeviceContext.hpp:13
Definition PointLight.hpp:7
glm::vec3 color
Definition PointLight.hpp:8
float intensity
Definition PointLight.hpp:9
float falloff
Definition PointLight.hpp:11
float radius
Definition PointLight.hpp:10