diff --git a/CopiumEngine/CopiumEngine.vcxproj b/CopiumEngine/CopiumEngine.vcxproj
index 4490e3e..1aa92ae 100644
--- a/CopiumEngine/CopiumEngine.vcxproj
+++ b/CopiumEngine/CopiumEngine.vcxproj
@@ -119,6 +119,7 @@
true
$(ProjectDir)ext/include/;C:/VulkanSDK/1.3.236.0/Include;%(AdditionalIncludeDirectories)$(ProjectDir)src/
stdcpp17
+ true
Console
@@ -145,6 +146,7 @@
true
$(ProjectDir)ext/include/;C:/VulkanSDK/1.3.236.0/Include;%(AdditionalIncludeDirectories)$(ProjectDir)src/
stdcpp17
+ true
Console
diff --git a/CopiumEngine/src/copium/buffer/Buffer.cpp b/CopiumEngine/src/copium/buffer/Buffer.cpp
index 1c2256d..53845d1 100644
--- a/CopiumEngine/src/copium/buffer/Buffer.cpp
+++ b/CopiumEngine/src/copium/buffer/Buffer.cpp
@@ -1,12 +1,11 @@
#include "copium/buffer/Buffer.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- Buffer::Buffer(Vulkan& vulkan, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
- : vulkan{vulkan}, size{size}, count{count}
+ Buffer::Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
+ : size{size}, count{count}
{
VkBufferCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@@ -14,25 +13,25 @@ namespace Copium
createInfo.usage = usage;
createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- CP_VK_ASSERT(vkCreateBuffer(vulkan.GetDevice(), &createInfo, nullptr, &handle), "Buffer : Failed to initialize buffer");
+ CP_VK_ASSERT(vkCreateBuffer(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Buffer : Failed to initialize buffer");
VkMemoryRequirements memoryRequirements;
- vkGetBufferMemoryRequirements(vulkan.GetDevice(), handle, &memoryRequirements);
+ vkGetBufferMemoryRequirements(Vulkan::GetDevice(), handle, &memoryRequirements);
VkMemoryAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.allocationSize = memoryRequirements.size;
- allocateInfo.memoryTypeIndex = vulkan.GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
+ allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
- CP_VK_ASSERT(vkAllocateMemory(vulkan.GetDevice(), &allocateInfo, nullptr, &memory), "Buffer : Failed to allocate buffer memory");
+ CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), "Buffer : Failed to allocate buffer memory");
- vkBindBufferMemory(vulkan.GetDevice(), handle, memory, 0);
+ vkBindBufferMemory(Vulkan::GetDevice(), handle, memory, 0);
}
Buffer::~Buffer()
{
- vkFreeMemory(vulkan.GetDevice(), memory, nullptr);
- vkDestroyBuffer(vulkan.GetDevice(), handle, nullptr);
+ vkFreeMemory(Vulkan::GetDevice(), memory, nullptr);
+ vkDestroyBuffer(Vulkan::GetDevice(), handle, nullptr);
}
void Buffer::Update(void* indexData, int index)
@@ -42,9 +41,9 @@ namespace Copium
if (mappedData == nullptr)
{
void* data;
- vkMapMemory(vulkan.GetDevice(), memory, index * size, size, 0, &data);
+ vkMapMemory(Vulkan::GetDevice(), memory, index * size, size, 0, &data);
memcpy(data, indexData, size);
- vkUnmapMemory(vulkan.GetDevice(), memory);
+ vkUnmapMemory(Vulkan::GetDevice(), memory);
}
else
{
@@ -55,26 +54,26 @@ namespace Copium
void Buffer::UpdateStaging(void* data)
{
VkDeviceSize bufferSize = size * count;
- Buffer stagingBuffer{vulkan, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1};
+ Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1};
stagingBuffer.Update(data, 0);
- CopyBuffer(vulkan, stagingBuffer, *this, 0, bufferSize);
+ CopyBuffer(stagingBuffer, *this, 0, bufferSize);
}
void Buffer::UpdateStaging(void* data, VkDeviceSize offset, VkDeviceSize size)
{
- Buffer stagingBuffer{vulkan, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, size, 1};
+ Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, size, 1};
stagingBuffer.Update(data, 0);
- CopyBuffer(vulkan, stagingBuffer, *this, offset, size);
+ CopyBuffer(stagingBuffer, *this, offset, size);
}
void* Buffer::Map()
{
CP_ASSERT(mappedData == nullptr, "Map : Mapping an already mapped buffer");
- vkMapMemory(vulkan.GetDevice(), memory, 0, size * count, 0, &mappedData);
+ vkMapMemory(Vulkan::GetDevice(), memory, 0, size * count, 0, &mappedData);
return mappedData;
}
@@ -82,7 +81,7 @@ namespace Copium
{
CP_ASSERT(mappedData != nullptr, "Unmap : Unmapping an already unmapped buffer");
- vkUnmapMemory(vulkan.GetDevice(), memory);
+ vkUnmapMemory(Vulkan::GetDevice(), memory);
mappedData = nullptr;
}
@@ -102,17 +101,17 @@ namespace Copium
return size * (VkDeviceSize)index;
}
- void Buffer::CopyBuffer(Vulkan& vulkan, const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size)
+ void Buffer::CopyBuffer(const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size)
{
VkCommandBufferAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
- allocateInfo.commandPool = vulkan.GetDevice().GetCommandPool();
+ allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
allocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
- CP_VK_ASSERT(vkAllocateCommandBuffers(vulkan.GetDevice(), &allocateInfo, &commandBuffer), "CopyBuffer : Failed to initialize command buffer");
+ CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), "CopyBuffer : Failed to initialize command buffer");
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -134,9 +133,9 @@ namespace Copium
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer;
- vkQueueSubmit(vulkan.GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
- vkQueueWaitIdle(vulkan.GetDevice().GetGraphicsQueue());
+ vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
+ vkQueueWaitIdle(Vulkan::GetDevice().GetGraphicsQueue());
- vkFreeCommandBuffers(vulkan.GetDevice(), vulkan.GetDevice().GetCommandPool(), 1, &commandBuffer);
+ vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), 1, &commandBuffer);
}
}
diff --git a/CopiumEngine/src/copium/buffer/Buffer.h b/CopiumEngine/src/copium/buffer/Buffer.h
index a3e6070..0722cfe 100644
--- a/CopiumEngine/src/copium/buffer/Buffer.h
+++ b/CopiumEngine/src/copium/buffer/Buffer.h
@@ -1,6 +1,5 @@
#pragma once
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include
@@ -11,8 +10,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Buffer);
protected:
- Vulkan& vulkan;
-
VkDeviceMemory memory;
VkBuffer handle;
VkDeviceSize size;
@@ -21,7 +18,7 @@ namespace Copium
void* mappedData = nullptr;
public:
- Buffer(Vulkan& vulkan, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count);
+ Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count);
virtual ~Buffer();
void Update(void* indexData, int index);
@@ -35,6 +32,6 @@ namespace Copium
VkDeviceSize GetSize() const;
VkDeviceSize GetPosition(int index) const;
- static void CopyBuffer(Vulkan& vulkan, const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size);
+ static void CopyBuffer(const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size);
};
}
diff --git a/CopiumEngine/src/copium/buffer/CommandBuffer.cpp b/CopiumEngine/src/copium/buffer/CommandBuffer.cpp
index 4eae0a7..f6d518d 100644
--- a/CopiumEngine/src/copium/buffer/CommandBuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/CommandBuffer.cpp
@@ -1,13 +1,11 @@
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- CommandBuffer::CommandBuffer(Vulkan& vulkan, Type type)
- : vulkan{vulkan}, type{type}
+ CommandBuffer::CommandBuffer(Type type)
+ : type{type}
{
switch (type)
{
@@ -24,14 +22,14 @@ namespace Copium
VkCommandBufferAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
- allocateInfo.commandPool = vulkan.GetDevice().GetCommandPool();
+ allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
allocateInfo.commandBufferCount = commandBuffers.size();
- CP_VK_ASSERT(vkAllocateCommandBuffers(vulkan.GetDevice(), &allocateInfo, commandBuffers.data()), "CommandBuffer : Failed to allocate CommandBuffer");
+ CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), "CommandBuffer : Failed to allocate CommandBuffer");
}
CommandBuffer::~CommandBuffer()
{
- vkFreeCommandBuffers(vulkan.GetDevice(), vulkan.GetDevice().GetCommandPool(), commandBuffers.size(), commandBuffers.data());
+ vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), commandBuffers.size(), commandBuffers.data());
}
// TODO: Test as constexpr function to see if it avoids the switch case
@@ -53,13 +51,13 @@ namespace Copium
CP_ABORT("Begin : Unreachable switch case");
}
- vkResetCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()], 0);
- CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()], &beginInfo), "Begin : Failed to begin command buffer");
+ vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0);
+ CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), "Begin : Failed to begin command buffer");
}
void CommandBuffer::End()
{
- vkEndCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()]);
+ vkEndCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()]);
}
void CommandBuffer::Submit()
@@ -67,15 +65,15 @@ namespace Copium
VkSubmitInfo submitInfo{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &commandBuffers[vulkan.GetSwapChain().GetFlightIndex()];
+ submitInfo.pCommandBuffers = &commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
- vkQueueSubmit(vulkan.GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
+ vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
// TODO: if singleUse?
- vkQueueWaitIdle(vulkan.GetDevice().GetGraphicsQueue());
+ vkQueueWaitIdle(Vulkan::GetDevice().GetGraphicsQueue());
}
CommandBuffer::operator VkCommandBuffer() const
{
- return commandBuffers[vulkan.GetSwapChain().GetFlightIndex()];
+ return commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/buffer/CommandBuffer.h b/CopiumEngine/src/copium/buffer/CommandBuffer.h
index 67ce2cb..907481c 100644
--- a/CopiumEngine/src/copium/buffer/CommandBuffer.h
+++ b/CopiumEngine/src/copium/buffer/CommandBuffer.h
@@ -1,6 +1,5 @@
#pragma once
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include
@@ -16,13 +15,11 @@ namespace Copium
SingleUse, Dynamic
};
private:
- Vulkan& vulkan;
-
std::vector commandBuffers;
const Type type;
public:
- CommandBuffer(Vulkan& vulkan, Type type);
+ CommandBuffer(Type type);
virtual ~CommandBuffer();
void Begin();
diff --git a/CopiumEngine/src/copium/buffer/CommandBufferScoped.cpp b/CopiumEngine/src/copium/buffer/CommandBufferScoped.cpp
index dcf9512..023a749 100644
--- a/CopiumEngine/src/copium/buffer/CommandBufferScoped.cpp
+++ b/CopiumEngine/src/copium/buffer/CommandBufferScoped.cpp
@@ -2,8 +2,8 @@
namespace Copium
{
- CommandBufferScoped::CommandBufferScoped(Vulkan& vulkan)
- : CommandBuffer{vulkan, Type::SingleUse}
+ CommandBufferScoped::CommandBufferScoped()
+ : CommandBuffer{Type::SingleUse}
{
CommandBuffer::Begin();
}
diff --git a/CopiumEngine/src/copium/buffer/CommandBufferScoped.h b/CopiumEngine/src/copium/buffer/CommandBufferScoped.h
index e17b5c6..442ba16 100644
--- a/CopiumEngine/src/copium/buffer/CommandBufferScoped.h
+++ b/CopiumEngine/src/copium/buffer/CommandBufferScoped.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
namespace Copium
@@ -10,7 +9,7 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped);
public:
- CommandBufferScoped(Vulkan& vulkan);
+ CommandBufferScoped();
~CommandBufferScoped() override;
};
diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.cpp b/CopiumEngine/src/copium/buffer/Framebuffer.cpp
index 811f8c6..6a2d2ba 100644
--- a/CopiumEngine/src/copium/buffer/Framebuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/Framebuffer.cpp
@@ -1,14 +1,13 @@
#include "copium/buffer/Framebuffer.h"
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Device.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h"
namespace Copium
{
- Framebuffer::Framebuffer(Vulkan& vulkan, uint32_t width, uint32_t height)
- : vulkan{vulkan}, width{width}, height{height}
+ Framebuffer::Framebuffer(uint32_t width, uint32_t height)
+ : width{width}, height{height}
{
InitializeImage();
InitializeDepthBuffer();
@@ -19,19 +18,19 @@ namespace Copium
Framebuffer::~Framebuffer()
{
for (auto& framebuffer : framebuffers)
- vkDestroyFramebuffer(vulkan.GetDevice(), framebuffer, nullptr);
- vkDestroyRenderPass(vulkan.GetDevice(), renderPass, nullptr);
+ vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
+ vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
}
void Framebuffer::Resize(uint32_t width, uint32_t height)
{
- vkDeviceWaitIdle(vulkan.GetDevice());
+ vkDeviceWaitIdle(Vulkan::GetDevice());
this->width = width;
this->height = height;
colorAttachment.reset();
depthAttachment.reset();
for (auto&& framebuffer : framebuffers)
- vkDestroyFramebuffer(vulkan.GetDevice(), framebuffer, nullptr);
+ vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
InitializeImage();
InitializeDepthBuffer();
InitializeFramebuffers();
@@ -46,7 +45,7 @@ namespace Copium
VkRenderPassBeginInfo renderPassBeginInfo{};
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassBeginInfo.renderPass = renderPass;
- renderPassBeginInfo.framebuffer = framebuffers[vulkan.GetSwapChain().GetFlightIndex()];
+ renderPassBeginInfo.framebuffer = framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
;
renderPassBeginInfo.renderArea.offset = {0, 0};
renderPassBeginInfo.renderArea.extent = {width, height};
@@ -80,7 +79,7 @@ namespace Copium
VkFramebuffer Framebuffer::GetFramebuffer() const
{
- return framebuffers[vulkan.GetSwapChain().GetFlightIndex()];
+ return framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
}
const ColorAttachment& Framebuffer::GetColorAttachment() const
@@ -100,12 +99,12 @@ namespace Copium
void Framebuffer::InitializeImage()
{
- colorAttachment = std::make_unique(vulkan, width, height);
+ colorAttachment = std::make_unique(width, height);
}
void Framebuffer::InitializeDepthBuffer()
{
- depthAttachment = std::make_unique(vulkan, width, height);
+ depthAttachment = std::make_unique(width, height);
}
void Framebuffer::InitializeRenderPass()
@@ -121,7 +120,7 @@ namespace Copium
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkAttachmentDescription depthAttachment{};
- depthAttachment.format = Image::SelectDepthFormat(vulkan);
+ depthAttachment.format = Image::SelectDepthFormat();
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
@@ -169,7 +168,7 @@ namespace Copium
renderPassCreateInfo.dependencyCount = dependencies.size();
renderPassCreateInfo.pDependencies = dependencies.data();
- CP_VK_ASSERT(vkCreateRenderPass(vulkan.GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
+ CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
}
void Framebuffer::InitializeFramebuffers()
@@ -188,7 +187,7 @@ namespace Copium
createInfo.height = height;
createInfo.layers = 1;
- CP_VK_ASSERT(vkCreateFramebuffer(vulkan.GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize framebuffer");
+ CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize framebuffer");
}
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.h b/CopiumEngine/src/copium/buffer/Framebuffer.h
index 74a79b3..f0a57e1 100644
--- a/CopiumEngine/src/copium/buffer/Framebuffer.h
+++ b/CopiumEngine/src/copium/buffer/Framebuffer.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/sampler/ColorAttachment.h"
#include "copium/sampler/DepthAttachment.h"
#include "copium/util/Common.h"
@@ -14,8 +13,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
private:
- Vulkan& vulkan;
-
std::unique_ptr colorAttachment;
std::unique_ptr depthAttachment;
std::vector framebuffers;
@@ -24,7 +21,7 @@ namespace Copium
uint32_t width;
uint32_t height;
public:
- Framebuffer(Vulkan& vulkan, uint32_t width, uint32_t height);
+ Framebuffer(uint32_t width, uint32_t height);
~Framebuffer();
void Resize(uint32_t width, uint32_t height);
diff --git a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp
index 9f1cd96..37ab256 100644
--- a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp
@@ -4,8 +4,8 @@
namespace Copium
{
- IndexBuffer::IndexBuffer(Vulkan& vulkan, int indexCount)
- : Buffer{vulkan, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexCount * sizeof(uint16_t), 1},
+ IndexBuffer::IndexBuffer(int indexCount)
+ : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexCount * sizeof(uint16_t), 1},
indexCount{indexCount}
{}
diff --git a/CopiumEngine/src/copium/buffer/IndexBuffer.h b/CopiumEngine/src/copium/buffer/IndexBuffer.h
index ef6454b..3c45871 100644
--- a/CopiumEngine/src/copium/buffer/IndexBuffer.h
+++ b/CopiumEngine/src/copium/buffer/IndexBuffer.h
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
namespace Copium
@@ -13,7 +12,7 @@ namespace Copium
private:
int indexCount;
public:
- IndexBuffer(Vulkan& vulkan, int indexCount);
+ IndexBuffer(int indexCount);
void Bind(const CommandBuffer& commandBuffer);
void Draw(const CommandBuffer& commandBuffer);
diff --git a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp
index ca7a39b..628720b 100644
--- a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp
@@ -1,17 +1,17 @@
#include "copium/buffer/RendererVertexBuffer.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- RendererVertexBuffer::RendererVertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount)
- : Buffer{vulkan, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, descriptor.GetVertexSize() * vertexCount, SwapChain::MAX_FRAMES_IN_FLIGHT}
+ RendererVertexBuffer::RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
+ : Buffer{VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, descriptor.GetVertexSize() * vertexCount, SwapChain::MAX_FRAMES_IN_FLIGHT}
{}
void RendererVertexBuffer::Bind(const CommandBuffer& commandBuffer)
{
- VkDeviceSize offset = GetPosition(vulkan.GetSwapChain().GetFlightIndex());
+ VkDeviceSize offset = GetPosition(Vulkan::GetSwapChain().GetFlightIndex());
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &handle, &offset);
}
}
diff --git a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h
index 5781ca7..6f29244 100644
--- a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h
+++ b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/pipeline/VertexDescriptor.h"
namespace Copium
@@ -11,7 +10,7 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer);
public:
- RendererVertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount);
+ RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
void Bind(const CommandBuffer& commandBuffer);
};
diff --git a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp
index ef362c9..7108b03 100644
--- a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp
@@ -1,11 +1,11 @@
#include "copium/buffer/UniformBuffer.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- UniformBuffer::UniformBuffer(Vulkan& vulkan, ShaderBinding binding)
- : Buffer{vulkan, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, binding.GetUniformBufferSize(), SwapChain::MAX_FRAMES_IN_FLIGHT}, binding{binding}
+ UniformBuffer::UniformBuffer(ShaderBinding binding)
+ : Buffer{VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, binding.GetUniformBufferSize(), SwapChain::MAX_FRAMES_IN_FLIGHT}, binding{binding}
{
buffer.resize(Buffer::GetSize());
}
@@ -70,6 +70,6 @@ namespace Copium
void UniformBuffer::Update()
{
- Buffer::Update(buffer.data(), vulkan.GetSwapChain().GetFlightIndex());
+ Buffer::Update(buffer.data(), Vulkan::GetSwapChain().GetFlightIndex());
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/buffer/UniformBuffer.h b/CopiumEngine/src/copium/buffer/UniformBuffer.h
index 1e0104c..9453b31 100644
--- a/CopiumEngine/src/copium/buffer/UniformBuffer.h
+++ b/CopiumEngine/src/copium/buffer/UniformBuffer.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/Buffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/pipeline/ShaderBinding.h"
#include "copium/util/Common.h"
@@ -13,12 +12,12 @@ namespace Copium
class UniformBuffer final : public Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer);
-
+ private:
ShaderBinding binding;
std::vector buffer;
public:
- UniformBuffer(Vulkan& vulkan, ShaderBinding binding);
+ UniformBuffer(ShaderBinding binding);
VkDescriptorBufferInfo GetDescriptorBufferInfo(int index) const;
diff --git a/CopiumEngine/src/copium/buffer/VertexBuffer.cpp b/CopiumEngine/src/copium/buffer/VertexBuffer.cpp
index 52d01b4..4734c37 100644
--- a/CopiumEngine/src/copium/buffer/VertexBuffer.cpp
+++ b/CopiumEngine/src/copium/buffer/VertexBuffer.cpp
@@ -2,8 +2,8 @@
namespace Copium
{
- VertexBuffer::VertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount)
- : Buffer{vulkan, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, descriptor.GetVertexSize() * vertexCount, 1}
+ VertexBuffer::VertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
+ : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, descriptor.GetVertexSize() * vertexCount, 1}
{
VkDeviceSize offset = 0;
for (auto&& binding : descriptor.GetBindings())
diff --git a/CopiumEngine/src/copium/buffer/VertexBuffer.h b/CopiumEngine/src/copium/buffer/VertexBuffer.h
index 27a041b..05547f5 100644
--- a/CopiumEngine/src/copium/buffer/VertexBuffer.h
+++ b/CopiumEngine/src/copium/buffer/VertexBuffer.h
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/pipeline/VertexDescriptor.h"
#include "copium/util/Common.h"
@@ -18,7 +17,7 @@ namespace Copium
std::vector bindingOffsets;
std::vector bindingSizes;
public:
- VertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount);
+ VertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
void Bind(const CommandBuffer& commandBuffer);
void UpdateStaging(uint32_t binding, void* data);
diff --git a/CopiumEngine/src/copium/core/Application.cpp b/CopiumEngine/src/copium/core/Application.cpp
index e9da293..59f6af4 100644
--- a/CopiumEngine/src/copium/core/Application.cpp
+++ b/CopiumEngine/src/copium/core/Application.cpp
@@ -1,11 +1,8 @@
#include "copium/core/Application.h"
+#include "copium/core/Vulkan.h"
#include "copium/mesh/Vertex.h"
#include "copium/mesh/VertexPassthrough.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
-#include "copium/core/SwapChain.h"
-#include "copium/core/Window.h"
#include
@@ -40,7 +37,6 @@ namespace Copium
Application::Application()
{
- InitializeVulkan();
InitializeFrameBuffer();
InitializeRenderer();
InitializeGraphicsPipeline();
@@ -52,56 +48,46 @@ namespace Copium
Application::~Application()
{
- vkDeviceWaitIdle(vulkan->GetDevice());
+ vkDeviceWaitIdle(Vulkan::GetDevice());
}
bool Application::Update()
{
- if (framebuffer->GetWidth() != vulkan->GetSwapChain().GetExtent().width || framebuffer->GetHeight() != vulkan->GetSwapChain().GetExtent().height)
+ if (framebuffer->GetWidth() != Vulkan::GetSwapChain().GetExtent().width || framebuffer->GetHeight() != Vulkan::GetSwapChain().GetExtent().height)
{
- framebuffer->Resize(vulkan->GetSwapChain().GetExtent().width / 8, vulkan->GetSwapChain().GetExtent().height / 8);
+ framebuffer->Resize(Vulkan::GetSwapChain().GetExtent().width / 8, Vulkan::GetSwapChain().GetExtent().height / 8);
descriptorSetPassthrough->SetSampler(framebuffer->GetColorAttachment(), 0);
}
- if (!vulkan->GetSwapChain().BeginPresent())
+ if (!Vulkan::GetSwapChain().BeginPresent())
return true;
RecordCommandBuffer();
- vulkan->GetSwapChain().SubmitToGraphicsQueue(*commandBuffer);
+ Vulkan::GetSwapChain().SubmitToGraphicsQueue(*commandBuffer);
- vulkan->GetSwapChain().EndPresent();
- return !glfwWindowShouldClose(vulkan->GetWindow().GetWindow());
- }
-
- void Application::InitializeVulkan()
- {
- vulkan = std::make_unique();
- vulkan->SetInstance(std::make_unique("Copium Engine"));
- vulkan->SetWindow(std::make_unique(*vulkan, "Copium Engine", 1920, 1080, Window::Mode::Windowed));
- vulkan->SetDevice(std::make_unique(*vulkan));
- vulkan->SetSwapChain(std::make_unique(*vulkan));
- CP_ASSERT(vulkan->Valid(), "Vulkan Manager was not initialized correctly");
+ Vulkan::GetSwapChain().EndPresent();
+ return !glfwWindowShouldClose(Vulkan::GetWindow().GetWindow());
}
void Application::InitializeFrameBuffer()
{
- framebuffer = std::make_unique(*vulkan, vulkan->GetSwapChain().GetExtent().width, vulkan->GetSwapChain().GetExtent().height);
+ framebuffer = std::make_unique(Vulkan::GetSwapChain().GetExtent().width, Vulkan::GetSwapChain().GetExtent().height);
}
void Application::InitializeRenderer()
{
- renderer = std::make_unique(*vulkan, framebuffer->GetRenderPass(), *descriptorPool);
+ renderer = std::make_unique(framebuffer->GetRenderPass());
}
void Application::InitializeTextureSampler()
{
- texture2D = std::make_unique(*vulkan, "res/textures/texture.png");
- texture2D2 = std::make_unique(*vulkan, "res/textures/texture2.png");
+ texture2D = std::make_unique("res/textures/texture.png");
+ texture2D2 = std::make_unique("res/textures/texture2.png");
}
void Application::InitializeDescriptorSets()
{
- descriptorPool = std::make_unique(*vulkan);
+ descriptorPool = std::make_unique();
descriptorSet = graphicsPipeline->CreateDescriptorSet(*descriptorPool, 0);
descriptorSet->SetSampler(*texture2D, 1);
@@ -116,22 +102,22 @@ namespace Copium
{
PipelineCreator creator{framebuffer->GetRenderPass(), "res/shaders/shader.vert", "res/shaders/shader.frag"};
creator.SetVertexDescriptor(Vertex::GetDescriptor());
- graphicsPipeline = std::make_unique(*vulkan, creator);
+ graphicsPipeline = std::make_unique(creator);
- PipelineCreator creatorPassthrough{vulkan->GetSwapChain().GetRenderPass(), "res/shaders/passthrough.vert", "res/shaders/passthrough.frag"};
+ PipelineCreator creatorPassthrough{Vulkan::GetSwapChain().GetRenderPass(), "res/shaders/passthrough.vert", "res/shaders/passthrough.frag"};
creatorPassthrough.SetVertexDescriptor(VertexPassthrough::GetDescriptor());
- graphicsPipelinePassthrough = std::make_unique(*vulkan, creatorPassthrough);
+ graphicsPipelinePassthrough = std::make_unique(creatorPassthrough);
}
void Application::InitializeMesh()
{
- mesh = std::make_unique(*vulkan, vertices, indices);
- meshPassthrough = std::make_unique(*vulkan, verticesPassthrough, indicesPassthrough);
+ mesh = std::make_unique(vertices, indices);
+ meshPassthrough = std::make_unique(verticesPassthrough, indicesPassthrough);
}
void Application::InitializeCommandBuffer()
{
- commandBuffer = std::make_unique(*vulkan, CommandBuffer::Type::Dynamic);
+ commandBuffer = std::make_unique(CommandBuffer::Type::Dynamic);
}
void Application::RecordCommandBuffer()
@@ -164,7 +150,7 @@ namespace Copium
framebuffer->Unbind(*commandBuffer);
- vulkan->GetSwapChain().BeginFrameBuffer(*commandBuffer);
+ Vulkan::GetSwapChain().BeginFrameBuffer(*commandBuffer);
graphicsPipelinePassthrough->Bind(*commandBuffer);
graphicsPipelinePassthrough->SetDescriptorSet(*descriptorSetPassthrough);
@@ -173,7 +159,7 @@ namespace Copium
meshPassthrough->Bind(*commandBuffer);
meshPassthrough->Render(*commandBuffer);
- vulkan->GetSwapChain().EndFrameBuffer(*commandBuffer);
+ Vulkan::GetSwapChain().EndFrameBuffer(*commandBuffer);
commandBuffer->End();
}
diff --git a/CopiumEngine/src/copium/core/Application.h b/CopiumEngine/src/copium/core/Application.h
index be2f11c..2ac290d 100644
--- a/CopiumEngine/src/copium/core/Application.h
+++ b/CopiumEngine/src/copium/core/Application.h
@@ -1,18 +1,12 @@
#pragma once
#include "copium/buffer/Framebuffer.h"
-#include "copium/buffer/IndexBuffer.h"
-#include "copium/buffer/UniformBuffer.h"
-#include "copium/buffer/VertexBuffer.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
-#include "copium/core/Vulkan.h"
#include "copium/mesh/Mesh.h"
#include "copium/pipeline/DescriptorPool.h"
#include "copium/pipeline/DescriptorSet.h"
#include "copium/pipeline/Pipeline.h"
-#include "copium/sampler/Texture2D.h"
#include "copium/renderer/Renderer.h"
+#include "copium/sampler/Texture2D.h"
namespace Copium
{
@@ -20,8 +14,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Application);
private:
- std::unique_ptr vulkan;
- std::unique_ptr instance;
std::unique_ptr renderer;
std::unique_ptr framebuffer;
std::unique_ptr texture2D;
@@ -42,7 +34,6 @@ namespace Copium
bool Update();
private:
- void InitializeVulkan();
void InitializeFrameBuffer();
void InitializeRenderer();
void InitializeTextureSampler();
diff --git a/CopiumEngine/src/copium/core/DebugMessenger.h b/CopiumEngine/src/copium/core/DebugMessenger.h
index eacf47b..1c9623d 100644
--- a/CopiumEngine/src/copium/core/DebugMessenger.h
+++ b/CopiumEngine/src/copium/core/DebugMessenger.h
@@ -13,6 +13,7 @@ namespace Copium
CP_DELETE_COPY_AND_MOVE_CTOR(DebugMessenger);
private:
Instance& instance;
+
VkDebugUtilsMessengerEXT debugMessenger;
public:
DebugMessenger(Instance& instance);
diff --git a/CopiumEngine/src/copium/core/Device.cpp b/CopiumEngine/src/copium/core/Device.cpp
index 584d036..0c5780a 100644
--- a/CopiumEngine/src/copium/core/Device.cpp
+++ b/CopiumEngine/src/copium/core/Device.cpp
@@ -1,13 +1,11 @@
#include "Device.h"
-#include "copium/core/Instance.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
#include "copium/core/Window.h"
namespace Copium
{
- Device::Device(Vulkan& vulkan)
- : vulkan{vulkan}
+ Device::Device()
{
SelectPhysicalDevice();
InitializeLogicalDevice();
@@ -60,11 +58,11 @@ namespace Copium
void Device::SelectPhysicalDevice()
{
uint32_t deviceCount;
- vkEnumeratePhysicalDevices(vulkan.GetInstance(), &deviceCount, nullptr);
+ vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, nullptr);
CP_ASSERT(deviceCount != 0, "SelectPhysicaDevice : No available devices support Vulkan");
std::vector devices(deviceCount);
- vkEnumeratePhysicalDevices(vulkan.GetInstance(), &deviceCount, devices.data());
+ vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, devices.data());
CP_INFO("SelectPhysicaDevice : Available devices:");
for (auto&& device : devices)
{
@@ -88,7 +86,7 @@ namespace Copium
void Device::InitializeLogicalDevice()
{
- QueueFamiliesQuery query{vulkan.GetWindow().GetSurface(), physicalDevice};
+ QueueFamiliesQuery query{Vulkan::GetWindow().GetSurface(), physicalDevice};
float queuePriority = 1.0f;
@@ -144,14 +142,14 @@ namespace Copium
if (!deviceFeatures.fillModeNonSolid || !deviceFeatures.samplerAnisotropy)
return false;
- QueueFamiliesQuery query{vulkan.GetWindow().GetSurface(), device};
+ QueueFamiliesQuery query{Vulkan::GetWindow().GetSurface(), device};
if (!query.AllRequiredFamiliesSupported())
return false;
if (!CheckDeviceExtensionSupport(device))
return false;
- SwapChainSupportDetails details{vulkan.GetWindow().GetSurface(), device};
+ SwapChainSupportDetails details{Vulkan::GetWindow().GetSurface(), device};
if (!details.Valid())
return false;
diff --git a/CopiumEngine/src/copium/core/Device.h b/CopiumEngine/src/copium/core/Device.h
index 0920c2b..24b6687 100644
--- a/CopiumEngine/src/copium/core/Device.h
+++ b/CopiumEngine/src/copium/core/Device.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/core/QueueFamilies.h"
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include
@@ -13,8 +12,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Device);
private:
- Vulkan& vulkan;
-
VkPhysicalDevice physicalDevice;
VkDevice device;
VkCommandPool commandPool;
@@ -27,7 +24,7 @@ namespace Copium
// TODO end
public:
- Device(Vulkan& vulkan);
+ Device();
~Device();
VkQueue GetGraphicsQueue() const;
diff --git a/CopiumEngine/src/copium/core/Instance.cpp b/CopiumEngine/src/copium/core/Instance.cpp
index 76768d5..31fd4cd 100644
--- a/CopiumEngine/src/copium/core/Instance.cpp
+++ b/CopiumEngine/src/copium/core/Instance.cpp
@@ -1,7 +1,6 @@
#include "Instance.h"
#include "copium/core/QueueFamilies.h"
-#include "copium/core/SwapChain.h"
#include "copium/util/Common.h"
namespace Copium
@@ -110,12 +109,4 @@ namespace Copium
}
return true;
}
-
- void Instance::FramebufferResizeCallback(GLFWwindow* window, int width, int height)
- {
- Instance* instance = static_cast(glfwGetWindowUserPointer(window));
- // TODO: Fix swap chain resizing again
- // instance->swapChain->ResizeFramebuffer(); // TODO: Should maybe be handled by an event system?
- CP_UNIMPLEMENTED("Framebuffer resizing currently not supported");
- }
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/core/Instance.h b/CopiumEngine/src/copium/core/Instance.h
index 66e10eb..ba8bf5e 100644
--- a/CopiumEngine/src/copium/core/Instance.h
+++ b/CopiumEngine/src/copium/core/Instance.h
@@ -3,7 +3,6 @@
#include "copium/core/DebugMessenger.h"
#include "copium/util/Timer.h"
-#include
#include
#include
@@ -36,6 +35,5 @@ namespace Copium
void InitializeDebugMessenger();
std::vector GetRequiredExtensions();
bool CheckLayerSupport(const std::vector& layers);
- static void FramebufferResizeCallback(GLFWwindow* window, int width, int height);
};
}
diff --git a/CopiumEngine/src/copium/core/SwapChain.cpp b/CopiumEngine/src/copium/core/SwapChain.cpp
index 8590af9..9af1dc3 100644
--- a/CopiumEngine/src/copium/core/SwapChain.cpp
+++ b/CopiumEngine/src/copium/core/SwapChain.cpp
@@ -1,9 +1,7 @@
#include "copium/core/SwapChain.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
#include "copium/core/QueueFamilies.h"
-#include "copium/core/Window.h"
+#include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h"
namespace Copium
@@ -34,8 +32,7 @@ namespace Copium
return !formats.empty() && !presentModes.empty();
}
- SwapChain::SwapChain(Vulkan& vulkan)
- : vulkan{vulkan}
+ SwapChain::SwapChain()
{
Initialize();
InitializeImageViews();
@@ -49,12 +46,12 @@ namespace Copium
{
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
{
- vkDestroyFence(vulkan.GetDevice(), inFlightFences[i], nullptr);
- vkDestroySemaphore(vulkan.GetDevice(), renderFinishedSemaphores[i], nullptr);
- vkDestroySemaphore(vulkan.GetDevice(), imageAvailableSemaphores[i], nullptr);
+ vkDestroyFence(Vulkan::GetDevice(), inFlightFences[i], nullptr);
+ vkDestroySemaphore(Vulkan::GetDevice(), renderFinishedSemaphores[i], nullptr);
+ vkDestroySemaphore(Vulkan::GetDevice(), imageAvailableSemaphores[i], nullptr);
}
Destroy();
- vkDestroyRenderPass(vulkan.GetDevice(), renderPass, nullptr);
+ vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
}
void SwapChain::BeginFrameBuffer(const CommandBuffer& commandBuffer) const
@@ -114,15 +111,15 @@ namespace Copium
bool SwapChain::BeginPresent()
{
- vkWaitForFences(vulkan.GetDevice(), 1, &inFlightFences[flightIndex], VK_TRUE, UINT64_MAX);
+ vkWaitForFences(Vulkan::GetDevice(), 1, &inFlightFences[flightIndex], VK_TRUE, UINT64_MAX);
- VkResult result = vkAcquireNextImageKHR(vulkan.GetDevice(), handle, UINT64_MAX, imageAvailableSemaphores[flightIndex], VK_NULL_HANDLE, &imageIndex);
+ VkResult result = vkAcquireNextImageKHR(Vulkan::GetDevice(), handle, UINT64_MAX, imageAvailableSemaphores[flightIndex], VK_NULL_HANDLE, &imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR)
{
Recreate();
return false;
}
- vkResetFences(vulkan.GetDevice(), 1, &inFlightFences[flightIndex]);
+ vkResetFences(Vulkan::GetDevice(), 1, &inFlightFences[flightIndex]);
return true;
}
@@ -140,7 +137,7 @@ namespace Copium
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &renderFinishedSemaphores[flightIndex];
- CP_VK_ASSERT(vkQueueSubmit(vulkan.GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "SubmitGraphicsQueue : Failed to submit command buffer");
+ CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "SubmitGraphicsQueue : Failed to submit command buffer");
}
void SwapChain::EndPresent()
@@ -154,7 +151,7 @@ namespace Copium
presentInfo.pImageIndices = &imageIndex;
presentInfo.pResults = nullptr;
- VkResult result = vkQueuePresentKHR(vulkan.GetDevice().GetPresentQueue(), &presentInfo);
+ VkResult result = vkQueuePresentKHR(Vulkan::GetDevice().GetPresentQueue(), &presentInfo);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || resizeFramebuffer)
{
Recreate();
@@ -173,14 +170,14 @@ namespace Copium
{
int width = 0;
int height = 0;
- glfwGetFramebufferSize(vulkan.GetWindow().GetWindow(), &width, &height);
+ glfwGetFramebufferSize(Vulkan::GetWindow().GetWindow(), &width, &height);
while (width == 0 || height == 0)
{
- glfwGetFramebufferSize(vulkan.GetWindow().GetWindow(), &width, &height);
+ glfwGetFramebufferSize(Vulkan::GetWindow().GetWindow(), &width, &height);
glfwWaitEvents();
}
- vkDeviceWaitIdle(vulkan.GetDevice());
+ vkDeviceWaitIdle(Vulkan::GetDevice());
Destroy();
@@ -197,11 +194,11 @@ namespace Copium
void SwapChain::Initialize()
{
- SwapChainSupportDetails swapChainSupport{vulkan.GetWindow().GetSurface(), vulkan.GetDevice().GetPhysicalDevice()};
+ SwapChainSupportDetails swapChainSupport{Vulkan::GetWindow().GetSurface(), Vulkan::GetDevice().GetPhysicalDevice()};
VkSurfaceFormatKHR format = SelectSwapSurfaceFormat(swapChainSupport.formats);
VkPresentModeKHR presentMode = SelectSwapPresentMode(swapChainSupport.presentModes);
- extent = SelectSwapExtent(vulkan.GetWindow().GetWindow(), swapChainSupport.capabilities);
+ extent = SelectSwapExtent(Vulkan::GetWindow().GetWindow(), swapChainSupport.capabilities);
imageFormat = format.format;
uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;
if (swapChainSupport.capabilities.maxImageCount != 0)
@@ -209,12 +206,12 @@ namespace Copium
imageCount = std::min(imageCount, swapChainSupport.capabilities.maxImageCount);
}
- QueueFamiliesQuery queueFamilies{vulkan.GetWindow().GetSurface(), vulkan.GetDevice().GetPhysicalDevice()};
+ QueueFamiliesQuery queueFamilies{Vulkan::GetWindow().GetSurface(), Vulkan::GetDevice().GetPhysicalDevice()};
std::vector queueFamilyIndices{queueFamilies.graphicsFamily.value(), queueFamilies.presentFamily.value()};
VkSwapchainCreateInfoKHR createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
- createInfo.surface = vulkan.GetWindow().GetSurface();
+ createInfo.surface = Vulkan::GetWindow().GetSurface();
createInfo.minImageCount = imageCount;
createInfo.imageFormat = format.format;
createInfo.imageColorSpace = format.colorSpace;
@@ -239,11 +236,11 @@ namespace Copium
createInfo.pQueueFamilyIndices = nullptr;
}
- CP_VK_ASSERT(vkCreateSwapchainKHR(vulkan.GetDevice(), &createInfo, nullptr, &handle), "Initialize : Failed to initialize the swapchain");
+ CP_VK_ASSERT(vkCreateSwapchainKHR(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Initialize : Failed to initialize the swapchain");
- vkGetSwapchainImagesKHR(vulkan.GetDevice(), handle, &imageCount, nullptr);
+ vkGetSwapchainImagesKHR(Vulkan::GetDevice(), handle, &imageCount, nullptr);
images.resize(imageCount);
- vkGetSwapchainImagesKHR(vulkan.GetDevice(), handle, &imageCount, images.data());
+ vkGetSwapchainImagesKHR(Vulkan::GetDevice(), handle, &imageCount, images.data());
}
void SwapChain::InitializeImageViews()
@@ -251,13 +248,13 @@ namespace Copium
imageViews.resize(images.size());
for (size_t i = 0; i < images.size(); i++)
{
- imageViews[i] = Image::InitializeImageView(vulkan, images[i], imageFormat, VK_IMAGE_ASPECT_COLOR_BIT);
+ imageViews[i] = Image::InitializeImageView(images[i], imageFormat, VK_IMAGE_ASPECT_COLOR_BIT);
}
}
void SwapChain::InitializeDepthAttachment()
{
- depthAttachment = std::make_unique(vulkan, extent.width, extent.height);
+ depthAttachment = std::make_unique(extent.width, extent.height);
}
void SwapChain::InitializeRenderPass()
@@ -273,7 +270,7 @@ namespace Copium
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
VkAttachmentDescription depthAttachment{};
- depthAttachment.format = Image::SelectDepthFormat(vulkan);
+ depthAttachment.format = Image::SelectDepthFormat();
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
@@ -314,7 +311,7 @@ namespace Copium
renderPassCreateInfo.dependencyCount = 1;
renderPassCreateInfo.pDependencies = &dependency;
- CP_VK_ASSERT(vkCreateRenderPass(vulkan.GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
+ CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
}
void SwapChain::InitializeFramebuffers()
@@ -334,7 +331,7 @@ namespace Copium
createInfo.height = extent.height;
createInfo.layers = 1;
- CP_VK_ASSERT(vkCreateFramebuffer(vulkan.GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize swap chain framebuffer");
+ CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize swap chain framebuffer");
}
}
@@ -347,14 +344,14 @@ namespace Copium
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
{
- CP_VK_ASSERT(vkCreateSemaphore(vulkan.GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "InitializeSyncObjects : Failed to initialize available image semaphore");
- CP_VK_ASSERT(vkCreateSemaphore(vulkan.GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "InitializeSyncObjects : Failed to initialize render finished semaphore");
+ CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "InitializeSyncObjects : Failed to initialize available image semaphore");
+ CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "InitializeSyncObjects : Failed to initialize render finished semaphore");
VkFenceCreateInfo fenceCreateInfo{};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
- CP_VK_ASSERT(vkCreateFence(vulkan.GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "InitializeSyncObjects : Failed to initialize in flight fence");
+ CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "InitializeSyncObjects : Failed to initialize in flight fence");
}
}
@@ -362,13 +359,13 @@ namespace Copium
{
for (auto&& framebuffer : framebuffers)
{
- vkDestroyFramebuffer(vulkan.GetDevice(), framebuffer, nullptr);
+ vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
}
for (auto&& swapChainImageView : imageViews)
{
- vkDestroyImageView(vulkan.GetDevice(), swapChainImageView, nullptr);
+ vkDestroyImageView(Vulkan::GetDevice(), swapChainImageView, nullptr);
}
- vkDestroySwapchainKHR(vulkan.GetDevice(), handle, nullptr);
+ vkDestroySwapchainKHR(Vulkan::GetDevice(), handle, nullptr);
}
VkSurfaceFormatKHR SwapChain::SelectSwapSurfaceFormat(const std::vector& availableFormats)
diff --git a/CopiumEngine/src/copium/core/SwapChain.h b/CopiumEngine/src/copium/core/SwapChain.h
index 6c02c09..b033577 100644
--- a/CopiumEngine/src/copium/core/SwapChain.h
+++ b/CopiumEngine/src/copium/core/SwapChain.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/sampler/DepthAttachment.h"
#include "copium/util/Common.h"
@@ -27,8 +26,6 @@ namespace Copium
public:
static const int MAX_FRAMES_IN_FLIGHT = 2;
private:
- Vulkan& vulkan;
-
VkSwapchainKHR handle;
VkRenderPass renderPass;
VkFormat imageFormat;
@@ -46,7 +43,7 @@ namespace Copium
std::vector inFlightFences;
public:
- SwapChain(Vulkan& vulkan);
+ SwapChain();
~SwapChain();
void BeginFrameBuffer(const CommandBuffer& commandBuffer) const;
diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp
index 552e100..16fb8aa 100644
--- a/CopiumEngine/src/copium/core/Vulkan.cpp
+++ b/CopiumEngine/src/copium/core/Vulkan.cpp
@@ -1,48 +1,44 @@
#include "copium/core/Vulkan.h"
-#include "copium/core/Device.h"
-#include "copium/core/Instance.h"
-#include "copium/core/SwapChain.h"
-#include "copium/core/Window.h"
-
namespace Copium
{
- void Vulkan::SetInstance(std::unique_ptr&& instance)
+ std::unique_ptr Vulkan::instance;
+ std::unique_ptr Vulkan::window;
+ std::unique_ptr Vulkan::device;
+ std::unique_ptr Vulkan::swapChain;
+
+ void Vulkan::Initialize()
{
- this->instance = std::move(instance);
+ instance = std::make_unique("Copium Engine");
+ window = std::make_unique( "Copium Engine", 1920, 1080, Window::Mode::Windowed);
+ device = std::make_unique();
+ swapChain = std::make_unique();
}
- void Vulkan::SetWindow(std::unique_ptr&& window)
+ void Vulkan::Destroy()
{
- this->window = std::move(window);
+ swapChain.reset();
+ device.reset();
+ window.reset();
+ instance.reset();
}
- void Vulkan::SetDevice(std::unique_ptr&& device)
- {
- this->device = std::move(device);
- }
-
- void Vulkan::SetSwapChain(std::unique_ptr&& swapChain)
- {
- this->swapChain = std::move(swapChain);
- }
-
- Instance& Vulkan::GetInstance() const
+ Instance& Vulkan::GetInstance()
{
return *instance;
}
- Window& Vulkan::GetWindow() const
+ Window& Vulkan::GetWindow()
{
return *window;
}
- Device& Vulkan::GetDevice() const
+ Device& Vulkan::GetDevice()
{
return *device;
}
- SwapChain& Vulkan::GetSwapChain() const
+ SwapChain& Vulkan::GetSwapChain()
{
return *swapChain;
}
diff --git a/CopiumEngine/src/copium/core/Vulkan.h b/CopiumEngine/src/copium/core/Vulkan.h
index 6e4aed9..85327f1 100644
--- a/CopiumEngine/src/copium/core/Vulkan.h
+++ b/CopiumEngine/src/copium/core/Vulkan.h
@@ -1,31 +1,31 @@
#pragma once
+#include "copium/core/Device.h"
+#include "copium/core/Instance.h"
+#include "copium/core/SwapChain.h"
+#include "copium/core/Window.h"
+#include "copium/util/Common.h"
+
#include
namespace Copium
{
- class Instance;
- class Window;
- class Device;
- class SwapChain;
-
class Vulkan
{
+ CP_STATIC_CLASS(Vulkan);
private:
- std::unique_ptr instance;
- std::unique_ptr window;
- std::unique_ptr device;
- std::unique_ptr swapChain;
+ static std::unique_ptr instance;
+ static std::unique_ptr window;
+ static std::unique_ptr device;
+ static std::unique_ptr swapChain;
public:
- void SetInstance(std::unique_ptr&& instance);
- void SetWindow(std::unique_ptr&& window);
- void SetDevice(std::unique_ptr&& device);
- void SetSwapChain(std::unique_ptr&& swapChain);
- Instance& GetInstance() const;
- Window& GetWindow() const;
- Device& GetDevice() const;
- SwapChain& GetSwapChain() const;
- bool Valid();
+ static void Initialize();
+ static void Destroy();
+ static Instance& GetInstance();
+ static Window& GetWindow();
+ static Device& GetDevice();
+ static SwapChain& GetSwapChain();
+ static bool Valid();
};
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/core/Window.cpp b/CopiumEngine/src/copium/core/Window.cpp
index 24c7858..b1d183d 100644
--- a/CopiumEngine/src/copium/core/Window.cpp
+++ b/CopiumEngine/src/copium/core/Window.cpp
@@ -1,12 +1,10 @@
#include "copium/core/Window.h"
-#include "copium/core/Instance.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- Window::Window(Vulkan& vulkan, const std::string& windowName, int width, int height, Mode mode)
- : vulkan{vulkan}
+ Window::Window(const std::string& windowName, int width, int height, Mode mode)
{
InitializeWindow(windowName, width, height, mode);
InitializeSurface();
@@ -14,7 +12,7 @@ namespace Copium
Window::~Window()
{
- vkDestroySurfaceKHR(vulkan.GetInstance(), surface, nullptr);
+ vkDestroySurfaceKHR(Vulkan::GetInstance(), surface, nullptr);
glfwDestroyWindow(window);
}
@@ -66,13 +64,12 @@ namespace Copium
void Window::InitializeSurface()
{
- CP_VK_ASSERT(glfwCreateWindowSurface(vulkan.GetInstance(), window, nullptr, &surface), "InitializeSurface : Failed to create Vulkan surface");
+ CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "InitializeSurface : Failed to create Vulkan surface");
}
void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
{
- Window* window = static_cast(glfwGetWindowUserPointer(glfwWindow));
- window->vulkan.GetSwapChain().ResizeFramebuffer(); // TODO: Should maybe be handled by an event system?
+ Vulkan::GetSwapChain().ResizeFramebuffer(); // TODO: Should maybe be handled by an event system?
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/core/Window.h b/CopiumEngine/src/copium/core/Window.h
index 6e60df9..d02846a 100644
--- a/CopiumEngine/src/copium/core/Window.h
+++ b/CopiumEngine/src/copium/core/Window.h
@@ -1,6 +1,5 @@
#pragma once
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include
@@ -16,13 +15,11 @@ namespace Copium
Fullscreen, BorderlessWindowed, Windowed
};
private:
- Vulkan& vulkan;
-
GLFWwindow* window;
VkSurfaceKHR surface;
public:
- Window(Vulkan& vulkan, const std::string& windowName, int width, int height, Mode mode);
+ Window(const std::string& windowName, int width, int height, Mode mode);
~Window();
VkSurfaceKHR GetSurface() const;
diff --git a/CopiumEngine/src/copium/main.cpp b/CopiumEngine/src/copium/main.cpp
index 8401cee..f33daf9 100644
--- a/CopiumEngine/src/copium/main.cpp
+++ b/CopiumEngine/src/copium/main.cpp
@@ -1,4 +1,5 @@
#include "copium/core/Application.h"
+#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include "copium/util/Timer.h"
@@ -7,6 +8,8 @@
int main()
{
CP_ASSERT(glfwInit() == GLFW_TRUE, "main : Failed to initialize the glfw context");
+
+ Copium::Vulkan::Initialize();
{
Copium::Application application;
Copium::Timer timer;
@@ -23,6 +26,7 @@ int main()
frames++;
}
}
+ Copium::Vulkan::Destroy();
glfwTerminate();
return 0;
diff --git a/CopiumEngine/src/copium/mesh/Mesh.h b/CopiumEngine/src/copium/mesh/Mesh.h
index d32788f..d530347 100644
--- a/CopiumEngine/src/copium/mesh/Mesh.h
+++ b/CopiumEngine/src/copium/mesh/Mesh.h
@@ -3,7 +3,6 @@
#include "copium/buffer/IndexBuffer.h"
#include "copium/buffer/VertexBuffer.h"
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include
@@ -19,18 +18,18 @@ namespace Copium
std::unique_ptr vertexBuffer;
public:
template
- Mesh(Vulkan& vulkan, const std::vector& vertices, const std::vector& indices);
+ Mesh(const std::vector& vertices, const std::vector& indices);
void Bind(const CommandBuffer& commandBuffer);
void Render(const CommandBuffer& commandBuffer);
};
template
- Mesh::Mesh(Vulkan& vulkan, const std::vector& vertices, const std::vector& indices)
+ Mesh::Mesh(const std::vector& vertices, const std::vector& indices)
{
- indexBuffer = std::make_unique(vulkan, indices.size());
+ indexBuffer = std::make_unique(indices.size());
indexBuffer->UpdateStaging((void*)indices.data());
- vertexBuffer = std::make_unique(vulkan, T::GetDescriptor(), vertices.size());
+ vertexBuffer = std::make_unique(T::GetDescriptor(), vertices.size());
vertexBuffer ->UpdateStaging(0, (void*)vertices.data());
}
}
diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp
index d5cb0ec..c5325b5 100644
--- a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp
+++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp
@@ -1,12 +1,10 @@
#include "copium/pipeline/DescriptorPool.h"
-#include "copium/core/Device.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- DescriptorPool::DescriptorPool(Vulkan& vulkan)
- : vulkan{vulkan}
+ DescriptorPool::DescriptorPool()
{
std::vector poolSizes{2};
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -22,12 +20,12 @@ namespace Copium
createInfo.maxSets = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT;
createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
- CP_VK_ASSERT(vkCreateDescriptorPool(vulkan.GetDevice(), &createInfo, nullptr, &descriptorPool), "DescriptorPool : Failed to initialize descriptor pool");
+ CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "DescriptorPool : Failed to initialize descriptor pool");
}
DescriptorPool::~DescriptorPool()
{
- vkDestroyDescriptorPool(vulkan.GetDevice(), descriptorPool, nullptr);
+ vkDestroyDescriptorPool(Vulkan::GetDevice(), descriptorPool, nullptr);
}
std::vector DescriptorPool::AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout)
@@ -40,13 +38,13 @@ namespace Copium
allocateInfo.descriptorSetCount = descriptorSets.size();
allocateInfo.pSetLayouts = layouts.data();
- CP_VK_ASSERT(vkAllocateDescriptorSets(vulkan.GetDevice(), &allocateInfo, descriptorSets.data()), "AllocateDescriptorSets : Failed to allocate descriptor sets");
+ CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "AllocateDescriptorSets : Failed to allocate descriptor sets");
return descriptorSets;
}
void DescriptorPool::FreeDescriptorSets(const std::vector& descriptorSets)
{
- vkFreeDescriptorSets(vulkan.GetDevice(), descriptorPool, descriptorSets.size(), descriptorSets.data());
+ vkFreeDescriptorSets(Vulkan::GetDevice(), descriptorPool, descriptorSets.size(), descriptorSets.data());
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.h b/CopiumEngine/src/copium/pipeline/DescriptorPool.h
index 1d4c1e9..ed50131 100644
--- a/CopiumEngine/src/copium/pipeline/DescriptorPool.h
+++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/util/Common.h"
-#include "copium/core/Vulkan.h"
#include
@@ -11,12 +10,10 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool);
private:
- Vulkan& vulkan;
-
VkDescriptorPool descriptorPool;
static const int DESCRIPTOR_SET_COUNT = 100;
public:
- DescriptorPool(Vulkan& vulkan);
+ DescriptorPool();
~DescriptorPool();
std::vector AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout);
diff --git a/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp b/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp
index 221166d..a79c115 100644
--- a/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp
+++ b/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp
@@ -1,12 +1,11 @@
#include "copium/pipeline/DescriptorSet.h"
-#include "copium/core/Device.h"
-#include "copium/core/SwapChain.h"
+#include "copium/core/Vulkan.h"
namespace Copium
{
- DescriptorSet::DescriptorSet(Vulkan& vulkan, DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings)
- : vulkan{vulkan}, descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
+ DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings)
+ : descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
{
CP_ASSERT(!bindings.empty(), "DescriptorSet : cannot initialize DescriptorSet with empty ShaderBindings");
@@ -15,7 +14,7 @@ namespace Copium
{
if (binding.bindingType == BindingType::UniformBuffer)
{
- std::unique_ptr uniformBuffer = std::make_unique(vulkan, binding);
+ std::unique_ptr uniformBuffer = std::make_unique(binding);
SetUniformBuffer(*uniformBuffer, binding.binding);
uniformBuffers.emplace(binding.name, std::move(uniformBuffer));
}
@@ -28,25 +27,6 @@ namespace Copium
descriptorPool.FreeDescriptorSets(descriptorSets);
}
- void DescriptorSet::SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding)
- {
- for (size_t i = 0; i < descriptorSets.size(); ++i) {
- VkDescriptorBufferInfo bufferInfo = uniformBuffer.GetDescriptorBufferInfo(i);
-
- VkWriteDescriptorSet descriptorWrite{};
- descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- descriptorWrite.dstSet = descriptorSets[i];
- descriptorWrite.dstBinding = binding;
- descriptorWrite.dstArrayElement = 0;
- descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
- descriptorWrite.descriptorCount = 1;
- descriptorWrite.pBufferInfo = &bufferInfo;
- descriptorWrite.pImageInfo = nullptr;
- descriptorWrite.pTexelBufferView = nullptr;
- vkUpdateDescriptorSets(vulkan.GetDevice(), 1, &descriptorWrite, 0, nullptr);
- }
- }
-
void DescriptorSet::SetSampler(const Sampler& sampler, uint32_t binding, int arrayIndex)
{
for (size_t i = 0; i < descriptorSets.size(); ++i)
@@ -62,16 +42,16 @@ namespace Copium
descriptorWrite.pBufferInfo = nullptr;
descriptorWrite.pImageInfo = &imageInfo;
descriptorWrite.pTexelBufferView = nullptr;
- vkUpdateDescriptorSets(vulkan.GetDevice(), 1, &descriptorWrite, 0, nullptr);
+ vkUpdateDescriptorSets(Vulkan::GetDevice(), 1, &descriptorWrite, 0, nullptr);
}
}
void DescriptorSet::SetSamplerDynamic(const Sampler& sampler, uint32_t binding, int arrayIndex)
{
- VkDescriptorImageInfo imageInfo = sampler.GetDescriptorImageInfo(vulkan.GetSwapChain().GetFlightIndex());
+ VkDescriptorImageInfo imageInfo = sampler.GetDescriptorImageInfo(Vulkan::GetSwapChain().GetFlightIndex());
VkWriteDescriptorSet descriptorWrite{};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- descriptorWrite.dstSet = descriptorSets[vulkan.GetSwapChain().GetFlightIndex()];
+ descriptorWrite.dstSet = descriptorSets[Vulkan::GetSwapChain().GetFlightIndex()];
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = arrayIndex;
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
@@ -79,7 +59,7 @@ namespace Copium
descriptorWrite.pBufferInfo = nullptr;
descriptorWrite.pImageInfo = &imageInfo;
descriptorWrite.pTexelBufferView = nullptr;
- vkUpdateDescriptorSets(vulkan.GetDevice(), 1, &descriptorWrite, 0, nullptr);
+ vkUpdateDescriptorSets(Vulkan::GetDevice(), 1, &descriptorWrite, 0, nullptr);
}
void DescriptorSet::SetSamplers(const std::vector& samplers, uint32_t binding)
@@ -99,7 +79,7 @@ namespace Copium
descriptorWrites[j].pImageInfo = &imageInfo;
descriptorWrites[j].pTexelBufferView = nullptr;
}
- vkUpdateDescriptorSets(vulkan.GetDevice(), descriptorWrites.size(), descriptorWrites.data(), 0, nullptr);
+ vkUpdateDescriptorSets(Vulkan::GetDevice(), descriptorWrites.size(), descriptorWrites.data(), 0, nullptr);
}
}
@@ -117,6 +97,26 @@ namespace Copium
DescriptorSet::operator VkDescriptorSet() const
{
- return descriptorSets[vulkan.GetSwapChain().GetFlightIndex()];
+ return descriptorSets[Vulkan::GetSwapChain().GetFlightIndex()];
}
+
+ void DescriptorSet::SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding)
+ {
+ for (size_t i = 0; i < descriptorSets.size(); ++i) {
+ VkDescriptorBufferInfo bufferInfo = uniformBuffer.GetDescriptorBufferInfo(i);
+
+ VkWriteDescriptorSet descriptorWrite{};
+ descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ descriptorWrite.dstSet = descriptorSets[i];
+ descriptorWrite.dstBinding = binding;
+ descriptorWrite.dstArrayElement = 0;
+ descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ descriptorWrite.descriptorCount = 1;
+ descriptorWrite.pBufferInfo = &bufferInfo;
+ descriptorWrite.pImageInfo = nullptr;
+ descriptorWrite.pTexelBufferView = nullptr;
+ vkUpdateDescriptorSets(Vulkan::GetDevice(), 1, &descriptorWrite, 0, nullptr);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/pipeline/DescriptorSet.h b/CopiumEngine/src/copium/pipeline/DescriptorSet.h
index ad0158d..d19d787 100644
--- a/CopiumEngine/src/copium/pipeline/DescriptorSet.h
+++ b/CopiumEngine/src/copium/pipeline/DescriptorSet.h
@@ -20,7 +20,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorSet);
private:
- Vulkan& vulkan;
DescriptorPool& descriptorPool;
VkDescriptorSetLayout descriptorSetLayout;
@@ -29,10 +28,9 @@ namespace Copium
std::map> uniformBuffers;
public:
- DescriptorSet(Vulkan& vulkan, DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings);
+ DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings);
~DescriptorSet();
- void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding);
void SetSampler(const Sampler& sampler, uint32_t binding, int arrayIndex = 0);
void SetSamplerDynamic(const Sampler& sampler, uint32_t binding, int arrayIndex = 0);
void SetSamplers(const std::vector& sampler, uint32_t binding);
@@ -40,5 +38,7 @@ namespace Copium
uint32_t GetSetIndex() const;
operator VkDescriptorSet() const;
+ private:
+ void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding);
};
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.cpp b/CopiumEngine/src/copium/pipeline/Pipeline.cpp
index 5a08d0b..b36532b 100644
--- a/CopiumEngine/src/copium/pipeline/Pipeline.cpp
+++ b/CopiumEngine/src/copium/pipeline/Pipeline.cpp
@@ -1,13 +1,13 @@
#include "copium/pipeline/Pipeline.h"
-#include "copium/core/Device.h"
+#include "copium/core/Vulkan.h"
#include "copium/pipeline/Shader.h"
#include "copium/util/FileSystem.h"
namespace Copium
{
- Pipeline::Pipeline(Vulkan& vulkan, PipelineCreator creator)
- : vulkan{vulkan}, shaderReflector{creator.shaderReflector}
+ Pipeline::Pipeline(PipelineCreator creator)
+ : shaderReflector{creator.shaderReflector}
{
InitializeDescriptorSetLayout(creator);
InitializePipeline(creator);
@@ -15,11 +15,11 @@ namespace Copium
Pipeline::~Pipeline()
{
- vkDestroyPipeline(vulkan.GetDevice(), graphicsPipeline, nullptr);
- vkDestroyPipelineLayout(vulkan.GetDevice(), pipelineLayout, nullptr);
+ vkDestroyPipeline(Vulkan::GetDevice(), graphicsPipeline, nullptr);
+ vkDestroyPipelineLayout(Vulkan::GetDevice(), pipelineLayout, nullptr);
for (auto&& descriptorSetLayout : descriptorSetLayouts)
{
- vkDestroyDescriptorSetLayout(vulkan.GetDevice(), descriptorSetLayout, nullptr);
+ vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr);
}
}
@@ -49,7 +49,7 @@ namespace Copium
bindings.emplace(binding);
}
- return std::make_unique(vulkan, descriptorPool, descriptorSetLayouts[setIndex], bindings);
+ return std::make_unique(descriptorPool, descriptorSetLayouts[setIndex], bindings);
}
void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator)
@@ -76,13 +76,13 @@ namespace Copium
createInfo.bindingCount = layoutBindings.size();
createInfo.pBindings = layoutBindings.data();
- CP_VK_ASSERT(vkCreateDescriptorSetLayout(vulkan.GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "InitializeDescriptorSetLayout : Failed to initialize descriptor set layout");
+ CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "InitializeDescriptorSetLayout : Failed to initialize descriptor set layout");
}
}
void Pipeline::InitializePipeline(const PipelineCreator& creator)
{
- Shader shader{vulkan, Shader::Type::GlslFile, creator.vertexShader, creator.fragmentShader};
+ Shader shader{Shader::Type::GlslFile, creator.vertexShader, creator.fragmentShader};
VkPipelineVertexInputStateCreateInfo vertexInputCreateInfo{};
vertexInputCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
@@ -192,7 +192,7 @@ namespace Copium
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
pipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
- CP_VK_ASSERT(vkCreatePipelineLayout(vulkan.GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "InitializePipeline : Failed to initialize pipeline layout");
+ CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "InitializePipeline : Failed to initialize pipeline layout");
const std::vector& shaderStages = shader.GetShaderStages();
VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{};
@@ -213,6 +213,6 @@ namespace Copium
graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
graphicsPipelineCreateInfo.basePipelineIndex = -1;
- CP_VK_ASSERT(vkCreateGraphicsPipelines(vulkan.GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "InitializePipeline : Failed to initialize graphics pipeline");
+ CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "InitializePipeline : Failed to initialize graphics pipeline");
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.h b/CopiumEngine/src/copium/pipeline/Pipeline.h
index d41dd30..d0be52a 100644
--- a/CopiumEngine/src/copium/pipeline/Pipeline.h
+++ b/CopiumEngine/src/copium/pipeline/Pipeline.h
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
-#include "copium/core/Vulkan.h"
#include "copium/pipeline/DescriptorSet.h"
#include "copium/pipeline/PipelineCreator.h"
#include "copium/util/Common.h"
@@ -15,8 +14,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
private:
- Vulkan& vulkan;
-
ShaderReflector shaderReflector;
std::vector descriptorSetLayouts{};
std::vector boundDescriptorSets;
@@ -24,7 +21,7 @@ namespace Copium
VkPipeline graphicsPipeline;
public:
- Pipeline(Vulkan& vulkan, PipelineCreator creator);
+ Pipeline(PipelineCreator creator);
~Pipeline();
void Bind(const CommandBuffer& commandBuffer);
void SetDescriptorSet(const DescriptorSet& descriptorSet);
diff --git a/CopiumEngine/src/copium/pipeline/PipelineCreator.h b/CopiumEngine/src/copium/pipeline/PipelineCreator.h
index 1b2be0a..85eba16 100644
--- a/CopiumEngine/src/copium/pipeline/PipelineCreator.h
+++ b/CopiumEngine/src/copium/pipeline/PipelineCreator.h
@@ -1,11 +1,12 @@
#pragma once
-#include "copium/pipeline/VertexDescriptor.h"
#include "copium/pipeline/ShaderReflector.h"
+#include "copium/pipeline/VertexDescriptor.h"
+
+#include
#include