Add mesh class
- Fix compile errors due to not adding files to git
This commit is contained in:
@@ -20,8 +20,8 @@ namespace Copium
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, bindingOffsets.size(), buffers.data(), bindingOffsets.data());
|
||||
}
|
||||
|
||||
void VertexBuffer::Update(uint32_t binding, void* data)
|
||||
void VertexBuffer::UpdateStaging(uint32_t binding, void* data)
|
||||
{
|
||||
UpdateStaging(data, bindingOffsets[binding], bindingSizes[binding]);
|
||||
Buffer::UpdateStaging(data, bindingOffsets[binding], bindingSizes[binding]);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,6 @@ namespace Copium
|
||||
VertexBuffer(Instance& instance, const VertexDescriptor& descriptor, int vertexCount);
|
||||
|
||||
void Bind(const CommandBuffer& commandBuffer);
|
||||
void Update(uint32_t binding, void* data);
|
||||
void UpdateStaging(uint32_t binding, void* data);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ namespace Copium
|
||||
InitializeTextureSampler();
|
||||
InitializeUniformBuffer();
|
||||
InitializeDescriptorSets();
|
||||
InitializeVertexBuffer();
|
||||
InitializeIndexBuffer();
|
||||
InitializeMesh();
|
||||
InitializeCommandBuffer();
|
||||
}
|
||||
|
||||
@@ -126,22 +125,10 @@ namespace Copium
|
||||
graphicsPipelinePassthrough = std::make_unique<Pipeline>(*instance, creatorPassthrough);
|
||||
}
|
||||
|
||||
void Application::InitializeVertexBuffer()
|
||||
void Application::InitializeMesh()
|
||||
{
|
||||
vertexBuffer = std::make_unique<VertexBuffer>(*instance, Vertex::GetDescriptor(), vertices.size());
|
||||
vertexBuffer->Update(0, (void*)vertices.data());
|
||||
|
||||
vertexBufferPassthrough = std::make_unique<VertexBuffer>(*instance, VertexPassthrough::GetDescriptor(), verticesPassthrough.size());
|
||||
vertexBufferPassthrough->Update(0, (void*)verticesPassthrough.data());
|
||||
}
|
||||
|
||||
void Application::InitializeIndexBuffer()
|
||||
{
|
||||
indexBuffer = std::make_unique<IndexBuffer>(*instance, indices.size());
|
||||
indexBuffer->UpdateStaging((void*)indices.data());
|
||||
|
||||
indexBufferPassthrough = std::make_unique<IndexBuffer>(*instance, indicesPassthrough.size());
|
||||
indexBufferPassthrough->UpdateStaging((void*)indicesPassthrough.data());
|
||||
mesh = std::make_unique<Mesh>(*instance, vertices, indices);
|
||||
meshPassthrough = std::make_unique<Mesh>(*instance, verticesPassthrough, indicesPassthrough);
|
||||
}
|
||||
|
||||
void Application::InitializeCommandBuffer()
|
||||
@@ -158,13 +145,12 @@ namespace Copium
|
||||
|
||||
UpdateUniformBuffer();
|
||||
|
||||
vertexBuffer->Bind(*commandBuffer);
|
||||
indexBuffer->Bind(*commandBuffer);
|
||||
|
||||
graphicsPipeline->SetDescriptorSet(0, *descriptorSet);
|
||||
graphicsPipeline->BindDescriptorSets(*commandBuffer);
|
||||
|
||||
indexBuffer->Draw(*commandBuffer);
|
||||
mesh->Bind(*commandBuffer);
|
||||
mesh->Render(*commandBuffer);
|
||||
|
||||
framebuffer->Unbind(*commandBuffer);
|
||||
|
||||
instance->GetSwapChain().BeginFrameBuffer(*commandBuffer);
|
||||
@@ -172,9 +158,9 @@ namespace Copium
|
||||
graphicsPipelinePassthrough->Bind(*commandBuffer);
|
||||
graphicsPipelinePassthrough->SetDescriptorSet(0, *descriptorSetPassthrough);
|
||||
graphicsPipelinePassthrough->BindDescriptorSets(*commandBuffer);
|
||||
vertexBufferPassthrough->Bind(*commandBuffer);
|
||||
indexBufferPassthrough->Bind(*commandBuffer);
|
||||
indexBufferPassthrough->Draw(*commandBuffer);
|
||||
|
||||
meshPassthrough->Bind(*commandBuffer);
|
||||
meshPassthrough->Render(*commandBuffer);
|
||||
|
||||
instance->GetSwapChain().EndFrameBuffer(*commandBuffer);
|
||||
commandBuffer->End();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "copium/buffer/UniformBuffer.h"
|
||||
#include "copium/buffer/VertexBuffer.h"
|
||||
#include "copium/core/Instance.h"
|
||||
#include "copium/mesh/Mesh.h"
|
||||
#include "copium/pipeline/DescriptorPool.h"
|
||||
#include "copium/pipeline/DescriptorSet.h"
|
||||
#include "copium/pipeline/Pipeline.h"
|
||||
@@ -17,20 +18,18 @@ namespace Copium
|
||||
CP_DELETE_COPY_AND_MOVE_CTOR(Application);
|
||||
private:
|
||||
std::unique_ptr<Instance> instance;
|
||||
std::unique_ptr<Pipeline> graphicsPipeline;
|
||||
std::unique_ptr<Framebuffer> framebuffer;
|
||||
std::unique_ptr<Texture2D> texture2D;
|
||||
std::unique_ptr<UniformBuffer> shaderUniformBuffer;
|
||||
std::unique_ptr<DescriptorPool> descriptorPool;
|
||||
std::unique_ptr<DescriptorSet> descriptorSet;
|
||||
std::unique_ptr<VertexBuffer> vertexBuffer;
|
||||
std::unique_ptr<IndexBuffer> indexBuffer;
|
||||
std::unique_ptr<DescriptorSet> descriptorSetPassthrough;
|
||||
std::unique_ptr<Pipeline> graphicsPipeline;
|
||||
std::unique_ptr<Pipeline> graphicsPipelinePassthrough;
|
||||
std::unique_ptr<Mesh> mesh;
|
||||
std::unique_ptr<Mesh> meshPassthrough;
|
||||
std::unique_ptr<CommandBuffer> commandBuffer;
|
||||
|
||||
std::unique_ptr<Framebuffer> framebuffer;
|
||||
std::unique_ptr<Pipeline> graphicsPipelinePassthrough;
|
||||
std::unique_ptr<VertexBuffer> vertexBufferPassthrough;
|
||||
std::unique_ptr<IndexBuffer> indexBufferPassthrough;
|
||||
std::unique_ptr<DescriptorSet> descriptorSetPassthrough;
|
||||
|
||||
public:
|
||||
Application();
|
||||
@@ -44,9 +43,9 @@ namespace Copium
|
||||
void InitializeUniformBuffer();
|
||||
void InitializeDescriptorSets();
|
||||
void InitializeGraphicsPipeline();
|
||||
void InitializeVertexBuffer();
|
||||
void InitializeIndexBuffer();
|
||||
void InitializeMesh();
|
||||
void InitializeCommandBuffer();
|
||||
|
||||
void RecordCommandBuffer();
|
||||
void UpdateUniformBuffer();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "copium/mesh/Mesh.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
void Mesh::Bind(const CommandBuffer& commandBuffer)
|
||||
{
|
||||
indexBuffer->Bind(commandBuffer);
|
||||
vertexBuffer->Bind(commandBuffer);
|
||||
}
|
||||
|
||||
void Mesh::Render(const CommandBuffer& commandBuffer)
|
||||
{
|
||||
indexBuffer->Draw(commandBuffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "copium/buffer/IndexBuffer.h"
|
||||
#include "copium/buffer/VertexBuffer.h"
|
||||
#include "copium/buffer/CommandBuffer.h"
|
||||
#include "copium/core/Instance.h"
|
||||
#include "copium/util/Common.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
class Mesh
|
||||
{
|
||||
CP_DELETE_COPY_AND_MOVE_CTOR(Mesh);
|
||||
private:
|
||||
std::unique_ptr<IndexBuffer> indexBuffer;
|
||||
std::unique_ptr<VertexBuffer> vertexBuffer;
|
||||
public:
|
||||
template <typename T>
|
||||
Mesh(Instance& instance, const std::vector<T>& vertices, const std::vector<uint16_t>& indices);
|
||||
|
||||
void Bind(const CommandBuffer& commandBuffer);
|
||||
void Render(const CommandBuffer& commandBuffer);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Mesh::Mesh(Instance& instance, const std::vector<T>& vertices, const std::vector<uint16_t>& indices)
|
||||
{
|
||||
indexBuffer = std::make_unique<IndexBuffer>(instance, indices.size());
|
||||
indexBuffer->UpdateStaging((void*)indices.data());
|
||||
vertexBuffer = std::make_unique<VertexBuffer>(instance, T::GetDescriptor(), vertices.size());
|
||||
vertexBuffer ->UpdateStaging(0, (void*)vertices.data());
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ namespace Copium
|
||||
|
||||
VkSamplerCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
createInfo.magFilter = VK_FILTER_LINEAR;
|
||||
createInfo.minFilter = VK_FILTER_LINEAR;
|
||||
createInfo.magFilter = VK_FILTER_LINEAR; // TODO: Some way to control this
|
||||
createInfo.minFilter = VK_FILTER_LINEAR; // TODO: Some way to control this
|
||||
createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
|
||||
Reference in New Issue
Block a user