22 "Cannot create a GPU buffer for an entity without a Mesh component.");
25 if (meshComponent->GetNormals().size() != meshComponent->GetVertices().size() ||
26 meshComponent->GetTexCoords().size() != meshComponent->GetVertices().size())
29 "Cannot create GPU buffer: normals or texCoords size mismatch with vertices.");
33 bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Vertex;
34 bufferDesc.size =
sizeof(float) * meshComponent->GetVertices().size() * 8;
35 std::string label = fmt::format(
"PointGPUBuffer_{}",
_entity);
39 _buffer = context.deviceContext.GetDevice()->createBuffer(bufferDesc);
69 "Cannot update a GPU buffer from a Mesh component with no vertices.");
72 const auto &normals = meshComponent.GetNormals();
73 const auto &texCoords = meshComponent.GetTexCoords();
75 if (normals.size() != vertices.size() || texCoords.size() != vertices.size())
78 "Cannot update GPU buffer: normals or texCoords size mismatch with vertices.");
81 std::vector<float> pointData;
82 pointData.reserve(vertices.size() * 8u);
84 for (uint64_t i = 0u; i < vertices.size(); ++i)
86 pointData.emplace_back(vertices[i].x);
87 pointData.emplace_back(vertices[i].y);
88 pointData.emplace_back(vertices[i].z);
89 pointData.emplace_back(normals[i].x);
90 pointData.emplace_back(normals[i].y);
91 pointData.emplace_back(normals[i].z);
92 pointData.emplace_back(texCoords[i].x);
93 pointData.emplace_back(texCoords[i].y);
97 sizeof(
float) * pointData.size());
void Update(Engine::Core &core) override
Definition PointGPUBuffer.hpp:56
wgpu::Buffer _buffer
Definition PointGPUBuffer.hpp:103
bool _isCreated
Definition PointGPUBuffer.hpp:104
void Destroy(Engine::Core &core) override
Definition PointGPUBuffer.hpp:44
const wgpu::Buffer & GetBuffer() const override
Definition PointGPUBuffer.hpp:100
PointGPUBuffer(Engine::Entity entity)
Definition PointGPUBuffer.hpp:12
Engine::Entity _entity
Definition PointGPUBuffer.hpp:105
void Create(Engine::Core &core) override
Definition PointGPUBuffer.hpp:14
bool IsCreated(Engine::Core &core) const override
Definition PointGPUBuffer.hpp:55
~PointGPUBuffer() override
Definition PointGPUBuffer.hpp:13
void Destroy()
Definition PointGPUBuffer.hpp:46
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
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
Mesh structure.
Definition Mesh.hpp:40
const std::vector< glm::vec3 > & GetVertices() const
Definition Mesh.hpp:96