renamed model to mesh

This commit is contained in:
2026-09-08 22:48:59 -07:00
parent c211fffda1
commit 73d2121bc1
8 changed files with 41 additions and 42 deletions
+2 -2
View File
@@ -43,8 +43,8 @@ class Application {
private: private:
friend class Canvas; friend class Canvas;
void pushModel(std::vector<CanvasVertex> vertices, std::vector<u32> indices); void pushMesh(std::vector<CanvasVertex> vertices, std::vector<u32> indices);
void clearModels(); void clearMeshes();
class Impl; class Impl;
std::unique_ptr<Impl> impl; std::unique_ptr<Impl> impl;
-1
View File
@@ -2,7 +2,6 @@
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE #define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
+12 -12
View File
@@ -14,7 +14,7 @@
#include "buffer.hpp" #include "buffer.hpp"
#include "device.hpp" #include "device.hpp"
#include "model.hpp" #include "mesh.hpp"
#include "pipelines/graphics_pipeline.hpp" #include "pipelines/graphics_pipeline.hpp"
#include "render_context.hpp" #include "render_context.hpp"
#include "shader.hpp" #include "shader.hpp"
@@ -183,7 +183,7 @@ class Application::Impl {
commandBuffer.setViewport(0, viewport); commandBuffer.setViewport(0, viewport);
commandBuffer.setScissor(0, scissor); commandBuffer.setScissor(0, scissor);
modelRenderSystem.render(commandBuffer, this->models, frameInfo); modelRenderSystem.render(commandBuffer, this->meshes, frameInfo);
commandBuffer.endRendering(); commandBuffer.endRendering();
@@ -205,23 +205,23 @@ class Application::Impl {
log::info("Application ran for", totalRuntime, "s"); log::info("Application ran for", totalRuntime, "s");
} }
void pushModel(std::vector<CanvasVertex> vertices, std::vector<u32> indices) { void pushMesh(std::vector<CanvasVertex> vertices, std::vector<u32> indices) {
Model::Builder builder{}; Mesh::Builder builder{};
builder.vertices.reserve(vertices.size()); builder.vertices.reserve(vertices.size());
for (const CanvasVertex& vertex : vertices) { for (const CanvasVertex& vertex : vertices) {
builder.vertices.push_back({vertex.position, vertex.color}); builder.vertices.push_back({vertex.position, vertex.color});
} }
builder.indices = std::move(indices); builder.indices = std::move(indices);
this->models.push_back(std::make_unique<Model>(this->device, builder)); this->meshes.push_back(std::make_unique<Mesh>(this->device, builder));
} }
void clearModels() { void clearMeshes() {
// Models back live GPU vertex buffers and up to MAX_FRAMES_IN_FLIGHT // Meshes back live GPU vertex buffers and up to MAX_FRAMES_IN_FLIGHT
// command buffers may still be executing against them, so wait for the // command buffers may still be executing against them, so wait for the
// device to go idle before freeing anything. // device to go idle before freeing anything.
this->device.waitIdle(); this->device.waitIdle();
this->models.clear(); this->meshes.clear();
} }
private: private:
@@ -231,7 +231,7 @@ class Application::Impl {
Device device; Device device;
RenderContext renderContext; RenderContext renderContext;
std::vector<std::unique_ptr<Model>> models; std::vector<std::unique_ptr<Mesh>> meshes;
}; };
void Application::setCommandLineArgs(int argc, const char* const* argv) { void Application::setCommandLineArgs(int argc, const char* const* argv) {
@@ -247,11 +247,11 @@ Application::~Application() = default;
void Application::run() { impl->run(); } void Application::run() { impl->run(); }
void Application::pushModel(std::vector<CanvasVertex> vertices, void Application::pushMesh(std::vector<CanvasVertex> vertices,
std::vector<u32> indices) { std::vector<u32> indices) {
impl->pushModel(std::move(vertices), std::move(indices)); impl->pushMesh(std::move(vertices), std::move(indices));
} }
void Application::clearModels() { impl->clearModels(); } void Application::clearMeshes() { impl->clearMeshes(); }
} // namespace sophia } // namespace sophia
+3 -3
View File
@@ -15,7 +15,7 @@ class Canvas::Impl {
{c, color}, {c, color},
}; };
application->pushModel(std::move(vertices), {}); application->pushMesh(std::move(vertices), {});
} }
void quad(glm::vec2 position, glm::vec2 size, void quad(glm::vec2 position, glm::vec2 size,
@@ -28,10 +28,10 @@ class Canvas::Impl {
}; };
std::vector<u32> indices{0, 1, 2, 2, 3, 0}; std::vector<u32> indices{0, 1, 2, 2, 3, 0};
application->pushModel(std::move(vertices), std::move(indices)); application->pushMesh(std::move(vertices), std::move(indices));
} }
void clear() { application->clearModels(); } void clear() { application->clearMeshes(); }
private: private:
Application* application; Application* application;
+9 -9
View File
@@ -1,4 +1,4 @@
#include "model.hpp" #include "mesh.hpp"
#include <cassert> #include <cassert>
#include <sophia/util/logger.hpp> #include <sophia/util/logger.hpp>
@@ -6,7 +6,7 @@
namespace sophia { namespace sophia {
std::vector<vk::VertexInputBindingDescription> std::vector<vk::VertexInputBindingDescription>
Model::Vertex::getBindingDescriptions() { Mesh::Vertex::getBindingDescriptions() {
std::vector<vk::VertexInputBindingDescription> bindingDescriptions(1); std::vector<vk::VertexInputBindingDescription> bindingDescriptions(1);
bindingDescriptions[0].binding = 0; bindingDescriptions[0].binding = 0;
bindingDescriptions[0].stride = sizeof(Vertex); bindingDescriptions[0].stride = sizeof(Vertex);
@@ -16,7 +16,7 @@ Model::Vertex::getBindingDescriptions() {
} }
std::vector<vk::VertexInputAttributeDescription> std::vector<vk::VertexInputAttributeDescription>
Model::Vertex::getAttributeDescriptions() { Mesh::Vertex::getAttributeDescriptions() {
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{}; std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{};
attributeDescriptions.push_back( attributeDescriptions.push_back(
@@ -31,14 +31,14 @@ Model::Vertex::getAttributeDescriptions() {
return attributeDescriptions; return attributeDescriptions;
} }
Model::Model(Device& device, const Builder& builder) : device{device} { Mesh::Mesh(Device& device, const Builder& builder) : device{device} {
createVertexBuffers(builder.vertices); createVertexBuffers(builder.vertices);
createIndexBuffers(builder.indices); createIndexBuffers(builder.indices);
} }
Model::~Model() {} Mesh::~Mesh() {}
void Model::bind(vk::CommandBuffer commandBuffer) { void Mesh::bind(vk::CommandBuffer commandBuffer) {
vk::Buffer buffers[] = {this->vertexBuffer->getBuffer()}; vk::Buffer buffers[] = {this->vertexBuffer->getBuffer()};
vk::DeviceSize offset[] = {0}; vk::DeviceSize offset[] = {0};
commandBuffer.bindVertexBuffers(0, 1, buffers, offset); commandBuffer.bindVertexBuffers(0, 1, buffers, offset);
@@ -49,7 +49,7 @@ void Model::bind(vk::CommandBuffer commandBuffer) {
} }
} }
void Model::draw(vk::CommandBuffer commandBuffer) { void Mesh::draw(vk::CommandBuffer commandBuffer) {
if (this->hasIndexBuffer) { if (this->hasIndexBuffer) {
commandBuffer.drawIndexed(this->indexCount, 1, 0, 0, 0); commandBuffer.drawIndexed(this->indexCount, 1, 0, 0, 0);
} else { } else {
@@ -57,7 +57,7 @@ void Model::draw(vk::CommandBuffer commandBuffer) {
} }
} }
void Model::createVertexBuffers(const std::vector<Vertex>& vertices) { void Mesh::createVertexBuffers(const std::vector<Vertex>& vertices) {
this->vertexCount = static_cast<u32>(vertices.size()); this->vertexCount = static_cast<u32>(vertices.size());
assert(this->vertexCount >= 3 && "vertex count must be at least 3"); assert(this->vertexCount >= 3 && "vertex count must be at least 3");
@@ -87,7 +87,7 @@ void Model::createVertexBuffers(const std::vector<Vertex>& vertices) {
this->vertexBuffer->getBuffer(), bufferSize); this->vertexBuffer->getBuffer(), bufferSize);
} }
void Model::createIndexBuffers(const std::vector<u32>& indicies) { void Mesh::createIndexBuffers(const std::vector<u32>& indicies) {
this->indexCount = static_cast<u32>(indicies.size()); this->indexCount = static_cast<u32>(indicies.size());
this->hasIndexBuffer = this->indexCount > 0; this->hasIndexBuffer = this->indexCount > 0;
+6 -6
View File
@@ -12,7 +12,7 @@
namespace sophia { namespace sophia {
class Model { class Mesh {
public: public:
struct Vertex { struct Vertex {
glm::vec2 position{}; glm::vec2 position{};
@@ -37,13 +37,13 @@ class Model {
// void loadModel(const std::string& filepath); // void loadModel(const std::string& filepath);
}; };
Model(Device& device, const Model::Builder& builder); Mesh(Device& device, const Mesh::Builder& builder);
~Model(); ~Mesh();
Model(const Model&) = delete; Mesh(const Mesh&) = delete;
Model& operator=(const Model&) = delete; Mesh& operator=(const Mesh&) = delete;
// static std::unique_ptr<Model> createModelFromFile( // static std::unique_ptr<Mesh> createMeshFromFile(
// Device& device, const std::string& filepath); // Device& device, const std::string& filepath);
void bind(vk::CommandBuffer commandBuffer); void bind(vk::CommandBuffer commandBuffer);
+6 -6
View File
@@ -24,8 +24,8 @@ ModelRenderSystem::ModelRenderSystem(Device& device,
.setStage(ShaderStage::FRAGMENT) .setStage(ShaderStage::FRAGMENT)
.build(); .build();
auto bindingDescriptions = Model::Vertex::getBindingDescriptions(); auto bindingDescriptions = Mesh::Vertex::getBindingDescriptions();
auto attributeDescriptions = Model::Vertex::getAttributeDescriptions(); auto attributeDescriptions = Mesh::Vertex::getAttributeDescriptions();
this->graphicsPipeline = this->graphicsPipeline =
GraphicsPipeline::Builder(device) GraphicsPipeline::Builder(device)
@@ -42,13 +42,13 @@ ModelRenderSystem::~ModelRenderSystem() {
} }
void ModelRenderSystem::render(vk::CommandBuffer commandBuffer, void ModelRenderSystem::render(vk::CommandBuffer commandBuffer,
std::span<const std::unique_ptr<Model>> models, std::span<const std::unique_ptr<Mesh>> meshes,
const FrameInfo& frameInfo) { const FrameInfo& frameInfo) {
glm::mat4 viewProjection = frameInfo.camera.getViewProjection(); glm::mat4 viewProjection = frameInfo.camera.getViewProjection();
this->graphicsPipeline->bind(commandBuffer); this->graphicsPipeline->bind(commandBuffer);
for (const std::unique_ptr<Model>& model : models) { for (const std::unique_ptr<Mesh>& mesh : meshes) {
PushConstantData push{}; PushConstantData push{};
push.modelMatrix = viewProjection; push.modelMatrix = viewProjection;
@@ -57,8 +57,8 @@ void ModelRenderSystem::render(vk::CommandBuffer commandBuffer,
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
0, sizeof(PushConstantData), &push); 0, sizeof(PushConstantData), &push);
model->bind(commandBuffer); mesh->bind(commandBuffer);
model->draw(commandBuffer); mesh->draw(commandBuffer);
} }
} }
+2 -2
View File
@@ -5,7 +5,7 @@
#include <span> #include <span>
#include "device.hpp" #include "device.hpp"
#include "model.hpp" #include "mesh.hpp"
#include "pipelines/graphics_pipeline.hpp" #include "pipelines/graphics_pipeline.hpp"
#include "render_context.hpp" #include "render_context.hpp"
@@ -25,7 +25,7 @@ class ModelRenderSystem {
~ModelRenderSystem(); ~ModelRenderSystem();
void render(vk::CommandBuffer commandBuffer, void render(vk::CommandBuffer commandBuffer,
std::span<const std::unique_ptr<Model>> models, std::span<const std::unique_ptr<Mesh>> meshes,
const FrameInfo& frameInfo); const FrameInfo& frameInfo);
private: private: