Skip to content

Commit

Permalink
Not Crashing Currently
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheeleynz committed Jul 25, 2021
1 parent 2f439df commit 24461c0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace Arcane {

void VulkanContext::SwapBuffers()
{
// printf("Swapchain Image index: %d\n", m_SwapChain->GetImageIndex());
m_SwapChain->SwapBuffers();
}
}
1 change: 1 addition & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Arcane {
public:
VulkanPipeline(PipelineSpecification& spec);

VkPipelineLayout GetLayout() { return m_PipelineLayout; }
VkPipeline GetPipeline() { return m_Pipeline; }
private:
VkPipelineLayout m_PipelineLayout;
Expand Down
1 change: 1 addition & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ namespace Arcane {

uint32_t imageIndex;
vkAcquireNextImageKHR(_context->GetDevice().GetLogicalDevice(), m_SwapChain, UINT64_MAX, m_ImageAvailableSemaphores[m_CurrentFrameIndex], VK_NULL_HANDLE, &imageIndex);
m_CurrentImageIndex = imageIndex;

if (m_ImagesInFlight[imageIndex] != VK_NULL_HANDLE) {
vkWaitForFences(_context->GetDevice().GetLogicalDevice(), 1, &m_ImagesInFlight[imageIndex], VK_TRUE, UINT64_MAX);
Expand Down
3 changes: 3 additions & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanSwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Arcane {
std::vector<VkFramebuffer> GetSwapChainFramebuffers() { return m_SwapChainFramebuffers; }
uint32_t GetSwapChainImagesSize() { return m_SwapChainImages.size(); }

uint32_t GetImageIndex() { return m_CurrentImageIndex; }

void SwapBuffers();
private:
VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
Expand Down Expand Up @@ -47,5 +49,6 @@ namespace Arcane {

int m_MaxFramesInFlight = 2;
size_t m_CurrentFrameIndex = 0;
uint32_t m_CurrentImageIndex = 0;
};
}
9 changes: 9 additions & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanUniformBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace Arcane {

VulkanUniformBuffer::VulkanUniformBuffer(uint32_t size)
{
m_Size = size;

Application& app = Application::Get();
VulkanContext* context = static_cast<VulkanContext*>(app.GetWindow().GetContext());
VkDevice logicalDevice = context->GetDevice().GetLogicalDevice();
Expand Down Expand Up @@ -141,6 +143,13 @@ namespace Arcane {

void VulkanUniformBuffer::WriteData(void* data)
{
Application& app = Application::Get();
VulkanContext* context = static_cast<VulkanContext*>(app.GetWindow().GetContext());
VkDevice logicalDevice = context->GetDevice().GetLogicalDevice();

// Copy data into uniform buffer memory
vkMapMemory(logicalDevice, m_UniformBuffersMemory[context->GetSwapChain().GetImageIndex()], 0, m_Size, 0, &data);
memcpy(data, data, m_Size);
vkUnmapMemory(logicalDevice, m_UniformBuffersMemory[context->GetSwapChain().GetImageIndex()]);
}
}
3 changes: 3 additions & 0 deletions Arcane/src/Arcane/Platform/Vulkan/VulkanUniformBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ namespace Arcane {
std::vector<VkBuffer> m_UniformBuffers;
std::vector<VkDeviceMemory> m_UniformBuffersMemory;
std::vector<VkDescriptorSet> m_DescriptorSets;

// Uniform Buffer Size
uint32_t m_Size;
};
}
4 changes: 2 additions & 2 deletions EnchantingTable/src/Assets/Shaders/Basic.vert
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450

layout (location = 0) uniform UniformBufferObject {
layout (binding = 0) uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
Expand All @@ -12,6 +12,6 @@ layout (location = 1) in vec3 aColor;
layout(location = 0) out vec3 fragColor;

void main() {
gl_Position = vec4(aPos, 1.0);
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(aPos, 1.0);
fragColor = aColor;
}
Binary file modified EnchantingTable/src/Assets/Shaders/vert.spv
Binary file not shown.
21 changes: 15 additions & 6 deletions EnchantingTable/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ void EditorLayer::OnAttach()
Arcane::VertexType::float3
});

m_UniformBuffer = Arcane::UniformBuffer::Create(sizeof(UniformBufferObject));

// Test Pipeline
Arcane::PipelineSpecification spec;
spec.descriptor = m_VertexDescriptor;
spec.renderPass = m_RenderPass;
spec.shader = m_Shader;
spec.uniformBuffer = Arcane::UniformBuffer::Create(sizeof(UniformBufferObject));
spec.uniformBuffer = m_UniformBuffer;

m_Pipeline = Arcane::Pipeline::Create(spec);

Expand All @@ -60,6 +62,15 @@ void EditorLayer::OnAttach()
m_VertexBuffer = Arcane::VertexBuffer::Create(vertices.data(), sizeof(TestVertex) * vertices.size());
Arcane::IndexBuffer* indexBuffer = Arcane::IndexBuffer::Create(indices.data(), indices.size());
m_VertexBuffer->AddIndexBuffer(indexBuffer);

UniformBufferObject ubo{};
ubo.model = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), 1600.0f / 1200.0f, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;

m_UniformBuffer->WriteData(&ubo);

}

void EditorLayer::OnDetach()
Expand All @@ -69,12 +80,10 @@ void EditorLayer::OnDetach()

void EditorLayer::OnUpdate(float deltaTime)
{
printf("%.2f\n", deltaTime);
// printf("%.2f\n", deltaTime);

UniformBufferObject ubo{};
ubo.model = glm::rotate(glm::mat4(1.0f), deltaTime * glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), 1600.0f / 1200.0f, 0.1f, 10.0f);

// m_UniformBuffer->WriteData(&ubo);

// Begin a Render pass
Arcane::Renderer::BeginRenderPass(m_RenderPass);
Expand Down

0 comments on commit 24461c0

Please sign in to comment.