Huge changes for 3d

This commit is contained in:
2026-09-30 18:53:16 -07:00
parent cd2e80cfca
commit b5b0eb9497
53 changed files with 1313 additions and 457 deletions
+18 -28
View File
@@ -5,35 +5,23 @@
namespace sophia {
std::vector<vk::VertexInputBindingDescription>
Mesh::Vertex::getBindingDescriptions() {
std::vector<vk::VertexInputBindingDescription> bindingDescriptions(1);
bindingDescriptions[0].binding = 0;
bindingDescriptions[0].stride = sizeof(Vertex);
bindingDescriptions[0].inputRate = vk::VertexInputRate::eVertex;
return bindingDescriptions;
std::vector<vk::VertexInputBindingDescription> Mesh::getBindingDescriptions() {
return {{0, sizeof(MeshVertex), vk::VertexInputRate::eVertex}};
}
std::vector<vk::VertexInputAttributeDescription>
Mesh::Vertex::getAttributeDescriptions() {
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{};
attributeDescriptions.push_back(
{0, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, position)});
attributeDescriptions.push_back(
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, color)});
// attributeDescriptions.push_back(
// {2, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, normal)});
// attributeDescriptions.push_back(
// {3, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, uv)});
return attributeDescriptions;
Mesh::getAttributeDescriptions() {
return {
{0, 0, vk::Format::eR32G32B32Sfloat, offsetof(MeshVertex, position)},
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(MeshVertex, normal)},
{2, 0, vk::Format::eR32G32Sfloat, offsetof(MeshVertex, uv)},
{3, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(MeshVertex, color)},
};
}
Mesh::Mesh(Device& device, const Builder& builder) : device{device} {
createVertexBuffers(builder.vertices);
createIndexBuffers(builder.indices);
Mesh::Mesh(Device& device, const MeshData& data) : device{device} {
createVertexBuffers(data.vertices);
createIndexBuffers(data.indices);
}
Mesh::~Mesh() = default;
@@ -49,15 +37,17 @@ void Mesh::bind(vk::CommandBuffer commandBuffer) const {
}
}
void Mesh::draw(vk::CommandBuffer commandBuffer) const {
void Mesh::draw(vk::CommandBuffer commandBuffer, u32 instanceCount,
u32 firstInstance) const {
if (this->hasIndexBuffer) {
commandBuffer.drawIndexed(this->indexCount, 1, 0, 0, 0);
commandBuffer.drawIndexed(this->indexCount, instanceCount, 0, 0,
firstInstance);
} else {
commandBuffer.draw(this->vertexCount, 1, 0, 0);
commandBuffer.draw(this->vertexCount, instanceCount, 0, firstInstance);
}
}
void Mesh::createVertexBuffers(const std::vector<Vertex>& vertices) {
void Mesh::createVertexBuffers(const std::vector<MeshVertex>& vertices) {
this->vertexCount = static_cast<u32>(vertices.size());
SOPHIA_ASSERT(this->vertexCount >= 3, "vertex count must be at least 3");