Refactor for correct naming

This commit is contained in:
Chewico 2026-03-23 11:31:55 +01:00
parent 10175d92b3
commit 8b1aa63327
13 changed files with 171 additions and 198 deletions

View File

@ -83,7 +83,7 @@ namespace deerith {
QueueFamilyIndices find_queue_families(VkPhysicalDevice device); QueueFamilyIndices find_queue_families(VkPhysicalDevice device);
SwapChainSupportDetails query_swap_chain_support(VkPhysicalDevice device); SwapChainSupportDetails query_swap_chain_support(VkPhysicalDevice device);
void record_command_buffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); void record_command_buffer(VkCommandBuffer command_buffer, uint32_t image_index);
} // namespace graphics } // namespace graphics
} // namespace deerith } // namespace deerith

View File

@ -7,16 +7,16 @@ namespace deerith {
for (size_t i = 0; i < swap_chain_image_views.size(); i++) { for (size_t i = 0; i < swap_chain_image_views.size(); i++) {
VkImageView attachments[] = {swap_chain_image_views[i]}; VkImageView attachments[] = {swap_chain_image_views[i]};
VkFramebufferCreateInfo framebufferInfo{}; VkFramebufferCreateInfo frame_buffer_info{};
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; frame_buffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferInfo.renderPass = render_pass; frame_buffer_info.renderPass = render_pass;
framebufferInfo.attachmentCount = 1; frame_buffer_info.attachmentCount = 1;
framebufferInfo.pAttachments = attachments; frame_buffer_info.pAttachments = attachments;
framebufferInfo.width = swap_chain_extent.width; frame_buffer_info.width = swap_chain_extent.width;
framebufferInfo.height = swap_chain_extent.height; frame_buffer_info.height = swap_chain_extent.height;
framebufferInfo.layers = 1; frame_buffer_info.layers = 1;
if (vkCreateFramebuffer(device, &framebufferInfo, nullptr, &swap_chain_frame_buffers[i]) != VK_SUCCESS) { if (vkCreateFramebuffer(device, &frame_buffer_info, nullptr, &swap_chain_frame_buffers[i]) != VK_SUCCESS) {
deerith_graphics_error("failed to create framebuffer!"); deerith_graphics_error("failed to create framebuffer!");
} }
} }

View File

@ -9,37 +9,37 @@ namespace deerith {
} // namespace graphics } // namespace graphics
void graphics::create_vulkan_graphics_pipeline() { void graphics::create_vulkan_graphics_pipeline() {
auto vertShaderCode = read_file("shaders/vert.spv"); auto vert_shader_code = read_file("shaders/vert.spv");
auto fragShaderCode = read_file("shaders/frag.spv"); auto frag_shader_code = read_file("shaders/frag.spv");
VkShaderModule vertShaderModule = create_shader_module(vertShaderCode); VkShaderModule vert_shader_module = create_shader_module(vert_shader_code);
VkShaderModule fragShaderModule = create_shader_module(fragShaderCode); VkShaderModule frag_shader_module = create_shader_module(frag_shader_code);
VkPipelineShaderStageCreateInfo vertShaderStageInfo{}; VkPipelineShaderStageCreateInfo vert_shader_stage_info{};
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; vert_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; vert_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
vertShaderStageInfo.module = vertShaderModule; vert_shader_stage_info.module = vert_shader_module;
vertShaderStageInfo.pName = "main"; vert_shader_stage_info.pName = "main";
VkPipelineShaderStageCreateInfo fragShaderStageInfo{}; VkPipelineShaderStageCreateInfo frag_shader_stage_info{};
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; frag_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; frag_shader_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
fragShaderStageInfo.module = fragShaderModule; frag_shader_stage_info.module = frag_shader_module;
fragShaderStageInfo.pName = "main"; frag_shader_stage_info.pName = "main";
VkPipelineShaderStageCreateInfo shaderStages[] = {vertShaderStageInfo, fragShaderStageInfo}; VkPipelineShaderStageCreateInfo shader_stages[] = {vert_shader_stage_info, frag_shader_stage_info};
VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; VkPipelineVertexInputStateCreateInfo vertex_input_info{};
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertex_input_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputInfo.vertexBindingDescriptionCount = 0; vertex_input_info.vertexBindingDescriptionCount = 0;
vertexInputInfo.pVertexBindingDescriptions = nullptr; // Optional vertex_input_info.pVertexBindingDescriptions = nullptr; // Optional
vertexInputInfo.vertexAttributeDescriptionCount = 0; vertex_input_info.vertexAttributeDescriptionCount = 0;
vertexInputInfo.pVertexAttributeDescriptions = nullptr; // Optional vertex_input_info.pVertexAttributeDescriptions = nullptr; // Optional
VkPipelineInputAssemblyStateCreateInfo inputAssembly{}; VkPipelineInputAssemblyStateCreateInfo input_assembly{};
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; input_assembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
inputAssembly.primitiveRestartEnable = VK_FALSE; input_assembly.primitiveRestartEnable = VK_FALSE;
VkViewport viewport{}; VkViewport viewport{};
viewport.x = 0.0f; viewport.x = 0.0f;
@ -53,12 +53,12 @@ namespace deerith {
scissor.offset = {0, 0}; scissor.offset = {0, 0};
scissor.extent = swap_chain_extent; scissor.extent = swap_chain_extent;
VkPipelineViewportStateCreateInfo viewportState{}; VkPipelineViewportStateCreateInfo viewport_state{};
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportState.viewportCount = 1; viewport_state.viewportCount = 1;
viewportState.pViewports = &viewport; viewport_state.pViewports = &viewport;
viewportState.scissorCount = 1; viewport_state.scissorCount = 1;
viewportState.pScissors = &scissor; viewport_state.pScissors = &scissor;
VkPipelineRasterizationStateCreateInfo rasterizer{}; VkPipelineRasterizationStateCreateInfo rasterizer{};
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
@ -70,16 +70,16 @@ namespace deerith {
rasterizer.depthBiasClamp = 0.0f; // Optional rasterizer.depthBiasClamp = 0.0f; // Optional
rasterizer.depthBiasSlopeFactor = 0.0f; // Optional rasterizer.depthBiasSlopeFactor = 0.0f; // Optional
VkPipelineColorBlendAttachmentState colorBlendAttachment{}; VkPipelineColorBlendAttachmentState color_blend_attachment{};
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; color_blend_attachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
colorBlendAttachment.blendEnable = VK_FALSE; color_blend_attachment.blendEnable = VK_FALSE;
VkPipelineLayoutCreateInfo pipelineLayoutInfo{}; VkPipelineLayoutCreateInfo pipeline_layout_info{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.setLayoutCount = 0; // Optional pipeline_layout_info.setLayoutCount = 0; // Optional
pipelineLayoutInfo.pSetLayouts = nullptr; // Optional pipeline_layout_info.pSetLayouts = nullptr; // Optional
pipelineLayoutInfo.pushConstantRangeCount = 0; // Optional pipeline_layout_info.pushConstantRangeCount = 0; // Optional
pipelineLayoutInfo.pPushConstantRanges = nullptr; // Optional pipeline_layout_info.pPushConstantRanges = nullptr; // Optional
VkPipelineMultisampleStateCreateInfo multisampling{}; VkPipelineMultisampleStateCreateInfo multisampling{};
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
@ -90,44 +90,44 @@ namespace deerith {
multisampling.alphaToCoverageEnable = VK_FALSE; // Optional multisampling.alphaToCoverageEnable = VK_FALSE; // Optional
multisampling.alphaToOneEnable = VK_FALSE; // Optional multisampling.alphaToOneEnable = VK_FALSE; // Optional
VkPipelineColorBlendStateCreateInfo colorBlending{}; VkPipelineColorBlendStateCreateInfo color_blending{};
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; color_blending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlending.logicOpEnable = VK_FALSE; color_blending.logicOpEnable = VK_FALSE;
colorBlending.logicOp = VK_LOGIC_OP_COPY; // Optional color_blending.logicOp = VK_LOGIC_OP_COPY; // Optional
colorBlending.attachmentCount = 1; color_blending.attachmentCount = 1;
colorBlending.pAttachments = &colorBlendAttachment; color_blending.pAttachments = &color_blend_attachment;
colorBlending.blendConstants[0] = 0.0f; // Optional color_blending.blendConstants[0] = 0.0f; // Optional
colorBlending.blendConstants[1] = 0.0f; // Optional color_blending.blendConstants[1] = 0.0f; // Optional
colorBlending.blendConstants[2] = 0.0f; // Optional color_blending.blendConstants[2] = 0.0f; // Optional
colorBlending.blendConstants[3] = 0.0f; // Optional color_blending.blendConstants[3] = 0.0f; // Optional
if (vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &pipeline_layout) != VK_SUCCESS) { if (vkCreatePipelineLayout(device, &pipeline_layout_info, nullptr, &pipeline_layout) != VK_SUCCESS) {
deerith_graphics_error("failed to create pipeline layout!"); deerith_graphics_error("failed to create pipeline layout!");
} }
VkGraphicsPipelineCreateInfo pipelineInfo{}; VkGraphicsPipelineCreateInfo pipline_info{};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount = 2; pipline_info.stageCount = 2;
pipelineInfo.pStages = shaderStages; pipline_info.pStages = shader_stages;
pipelineInfo.pVertexInputState = &vertexInputInfo; pipline_info.pVertexInputState = &vertex_input_info;
pipelineInfo.pInputAssemblyState = &inputAssembly; pipline_info.pInputAssemblyState = &input_assembly;
pipelineInfo.pViewportState = &viewportState; pipline_info.pViewportState = &viewport_state;
pipelineInfo.pRasterizationState = &rasterizer; pipline_info.pRasterizationState = &rasterizer;
pipelineInfo.pMultisampleState = &multisampling; pipline_info.pMultisampleState = &multisampling;
pipelineInfo.pDepthStencilState = nullptr; // Optional pipline_info.pDepthStencilState = nullptr; // Optional
pipelineInfo.pColorBlendState = &colorBlending; pipline_info.pColorBlendState = &color_blending;
pipelineInfo.pDynamicState = nullptr; pipline_info.pDynamicState = nullptr;
pipelineInfo.layout = pipeline_layout; pipline_info.layout = pipeline_layout;
pipelineInfo.renderPass = render_pass; pipline_info.renderPass = render_pass;
pipelineInfo.subpass = 0; pipline_info.subpass = 0;
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphics_pipeline) != VK_SUCCESS) { if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipline_info, nullptr, &graphics_pipeline) != VK_SUCCESS) {
deerith_graphics_error("failed to create graphics pipeline!"); deerith_graphics_error("failed to create graphics pipeline!");
} }
vkDestroyShaderModule(device, fragShaderModule, nullptr); vkDestroyShaderModule(device, frag_shader_module, nullptr);
vkDestroyShaderModule(device, vertShaderModule, nullptr); vkDestroyShaderModule(device, vert_shader_module, nullptr);
} }
VkShaderModule graphics::create_shader_module(const std::vector<char>& code) { VkShaderModule graphics::create_shader_module(const std::vector<char>& code) {
@ -151,11 +151,11 @@ namespace deerith {
deerith_graphics_error("failed to open file!"); deerith_graphics_error("failed to open file!");
} }
size_t fileSize = (size_t)file.tellg(); size_t file_size = (size_t)file.tellg();
std::vector<char> buffer(fileSize); std::vector<char> buffer(file_size);
file.seekg(0); file.seekg(0);
file.read(buffer.data(), fileSize); file.read(buffer.data(), file_size);
file.close(); file.close();
return buffer; return buffer;

View File

@ -37,19 +37,21 @@ namespace deerith {
} }
bool graphics::is_device_suitable(VkPhysicalDevice device) { bool graphics::is_device_suitable(VkPhysicalDevice device) {
VkPhysicalDeviceProperties deviceProperties; VkPhysicalDeviceProperties device_properties;
vkGetPhysicalDeviceProperties(device, &deviceProperties); vkGetPhysicalDeviceProperties(device, &device_properties);
VkPhysicalDeviceFeatures deviceFeatures; VkPhysicalDeviceFeatures device_features;
vkGetPhysicalDeviceFeatures(device, &deviceFeatures); vkGetPhysicalDeviceFeatures(device, &device_features);
QueueFamilyIndices indices = find_queue_families(device); QueueFamilyIndices indices = find_queue_families(device);
SwapChainSupportDetails swap_chainSupport = query_swap_chain_support(device); SwapChainSupportDetails swap_chainSupport = query_swap_chain_support(device);
bool swap_chain_adequate = !swap_chainSupport.formats.empty() && !swap_chainSupport.present_modes.empty(); bool swap_chain_adequate = !swap_chainSupport.formats.empty() && !swap_chainSupport.present_modes.empty();
return deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && bool is_gpu = device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ||
deviceFeatures.geometryShader && device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
return is_gpu && device_features.geometryShader &&
indices.is_complete() && indices.is_complete() &&
swap_chain_adequate; swap_chain_adequate;
} }
@ -69,10 +71,10 @@ namespace deerith {
indices.graphics_family = i; indices.graphics_family = i;
} }
VkBool32 presentSupport = false; VkBool32 present_support = false;
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport); vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &present_support);
if (presentSupport) { if (present_support) {
indices.present_family = i; indices.present_family = i;
} }
@ -87,18 +89,18 @@ namespace deerith {
} }
bool graphics::check_device_extension_support(VkPhysicalDevice device) { bool graphics::check_device_extension_support(VkPhysicalDevice device) {
uint32_t extensionCount; uint32_t extension_count;
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, nullptr);
std::vector<VkExtensionProperties> availableExtensions(extensionCount); std::vector<VkExtensionProperties> available_extensions(extension_count);
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data()); vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, available_extensions.data());
std::set<std::string> requiredExtensions(device_extensions.begin(), device_extensions.end()); std::set<std::string> required_extensions(device_extensions.begin(), device_extensions.end());
for (const auto& extension : availableExtensions) { for (const auto& extension : available_extensions) {
requiredExtensions.erase(extension.extensionName); required_extensions.erase(extension.extensionName);
} }
return requiredExtensions.empty(); return required_extensions.empty();
} }
} // namespace deerith } // namespace deerith

View File

@ -2,57 +2,57 @@
namespace deerith { namespace deerith {
void graphics::create_vulkan_command_buffer() { void graphics::create_vulkan_command_buffer() {
QueueFamilyIndices queueFamilyIndices = find_queue_families(physical_device); QueueFamilyIndices queue_family_indices = find_queue_families(physical_device);
VkCommandPoolCreateInfo poolInfo{}; VkCommandPoolCreateInfo pool_info{};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
poolInfo.queueFamilyIndex = queueFamilyIndices.graphics_family.value(); pool_info.queueFamilyIndex = queue_family_indices.graphics_family.value();
if (vkCreateCommandPool(device, &poolInfo, nullptr, &command_pool) != VK_SUCCESS) { if (vkCreateCommandPool(device, &pool_info, nullptr, &command_pool) != VK_SUCCESS) {
deerith_graphics_error("failed to create command pool!"); deerith_graphics_error("failed to create command pool!");
} }
VkCommandBufferAllocateInfo allocInfo{}; VkCommandBufferAllocateInfo alloc_info{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = command_pool; alloc_info.commandPool = command_pool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = 1; alloc_info.commandBufferCount = 1;
if (vkAllocateCommandBuffers(device, &allocInfo, &command_buffer) != VK_SUCCESS) { if (vkAllocateCommandBuffers(device, &alloc_info, &command_buffer) != VK_SUCCESS) {
deerith_graphics_error("failed to allocate command buffers!"); deerith_graphics_error("failed to allocate command buffers!");
} }
} }
void graphics::record_command_buffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { void graphics::record_command_buffer(VkCommandBuffer command_buffer, uint32_t image_index) {
VkCommandBufferBeginInfo beginInfo{}; VkCommandBufferBeginInfo begin_info{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = 0; // Optional begin_info.flags = 0; // Optional
beginInfo.pInheritanceInfo = nullptr; // Optional begin_info.pInheritanceInfo = nullptr; // Optional
if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS) { if (vkBeginCommandBuffer(command_buffer, &begin_info) != VK_SUCCESS) {
deerith_graphics_error("failed to begin recording command buffer!"); deerith_graphics_error("failed to begin recording command buffer!");
} }
VkRenderPassBeginInfo renderPassInfo{}; VkRenderPassBeginInfo render_pass_info{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = render_pass; render_pass_info.renderPass = render_pass;
renderPassInfo.framebuffer = swap_chain_frame_buffers[imageIndex]; render_pass_info.framebuffer = swap_chain_frame_buffers[image_index];
renderPassInfo.renderArea.offset = {0, 0}; render_pass_info.renderArea.offset = {0, 0};
renderPassInfo.renderArea.extent = swap_chain_extent; render_pass_info.renderArea.extent = swap_chain_extent;
VkClearValue clearColor = {{{0.0f, 0.0f, 0.0f, 1.0f}}}; VkClearValue clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}};
renderPassInfo.clearValueCount = 1; render_pass_info.clearValueCount = 1;
renderPassInfo.pClearValues = &clearColor; render_pass_info.pClearValues = &clear_color;
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(command_buffer, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline); vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline);
vkCmdDraw(commandBuffer, 3, 1, 0, 0); vkCmdDraw(command_buffer, 3, 1, 0, 0);
vkCmdEndRenderPass(commandBuffer); vkCmdEndRenderPass(command_buffer);
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) { if (vkEndCommandBuffer(command_buffer) != VK_SUCCESS) {
deerith_graphics_error("failed to record command buffer!"); deerith_graphics_error("failed to record command buffer!");
} }
} }

View File

@ -2,37 +2,37 @@
namespace deerith { namespace deerith {
void graphics::create_vulkan_render_pass() { void graphics::create_vulkan_render_pass() {
VkAttachmentDescription colorAttachment{}; VkAttachmentDescription color_attachment{};
colorAttachment.format = swap_chain_image_format; color_attachment.format = swap_chain_image_format;
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; color_attachment.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; color_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; color_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; color_attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; color_attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; color_attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; color_attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
VkAttachmentReference colorAttachmentRef{}; VkAttachmentReference color_attachmentRef{};
colorAttachmentRef.attachment = 0; color_attachmentRef.attachment = 0;
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; color_attachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass{}; VkSubpassDescription subpass{};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1; subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef; subpass.pColorAttachments = &color_attachmentRef;
VkRenderPassCreateInfo renderPassInfo{}; VkRenderPassCreateInfo render_pass_info{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; render_pass_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = 1; render_pass_info.attachmentCount = 1;
renderPassInfo.pAttachments = &colorAttachment; render_pass_info.pAttachments = &color_attachment;
renderPassInfo.subpassCount = 1; render_pass_info.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass; render_pass_info.pSubpasses = &subpass;
if (vkCreateRenderPass(device, &renderPassInfo, nullptr, &render_pass) != VK_SUCCESS) { if (vkCreateRenderPass(device, &render_pass_info, nullptr, &render_pass) != VK_SUCCESS) {
deerith_graphics_error("failed to create render pass!"); deerith_graphics_error("failed to create render pass!");
} }
} }

View File

@ -31,30 +31,30 @@ namespace deerith {
vkWaitForFences(device, 1, &in_flight_fence, VK_TRUE, UINT64_MAX); vkWaitForFences(device, 1, &in_flight_fence, VK_TRUE, UINT64_MAX);
vkResetFences(device, 1, &in_flight_fence); vkResetFences(device, 1, &in_flight_fence);
uint32_t imageIndex; uint32_t image_index;
vkAcquireNextImageKHR(device, swap_chain, UINT64_MAX, image_available_semaphore, VK_NULL_HANDLE, &imageIndex); vkAcquireNextImageKHR(device, swap_chain, UINT64_MAX, image_available_semaphore, VK_NULL_HANDLE, &image_index);
vkResetCommandBuffer(command_buffer, 0); vkResetCommandBuffer(command_buffer, 0);
record_command_buffer(command_buffer, imageIndex); record_command_buffer(command_buffer, image_index);
VkSubmitInfo submitInfo{}; VkSubmitInfo submit_info{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
VkSemaphore waitSemaphores[] = {image_available_semaphore}; VkSemaphore waitSemaphores[] = {image_available_semaphore};
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
submitInfo.waitSemaphoreCount = 1; submit_info.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = waitSemaphores; submit_info.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages; submit_info.pWaitDstStageMask = waitStages;
submitInfo.commandBufferCount = 1; submit_info.commandBufferCount = 1;
submitInfo.pCommandBuffers = &command_buffer; submit_info.pCommandBuffers = &command_buffer;
VkSemaphore signalSemaphores[] = {render_finished_semaphore}; VkSemaphore signalSemaphores[] = {render_finished_semaphore};
submitInfo.signalSemaphoreCount = 1; submit_info.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores; submit_info.pSignalSemaphores = signalSemaphores;
if (vkQueueSubmit(graphics_queue, 1, &submitInfo, in_flight_fence) != VK_SUCCESS) { if (vkQueueSubmit(graphics_queue, 1, &submit_info, in_flight_fence) != VK_SUCCESS) {
deerith_graphics_error("failed to submit draw command buffer!"); deerith_graphics_error("failed to submit draw command buffer!");
} }
@ -77,7 +77,7 @@ namespace deerith {
VkSwapchainKHR swapChains[] = {swap_chain}; VkSwapchainKHR swapChains[] = {swap_chain};
presentInfo.swapchainCount = 1; presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains; presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &imageIndex; presentInfo.pImageIndices = &image_index;
presentInfo.pResults = nullptr; // Optional presentInfo.pResults = nullptr; // Optional
vkQueuePresentKHR(pressent_queue, &presentInfo); vkQueuePresentKHR(pressent_queue, &presentInfo);

View File

@ -34,12 +34,12 @@ namespace deerith {
create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
QueueFamilyIndices indices = find_queue_families(physical_device); QueueFamilyIndices indices = find_queue_families(physical_device);
uint32_t queueFamilyIndices[] = {indices.graphics_family.value(), indices.present_family.value()}; uint32_t queue_family_indices[] = {indices.graphics_family.value(), indices.present_family.value()};
if (indices.graphics_family != indices.present_family) { if (indices.graphics_family != indices.present_family) {
create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
create_info.queueFamilyIndexCount = 2; create_info.queueFamilyIndexCount = 2;
create_info.pQueueFamilyIndices = queueFamilyIndices; create_info.pQueueFamilyIndices = queue_family_indices;
} else { } else {
create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
create_info.queueFamilyIndexCount = 0; create_info.queueFamilyIndexCount = 0;

View File

@ -27,8 +27,8 @@ namespace deerith {
for (const char* layerName : validation_layers) { for (const char* layerName : validation_layers) {
bool layerFound = false; bool layerFound = false;
for (const auto& layerProperties : available_layers) { for (const auto& layer_properties : available_layers) {
if (strcmp(layerName, layerProperties.layerName) == 0) { if (strcmp(layerName, layer_properties.layerName) == 0) {
layerFound = true; layerFound = true;
break; break;
} }

Binary file not shown.

View File

@ -1,9 +0,0 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(fragColor, 1.0);
}

View File

@ -1,20 +0,0 @@
#version 450
layout(location = 0) out vec3 fragColor;
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
vec3 colors[3] = vec3[](
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(0.0, 0.0, 1.0)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragColor = colors[gl_VertexIndex];
}

Binary file not shown.