23 "Cannot create a GPU buffer for an entity without a Mesh component.");
26 if (meshComponent->GetNormals().size() != meshComponent->GetVertices().size() ||
27 meshComponent->GetTexCoords().size() != meshComponent->GetVertices().size())
30 "Cannot create GPU buffer: normals or texCoords size mismatch with vertices.");
34 bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Vertex;
35 bufferDesc.size =
sizeof(float) * meshComponent->GetVertices().size() * 8;
36 std::string label = fmt::format(
"PointGPUBuffer_{}",
_entity);
40 _buffer = deviceContext.GetDevice()->createBuffer(bufferDesc);
70 "Cannot update a GPU buffer from a Mesh component with no vertices.");
73 const auto &normals = meshComponent.GetNormals();
74 const auto &texCoords = meshComponent.GetTexCoords();
76 if (normals.size() != vertices.size() || texCoords.size() != vertices.size())
79 "Cannot update GPU buffer: normals or texCoords size mismatch with vertices.");
82 std::vector<float> pointData;
83 pointData.reserve(vertices.size() * 8u);
85 for (uint64_t i = 0u; i < vertices.size(); ++i)
87 pointData.emplace_back(vertices[i].x);
88 pointData.emplace_back(vertices[i].y);
89 pointData.emplace_back(vertices[i].z);
90 pointData.emplace_back(normals[i].x);
91 pointData.emplace_back(normals[i].y);
92 pointData.emplace_back(normals[i].z);
93 pointData.emplace_back(texCoords[i].x);
94 pointData.emplace_back(texCoords[i].y);
98 sizeof(
float) * pointData.size());
void Update(Engine::Core &core) override
Definition PointGPUBuffer.hpp:57
wgpu::Buffer _buffer
Definition PointGPUBuffer.hpp:104
bool _isCreated
Definition PointGPUBuffer.hpp:105
void Destroy(Engine::Core &core) override
Definition PointGPUBuffer.hpp:45
const wgpu::Buffer & GetBuffer() const override
Definition PointGPUBuffer.hpp:101
PointGPUBuffer(Engine::Entity entity)
Definition PointGPUBuffer.hpp:13
Engine::Entity _entity
Definition PointGPUBuffer.hpp:106
void Create(Engine::Core &core) override
Definition PointGPUBuffer.hpp:15
bool IsCreated(Engine::Core &core) const override
Definition PointGPUBuffer.hpp:56
~PointGPUBuffer() override
Definition PointGPUBuffer.hpp:14
void Destroy()
Definition PointGPUBuffer.hpp:47
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.ipp:14
Wrapper class providing a convenient interface for entity manipulation with the Core....
Definition Entity.hpp:20
Definition NonexistentComponentError.hpp:7
Definition UpdateBufferError.hpp:7
Definition AGPUBuffer.hpp:7
Definition AmbientLight.cpp:6
constexpr DefaultFlag Default
Definition webgpu.hpp:78
StringView(const std::string_view &cpp)
Definition webgpu.hpp:618
Definition DeviceContext.hpp:7
Mesh structure.
Definition Mesh.hpp:40
const std::vector< glm::vec3 > & GetVertices() const
Definition Mesh.hpp:96