|
@@ -7,12 +7,14 @@
|
|
#include "core/internal/GLFW.h"
|
|
#include "core/internal/GLFW.h"
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
|
|
+ VkFormat format;
|
|
VkSwapchainKHR handle;
|
|
VkSwapchainKHR handle;
|
|
u32 amount;
|
|
u32 amount;
|
|
VkImage* images;
|
|
VkImage* images;
|
|
VkImageView* imageViews;
|
|
VkImageView* imageViews;
|
|
VkCommandPool commandPool;
|
|
VkCommandPool commandPool;
|
|
VkCommandBuffer* commandsBuffers;
|
|
VkCommandBuffer* commandsBuffers;
|
|
|
|
+ VkFramebuffer* framebuffers;
|
|
} Swapchain;
|
|
} Swapchain;
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
@@ -29,6 +31,7 @@ typedef struct {
|
|
VkSemaphore semaphore;
|
|
VkSemaphore semaphore;
|
|
VkSemaphore renderSemaphore;
|
|
VkSemaphore renderSemaphore;
|
|
Swapchain swapchain;
|
|
Swapchain swapchain;
|
|
|
|
+ VkRenderPass renderPass;
|
|
u32 width;
|
|
u32 width;
|
|
u32 height;
|
|
u32 height;
|
|
} VulkanData;
|
|
} VulkanData;
|
|
@@ -308,6 +311,7 @@ static bool initSwapchain() {
|
|
if(getSurfaceFormat(&sf)) {
|
|
if(getSurfaceFormat(&sf)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ vk.swapchain.format = sf.format;
|
|
VkPresentModeKHR pm = {0};
|
|
VkPresentModeKHR pm = {0};
|
|
if(getPresentMode(&pm)) {
|
|
if(getPresentMode(&pm)) {
|
|
return true;
|
|
return true;
|
|
@@ -426,6 +430,32 @@ static void destroyCommandBuffers() {
|
|
vkDestroyCommandPool(vk.device, vk.swapchain.commandPool, nullptr);
|
|
vkDestroyCommandPool(vk.device, vk.swapchain.commandPool, nullptr);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static bool initRenderPass() {
|
|
|
|
+ VkAttachmentDescription c = {
|
|
|
|
+ .format = vk.swapchain.format,
|
|
|
|
+ .samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
+ .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
+ .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
|
|
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
|
|
|
|
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
+ .finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR};
|
|
|
|
+ VkAttachmentReference ca = {
|
|
|
|
+ .attachment = 0, .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
|
|
|
|
+ VkSubpassDescription subpass = {.pipelineBindPoint =
|
|
|
|
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
+ .colorAttachmentCount = 1,
|
|
|
|
+ .pColorAttachments = &ca};
|
|
|
|
+ VkRenderPassCreateInfo info = {
|
|
|
|
+ .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
|
|
|
+ .attachmentCount = 1,
|
|
|
|
+ .pAttachments = &c,
|
|
|
|
+ .subpassCount = 1,
|
|
|
|
+ .pSubpasses = &subpass};
|
|
|
|
+ VK_ASSERT(vkCreateRenderPass(vk.device, &info, nullptr, &vk.renderPass));
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
bool initVulkan() {
|
|
bool initVulkan() {
|
|
vk.width = 400;
|
|
vk.width = 400;
|
|
vk.height = 300;
|
|
vk.height = 300;
|
|
@@ -433,16 +463,32 @@ bool initVulkan() {
|
|
initPhysicalDevice() || initDevice() || checkPresentationSupport() ||
|
|
initPhysicalDevice() || initDevice() || checkPresentationSupport() ||
|
|
initSwapchain() || initSwapchainImages() ||
|
|
initSwapchain() || initSwapchainImages() ||
|
|
initSemaphore(&vk.semaphore) || initSemaphore(&vk.renderSemaphore) ||
|
|
initSemaphore(&vk.semaphore) || initSemaphore(&vk.renderSemaphore) ||
|
|
- initCommandBuffers();
|
|
|
|
|
|
+ initCommandBuffers() || initRenderPass();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static bool fillCommandBuffer(u32 index) {
|
|
|
|
+ VkCommandBufferBeginInfo info = {
|
|
|
|
+ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
+ .flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT};
|
|
|
|
+ VK_ASSERT(vkBeginCommandBuffer(vk.swapchain.commandsBuffers[index], &info));
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void renderVulkan() {
|
|
|
|
+ for(u32 i = 0; i < vk.swapchain.amount; i++) {
|
|
|
|
+ (void)fillCommandBuffer;
|
|
|
|
+ // fillCommandBuffer(i);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void destroyVulkan(void) {
|
|
void destroyVulkan(void) {
|
|
if(vk.device != VK_NULL_HANDLE) {
|
|
if(vk.device != VK_NULL_HANDLE) {
|
|
- destroySwapchainImages();
|
|
|
|
- vkDestroySwapchainKHR(vk.device, vk.swapchain.handle, nullptr);
|
|
|
|
|
|
+ vkDestroyRenderPass(vk.device, vk.renderPass, nullptr);
|
|
|
|
+ destroyCommandBuffers();
|
|
destroySemaphore(vk.semaphore);
|
|
destroySemaphore(vk.semaphore);
|
|
destroySemaphore(vk.renderSemaphore);
|
|
destroySemaphore(vk.renderSemaphore);
|
|
- destroyCommandBuffers();
|
|
|
|
|
|
+ destroySwapchainImages();
|
|
|
|
+ vkDestroySwapchainKHR(vk.device, vk.swapchain.handle, nullptr);
|
|
}
|
|
}
|
|
vkDestroyDevice(vk.device, nullptr);
|
|
vkDestroyDevice(vk.device, nullptr);
|
|
if(vk.instance != VK_NULL_HANDLE) {
|
|
if(vk.instance != VK_NULL_HANDLE) {
|