renamed model to mesh
This commit is contained in:
@@ -43,8 +43,8 @@ class Application {
|
||||
private:
|
||||
friend class Canvas;
|
||||
|
||||
void pushModel(std::vector<CanvasVertex> vertices, std::vector<u32> indices);
|
||||
void clearModels();
|
||||
void pushMesh(std::vector<CanvasVertex> vertices, std::vector<u32> indices);
|
||||
void clearMeshes();
|
||||
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
+12
-12
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "buffer.hpp"
|
||||
#include "device.hpp"
|
||||
#include "model.hpp"
|
||||
#include "mesh.hpp"
|
||||
#include "pipelines/graphics_pipeline.hpp"
|
||||
#include "render_context.hpp"
|
||||
#include "shader.hpp"
|
||||
@@ -183,7 +183,7 @@ class Application::Impl {
|
||||
commandBuffer.setViewport(0, viewport);
|
||||
commandBuffer.setScissor(0, scissor);
|
||||
|
||||
modelRenderSystem.render(commandBuffer, this->models, frameInfo);
|
||||
modelRenderSystem.render(commandBuffer, this->meshes, frameInfo);
|
||||
|
||||
commandBuffer.endRendering();
|
||||
|
||||
@@ -205,23 +205,23 @@ class Application::Impl {
|
||||
log::info("Application ran for", totalRuntime, "s");
|
||||
}
|
||||
|
||||
void pushModel(std::vector<CanvasVertex> vertices, std::vector<u32> indices) {
|
||||
Model::Builder builder{};
|
||||
void pushMesh(std::vector<CanvasVertex> vertices, std::vector<u32> indices) {
|
||||
Mesh::Builder builder{};
|
||||
builder.vertices.reserve(vertices.size());
|
||||
for (const CanvasVertex& vertex : vertices) {
|
||||
builder.vertices.push_back({vertex.position, vertex.color});
|
||||
}
|
||||
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() {
|
||||
// Models back live GPU vertex buffers and up to MAX_FRAMES_IN_FLIGHT
|
||||
void clearMeshes() {
|
||||
// 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
|
||||
// device to go idle before freeing anything.
|
||||
this->device.waitIdle();
|
||||
this->models.clear();
|
||||
this->meshes.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -231,7 +231,7 @@ class Application::Impl {
|
||||
Device device;
|
||||
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) {
|
||||
@@ -247,11 +247,11 @@ Application::~Application() = default;
|
||||
|
||||
void Application::run() { impl->run(); }
|
||||
|
||||
void Application::pushModel(std::vector<CanvasVertex> vertices,
|
||||
void Application::pushMesh(std::vector<CanvasVertex> vertices,
|
||||
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
|
||||
|
||||
@@ -15,7 +15,7 @@ class Canvas::Impl {
|
||||
{c, color},
|
||||
};
|
||||
|
||||
application->pushModel(std::move(vertices), {});
|
||||
application->pushMesh(std::move(vertices), {});
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
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:
|
||||
Application* application;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "model.hpp"
|
||||
#include "mesh.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <sophia/util/logger.hpp>
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace sophia {
|
||||
|
||||
std::vector<vk::VertexInputBindingDescription>
|
||||
Model::Vertex::getBindingDescriptions() {
|
||||
Mesh::Vertex::getBindingDescriptions() {
|
||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions(1);
|
||||
bindingDescriptions[0].binding = 0;
|
||||
bindingDescriptions[0].stride = sizeof(Vertex);
|
||||
@@ -16,7 +16,7 @@ Model::Vertex::getBindingDescriptions() {
|
||||
}
|
||||
|
||||
std::vector<vk::VertexInputAttributeDescription>
|
||||
Model::Vertex::getAttributeDescriptions() {
|
||||
Mesh::Vertex::getAttributeDescriptions() {
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{};
|
||||
|
||||
attributeDescriptions.push_back(
|
||||
@@ -31,14 +31,14 @@ Model::Vertex::getAttributeDescriptions() {
|
||||
return attributeDescriptions;
|
||||
}
|
||||
|
||||
Model::Model(Device& device, const Builder& builder) : device{device} {
|
||||
Mesh::Mesh(Device& device, const Builder& builder) : device{device} {
|
||||
createVertexBuffers(builder.vertices);
|
||||
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::DeviceSize offset[] = {0};
|
||||
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) {
|
||||
commandBuffer.drawIndexed(this->indexCount, 1, 0, 0, 0);
|
||||
} 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());
|
||||
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);
|
||||
}
|
||||
|
||||
void Model::createIndexBuffers(const std::vector<u32>& indicies) {
|
||||
void Mesh::createIndexBuffers(const std::vector<u32>& indicies) {
|
||||
this->indexCount = static_cast<u32>(indicies.size());
|
||||
this->hasIndexBuffer = this->indexCount > 0;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class Model {
|
||||
class Mesh {
|
||||
public:
|
||||
struct Vertex {
|
||||
glm::vec2 position{};
|
||||
@@ -37,13 +37,13 @@ class Model {
|
||||
// void loadModel(const std::string& filepath);
|
||||
};
|
||||
|
||||
Model(Device& device, const Model::Builder& builder);
|
||||
~Model();
|
||||
Mesh(Device& device, const Mesh::Builder& builder);
|
||||
~Mesh();
|
||||
|
||||
Model(const Model&) = delete;
|
||||
Model& operator=(const Model&) = delete;
|
||||
Mesh(const Mesh&) = delete;
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
|
||||
// static std::unique_ptr<Model> createModelFromFile(
|
||||
// static std::unique_ptr<Mesh> createMeshFromFile(
|
||||
// Device& device, const std::string& filepath);
|
||||
|
||||
void bind(vk::CommandBuffer commandBuffer);
|
||||
@@ -24,8 +24,8 @@ ModelRenderSystem::ModelRenderSystem(Device& device,
|
||||
.setStage(ShaderStage::FRAGMENT)
|
||||
.build();
|
||||
|
||||
auto bindingDescriptions = Model::Vertex::getBindingDescriptions();
|
||||
auto attributeDescriptions = Model::Vertex::getAttributeDescriptions();
|
||||
auto bindingDescriptions = Mesh::Vertex::getBindingDescriptions();
|
||||
auto attributeDescriptions = Mesh::Vertex::getAttributeDescriptions();
|
||||
|
||||
this->graphicsPipeline =
|
||||
GraphicsPipeline::Builder(device)
|
||||
@@ -42,13 +42,13 @@ ModelRenderSystem::~ModelRenderSystem() {
|
||||
}
|
||||
|
||||
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) {
|
||||
glm::mat4 viewProjection = frameInfo.camera.getViewProjection();
|
||||
|
||||
this->graphicsPipeline->bind(commandBuffer);
|
||||
|
||||
for (const std::unique_ptr<Model>& model : models) {
|
||||
for (const std::unique_ptr<Mesh>& mesh : meshes) {
|
||||
PushConstantData push{};
|
||||
push.modelMatrix = viewProjection;
|
||||
|
||||
@@ -57,8 +57,8 @@ void ModelRenderSystem::render(vk::CommandBuffer commandBuffer,
|
||||
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
|
||||
0, sizeof(PushConstantData), &push);
|
||||
|
||||
model->bind(commandBuffer);
|
||||
model->draw(commandBuffer);
|
||||
mesh->bind(commandBuffer);
|
||||
mesh->draw(commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <span>
|
||||
|
||||
#include "device.hpp"
|
||||
#include "model.hpp"
|
||||
#include "mesh.hpp"
|
||||
#include "pipelines/graphics_pipeline.hpp"
|
||||
#include "render_context.hpp"
|
||||
|
||||
@@ -25,7 +25,7 @@ class ModelRenderSystem {
|
||||
~ModelRenderSystem();
|
||||
|
||||
void render(vk::CommandBuffer commandBuffer,
|
||||
std::span<const std::unique_ptr<Model>> models,
|
||||
std::span<const std::unique_ptr<Mesh>> meshes,
|
||||
const FrameInfo& frameInfo);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user