Compare commits
No commits in common. "fc9768f859566caa7091bdc658b924c257457490" and "7c7c01bdac6e25ff170f1021910f81bdf50772a8" have entirely different histories.
fc9768f859
...
7c7c01bdac
2 changed files with 5 additions and 67 deletions
|
|
@ -30,17 +30,6 @@ file(GLOB_RECURSE HEADER_FILES
|
||||||
${CMAKE_SOURCE_DIR}/src/*.h)
|
${CMAKE_SOURCE_DIR}/src/*.h)
|
||||||
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
|
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
|
||||||
|
|
||||||
# Error on memory address issues in debug mode
|
|
||||||
if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
|
||||||
set(
|
|
||||||
CMAKE_C_FLAGS
|
|
||||||
"${CMAKE_C_FLAGS} -Werror -fsanitize=undefined -fsanitize=address"
|
|
||||||
)
|
|
||||||
target_link_options(${PROJECT_NAME}
|
|
||||||
BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Link Libraries
|
# Link Libraries
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
${GLFW_LIBRARIES}
|
${GLFW_LIBRARIES}
|
||||||
|
|
|
||||||
61
src/main.c
61
src/main.c
|
|
@ -6,7 +6,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
@ -50,11 +49,8 @@ typedef struct Application {
|
||||||
VkQueue presentQueue;
|
VkQueue presentQueue;
|
||||||
VkSwapchainKHR swapChain;
|
VkSwapchainKHR swapChain;
|
||||||
VkImage *swapChainImages;
|
VkImage *swapChainImages;
|
||||||
uint32_t swapChainImageCount;
|
|
||||||
VkFormat swapChainImageFormat;
|
VkFormat swapChainImageFormat;
|
||||||
VkExtent2D swapChainExtent;
|
VkExtent2D swapChainExtent;
|
||||||
VkImageView *swapChainImageViews;
|
|
||||||
uint32_t swapChainImageViewCount;
|
|
||||||
} Application;
|
} Application;
|
||||||
|
|
||||||
typedef struct SwapChainSupportDetails {
|
typedef struct SwapChainSupportDetails {
|
||||||
|
|
@ -183,17 +179,16 @@ void createInstance(Application *app) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This currently leaks memory :(
|
|
||||||
VkResult result = vkCreateInstance(&createInfo, NULL, &app->instance);
|
VkResult result = vkCreateInstance(&createInfo, NULL, &app->instance);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to create vulkan instance\n");
|
fprintf(stderr, "Failed to create vulkan instance\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Instance Extentions Available:\n");
|
printf("Instance Extentions Available:\n");
|
||||||
//for (uint i = 0; i < extensionCount; i++) {
|
for (uint i = 0; i < extensionCount; i++) {
|
||||||
// printf("\t%s\n", extensions[i].extensionName);
|
printf("\t%s\n", extensions[i].extensionName);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initWindow(Application *app) {
|
void initWindow(Application *app) {
|
||||||
|
|
@ -335,7 +330,7 @@ SwapChainSupportDetails querySwapchainSupport(VkPhysicalDevice device,
|
||||||
&details.numPresentModes, NULL);
|
&details.numPresentModes, NULL);
|
||||||
if (details.numPresentModes > 0) {
|
if (details.numPresentModes > 0) {
|
||||||
details.presentModes =
|
details.presentModes =
|
||||||
malloc(details.numPresentModes * sizeof(VkPresentModeKHR));
|
malloc(details.numFormats * sizeof(VkPresentModeKHR));
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR(
|
vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||||
device, *surface, &details.numPresentModes, details.presentModes);
|
device, *surface, &details.numPresentModes, details.presentModes);
|
||||||
}
|
}
|
||||||
|
|
@ -571,48 +566,8 @@ void createSwapChain(Application *app) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkGetSwapchainImagesKHR(app->device, app->swapChain,
|
|
||||||
&app->swapChainImageCount, NULL);
|
|
||||||
app->swapChainImages = malloc(app->swapChainImageCount * sizeof(VkImage));
|
|
||||||
vkGetSwapchainImagesKHR(app->device, app->swapChain,
|
|
||||||
&app->swapChainImageCount, app->swapChainImages);
|
|
||||||
|
|
||||||
app->swapChainImageFormat = surfaceFormat.format;
|
app->swapChainImageFormat = surfaceFormat.format;
|
||||||
app->swapChainExtent = extent;
|
app->swapChainExtent = extent;
|
||||||
|
|
||||||
free(swapChainSupport.presentModes);
|
|
||||||
free(swapChainSupport.formats);
|
|
||||||
}
|
|
||||||
|
|
||||||
void createImageViews(Application *app) {
|
|
||||||
app->swapChainImageViewCount = app->swapChainImageCount;
|
|
||||||
app->swapChainImageViews =
|
|
||||||
malloc(app->swapChainImageViewCount * sizeof(VkImageView));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < app->swapChainImageViewCount; i++) {
|
|
||||||
VkImageViewCreateInfo createInfo = {0};
|
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
||||||
createInfo.image = app->swapChainImages[i];
|
|
||||||
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
createInfo.format = app->swapChainImageFormat;
|
|
||||||
|
|
||||||
createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
|
||||||
createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
|
||||||
createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
|
||||||
createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
|
||||||
|
|
||||||
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
createInfo.subresourceRange.baseMipLevel = 0;
|
|
||||||
createInfo.subresourceRange.levelCount = 1;
|
|
||||||
createInfo.subresourceRange.baseArrayLayer = 0;
|
|
||||||
createInfo.subresourceRange.layerCount = 1;
|
|
||||||
|
|
||||||
if (vkCreateImageView(app->device, &createInfo, NULL,
|
|
||||||
&app->swapChainImageViews[i]) != VK_SUCCESS) {
|
|
||||||
fprintf(stderr, "Failed to create image views!\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initVulkan(Application *app) {
|
void initVulkan(Application *app) {
|
||||||
|
|
@ -622,7 +577,6 @@ void initVulkan(Application *app) {
|
||||||
pickPhysicalDevice(app);
|
pickPhysicalDevice(app);
|
||||||
createLogicalDevice(app);
|
createLogicalDevice(app);
|
||||||
createSwapChain(app);
|
createSwapChain(app);
|
||||||
createImageViews(app);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainLoop(Application *app) {
|
void mainLoop(Application *app) {
|
||||||
|
|
@ -632,11 +586,6 @@ void mainLoop(Application *app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup(Application *app) {
|
void cleanup(Application *app) {
|
||||||
for (size_t i = 0; i < app->swapChainImageViewCount; i++) {
|
|
||||||
vkDestroyImageView(app->device, app->swapChainImageViews[i], NULL);
|
|
||||||
}
|
|
||||||
free(app->swapChainImageViews);
|
|
||||||
free(app->swapChainImages);
|
|
||||||
vkDestroySwapchainKHR(app->device, app->swapChain, NULL);
|
vkDestroySwapchainKHR(app->device, app->swapChain, NULL);
|
||||||
vkDestroyDevice(app->device, NULL);
|
vkDestroyDevice(app->device, NULL);
|
||||||
if (enableValidationLayers) {
|
if (enableValidationLayers) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue