From 40f5a89f05e83273ab55a1e1dc0a9df119c08b0e Mon Sep 17 00:00:00 2001 From: Pawel Lapinski Date: Tue, 20 Mar 2018 10:25:34 +0100 Subject: [PATCH] Small code refactoring. --- Project/CMakeLists.txt | 7 +++---- Project/Common/OperatingSystem.cpp | 3 ++- Project/Common/VulkanCommon.cpp | 30 ++++++++++++++++------------- Project/Common/VulkanCommon.h | 2 +- Project/Tutorials/01/Tutorial01.cpp | 6 +++--- Project/Tutorials/02/Tutorial02.cpp | 28 +++++++++++++-------------- Project/Tutorials/03/Tutorial03.cpp | 8 ++++---- Project/Tutorials/04/Tutorial04.cpp | 12 ++++++------ Project/Tutorials/05/Tutorial05.cpp | 14 +++++++------- Project/Tutorials/06/Tutorial06.cpp | 8 ++++---- Project/Tutorials/07/Tutorial07.cpp | 10 +++++----- 11 files changed, 66 insertions(+), 62 deletions(-) diff --git a/Project/CMakeLists.txt b/Project/CMakeLists.txt index c17cdbf..6346d80 100644 --- a/Project/CMakeLists.txt +++ b/Project/CMakeLists.txt @@ -39,6 +39,7 @@ if( USE_PLATFORM STREQUAL "VK_USE_PLATFORM_WIN32_KHR" ) set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT" ) set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd" ) set( PLATFORM_LIBRARY "" ) + add_definitions( -DNOMINMAX ) elseif( USE_PLATFORM STREQUAL "VK_USE_PLATFORM_XCB_KHR" ) add_definitions( -std=c++11 ) set( PLATFORM_LIBRARY dl xcb ) @@ -108,11 +109,9 @@ set( PROJECT_HEADER_FILES REGULAR_EXPRESSION set( PROJECT_SOURCE_FILES REGULAR_EXPRESSION "(Tutorial|Benchmark)[0-9]+[.]cpp" ) -source_group( "Header Files\\Common" FILES ${BASIC_SHARED_HEADER_FILES} ) -source_group( "Source Files\\Common" FILES ${BASIC_SHARED_SOURCE_FILES} ) +source_group( "Header Files\\Common" FILES ${BASIC_SHARED_HEADER_FILES} ${ADVANCED_SHARED_HEADER_FILES} ) +source_group( "Source Files\\Common" FILES ${BASIC_SHARED_SOURCE_FILES} ${ADVANCED_SHARED_SOURCE_FILES} ) source_group( "Header Files\\External" FILES ${EXTERNAL_HEADER_FILES} ) -source_group( "Header Files\\Common" FILES ${ADVANCED_SHARED_HEADER_FILES} ) -source_group( "Source Files\\Common" FILES ${ADVANCED_SHARED_SOURCE_FILES} ) source_group( "Header Files" FILES ${PROJECT_HEADER_FILES} ) source_group( "Source Files" FILES ${PROJECT_SOURCE_FILES} ) diff --git a/Project/Common/OperatingSystem.cpp b/Project/Common/OperatingSystem.cpp index d8e10cd..4e2e01d 100644 --- a/Project/Common/OperatingSystem.cpp +++ b/Project/Common/OperatingSystem.cpp @@ -120,7 +120,7 @@ namespace ApiWithoutSecrets { TranslateMessage( &message ); DispatchMessage( &message ); } else { - // Draw + // Resize if( resize ) { resize = false; if( !project.OnWindowSizeChanged() ) { @@ -128,6 +128,7 @@ namespace ApiWithoutSecrets { break; } } + // Draw if( project.ReadyToDraw() ) { if( !project.Draw() ) { result = false; diff --git a/Project/Common/VulkanCommon.cpp b/Project/Common/VulkanCommon.cpp index 558ec77..b06a39a 100644 --- a/Project/Common/VulkanCommon.cpp +++ b/Project/Common/VulkanCommon.cpp @@ -62,6 +62,10 @@ namespace ApiWithoutSecrets { } bool VulkanCommon::OnWindowSizeChanged() { + if( Vulkan.Device != VK_NULL_HANDLE ) { + vkDeviceWaitIdle( Vulkan.Device ); + } + ChildClear(); if( CreateSwapChain() ) { @@ -90,7 +94,7 @@ namespace ApiWithoutSecrets { return Vulkan.PresentQueue; } - const SwapChainParameters VulkanCommon::GetSwapChain() const { + const SwapChainParameters& VulkanCommon::GetSwapChain() const { return Vulkan.SwapChain; } @@ -147,7 +151,7 @@ namespace ApiWithoutSecrets { } std::vector available_extensions( extensions_count ); - if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { + if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, available_extensions.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } @@ -188,7 +192,7 @@ namespace ApiWithoutSecrets { 0, // uint32_t enabledLayerCount nullptr, // const char * const *ppEnabledLayerNames static_cast(extensions.size()), // uint32_t enabledExtensionCount - &extensions[0] // const char * const *ppEnabledExtensionNames + extensions.data() // const char * const *ppEnabledExtensionNames }; if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) { @@ -264,7 +268,7 @@ namespace ApiWithoutSecrets { } std::vector physical_devices( num_devices ); - if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { + if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, physical_devices.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -292,7 +296,7 @@ namespace ApiWithoutSecrets { 0, // VkDeviceQueueCreateFlags flags selected_graphics_queue_family_index, // uint32_t queueFamilyIndex static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + queue_priorities.data() // const float *pQueuePriorities } ); if( selected_graphics_queue_family_index != selected_present_queue_family_index ) { @@ -302,7 +306,7 @@ namespace ApiWithoutSecrets { 0, // VkDeviceQueueCreateFlags flags selected_present_queue_family_index, // uint32_t queueFamilyIndex static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + queue_priorities.data() // const float *pQueuePriorities } ); } @@ -315,11 +319,11 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkDeviceCreateFlags flags static_cast(queue_create_infos.size()), // uint32_t queueCreateInfoCount - &queue_create_infos[0], // const VkDeviceQueueCreateInfo *pQueueCreateInfos + queue_create_infos.data(), // const VkDeviceQueueCreateInfo *pQueueCreateInfos 0, // uint32_t enabledLayerCount nullptr, // const char * const *ppEnabledLayerNames static_cast(extensions.size()), // uint32_t enabledExtensionCount - &extensions[0], // const char * const *ppEnabledExtensionNames + extensions.data(), // const char * const *ppEnabledExtensionNames nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures }; @@ -342,7 +346,7 @@ namespace ApiWithoutSecrets { } std::vector available_extensions( extensions_count ); - if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { + if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, available_extensions.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } @@ -382,7 +386,7 @@ namespace ApiWithoutSecrets { std::vector queue_family_properties( queue_families_count ); std::vector queue_present_support( queue_families_count ); - vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] ); + vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, queue_family_properties.data() ); uint32_t graphics_queue_family_index = UINT32_MAX; uint32_t present_queue_family_index = UINT32_MAX; @@ -473,7 +477,7 @@ namespace ApiWithoutSecrets { } std::vector surface_formats( formats_count ); - if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, &surface_formats[0] ) != VK_SUCCESS ) { + if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, surface_formats.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } @@ -486,7 +490,7 @@ namespace ApiWithoutSecrets { } std::vector present_modes( present_modes_count ); - if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, &present_modes[0] ) != VK_SUCCESS ) { + if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, present_modes.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } @@ -551,7 +555,7 @@ namespace ApiWithoutSecrets { Vulkan.SwapChain.Images.resize( image_count ); std::vector images( image_count ); - if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, &images[0] ) != VK_SUCCESS ) { + if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, images.data() ) != VK_SUCCESS ) { std::cout << "Could not get swap chain images!" << std::endl; return false; } diff --git a/Project/Common/VulkanCommon.h b/Project/Common/VulkanCommon.h index f843318..5c7df7b 100644 --- a/Project/Common/VulkanCommon.h +++ b/Project/Common/VulkanCommon.h @@ -154,7 +154,7 @@ namespace ApiWithoutSecrets { const QueueParameters GetGraphicsQueue() const; const QueueParameters GetPresentQueue() const; - const SwapChainParameters GetSwapChain() const; + const SwapChainParameters& GetSwapChain() const; private: OS::LibraryHandle VulkanLibrary; diff --git a/Project/Tutorials/01/Tutorial01.cpp b/Project/Tutorials/01/Tutorial01.cpp index 85ebee5..ebace68 100644 --- a/Project/Tutorials/01/Tutorial01.cpp +++ b/Project/Tutorials/01/Tutorial01.cpp @@ -155,7 +155,7 @@ namespace ApiWithoutSecrets { } std::vector physical_devices( num_devices ); - if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { + if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, physical_devices.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -181,7 +181,7 @@ namespace ApiWithoutSecrets { 0, // VkDeviceQueueCreateFlags flags selected_queue_family_index, // uint32_t queueFamilyIndex static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + queue_priorities.data() // const float *pQueuePriorities }; VkDeviceCreateInfo device_create_info = { @@ -231,7 +231,7 @@ namespace ApiWithoutSecrets { } std::vector queue_family_properties( queue_families_count ); - vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] ); + vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, queue_family_properties.data() ); for( uint32_t i = 0; i < queue_families_count; ++i ) { if( (queue_family_properties[i].queueCount > 0) && (queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) ) { diff --git a/Project/Tutorials/02/Tutorial02.cpp b/Project/Tutorials/02/Tutorial02.cpp index 25f4a34..b0fde14 100644 --- a/Project/Tutorials/02/Tutorial02.cpp +++ b/Project/Tutorials/02/Tutorial02.cpp @@ -114,7 +114,7 @@ namespace ApiWithoutSecrets { } std::vector available_extensions( extensions_count ); - if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { + if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, available_extensions.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } @@ -155,7 +155,7 @@ namespace ApiWithoutSecrets { 0, // uint32_t enabledLayerCount nullptr, // const char * const *ppEnabledLayerNames static_cast(extensions.size()), // uint32_t enabledExtensionCount - &extensions[0] // const char * const *ppEnabledExtensionNames + extensions.data() // const char * const *ppEnabledExtensionNames }; if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) { @@ -240,7 +240,7 @@ namespace ApiWithoutSecrets { } std::vector physical_devices( num_devices ); - if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { + if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, physical_devices.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -268,7 +268,7 @@ namespace ApiWithoutSecrets { 0, // VkDeviceQueueCreateFlags flags selected_graphics_queue_family_index, // uint32_t queueFamilyIndex static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + queue_priorities.data() // const float *pQueuePriorities } ); if( selected_graphics_queue_family_index != selected_present_queue_family_index ) { @@ -278,7 +278,7 @@ namespace ApiWithoutSecrets { 0, // VkDeviceQueueCreateFlags flags selected_present_queue_family_index, // uint32_t queueFamilyIndex static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + queue_priorities.data() // const float *pQueuePriorities } ); } @@ -291,11 +291,11 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkDeviceCreateFlags flags static_cast(queue_create_infos.size()), // uint32_t queueCreateInfoCount - &queue_create_infos[0], // const VkDeviceQueueCreateInfo *pQueueCreateInfos + queue_create_infos.data(), // const VkDeviceQueueCreateInfo *pQueueCreateInfos 0, // uint32_t enabledLayerCount nullptr, // const char * const *ppEnabledLayerNames static_cast(extensions.size()), // uint32_t enabledExtensionCount - &extensions[0], // const char * const *ppEnabledExtensionNames + extensions.data(), // const char * const *ppEnabledExtensionNames nullptr // const VkPhysicalDeviceFeatures *pEnabledFeatures }; @@ -318,7 +318,7 @@ namespace ApiWithoutSecrets { } std::vector available_extensions( extensions_count ); - if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { + if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, available_extensions.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } @@ -358,7 +358,7 @@ namespace ApiWithoutSecrets { std::vector queue_family_properties( queue_families_count ); std::vector queue_present_support( queue_families_count ); - vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, &queue_family_properties[0] ); + vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, queue_family_properties.data() ); uint32_t graphics_queue_family_index = UINT32_MAX; uint32_t present_queue_family_index = UINT32_MAX; @@ -457,7 +457,7 @@ namespace ApiWithoutSecrets { } std::vector surface_formats( formats_count ); - if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, &surface_formats[0] ) != VK_SUCCESS ) { + if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, surface_formats.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } @@ -470,7 +470,7 @@ namespace ApiWithoutSecrets { } std::vector present_modes( present_modes_count ); - if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, &present_modes[0] ) != VK_SUCCESS ) { + if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, present_modes.data() ) != VK_SUCCESS ) { std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } @@ -677,7 +677,7 @@ namespace ApiWithoutSecrets { VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level image_count // uint32_t bufferCount }; - if( vkAllocateCommandBuffers( Vulkan.Device, &cmd_buffer_allocate_info, &Vulkan.PresentQueueCmdBuffers[0] ) != VK_SUCCESS ) { + if( vkAllocateCommandBuffers( Vulkan.Device, &cmd_buffer_allocate_info, Vulkan.PresentQueueCmdBuffers.data() ) != VK_SUCCESS ) { std::cout << "Could not allocate command buffers!" << std::endl; return false; } @@ -693,7 +693,7 @@ namespace ApiWithoutSecrets { uint32_t image_count = static_cast(Vulkan.PresentQueueCmdBuffers.size()); std::vector swap_chain_images( image_count ); - if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain, &image_count, &swap_chain_images[0] ) != VK_SUCCESS ) { + if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain, &image_count, swap_chain_images.data() ) != VK_SUCCESS ) { std::cout << "Could not get swap chain images!" << std::endl; return false; } @@ -764,7 +764,7 @@ namespace ApiWithoutSecrets { vkDeviceWaitIdle( Vulkan.Device ); if( (Vulkan.PresentQueueCmdBuffers.size() > 0) && (Vulkan.PresentQueueCmdBuffers[0] != VK_NULL_HANDLE) ) { - vkFreeCommandBuffers( Vulkan.Device, Vulkan.PresentQueueCmdPool, static_cast(Vulkan.PresentQueueCmdBuffers.size()), &Vulkan.PresentQueueCmdBuffers[0] ); + vkFreeCommandBuffers( Vulkan.Device, Vulkan.PresentQueueCmdPool, static_cast(Vulkan.PresentQueueCmdBuffers.size()), Vulkan.PresentQueueCmdBuffers.data() ); Vulkan.PresentQueueCmdBuffers.clear(); } diff --git a/Project/Tutorials/03/Tutorial03.cpp b/Project/Tutorials/03/Tutorial03.cpp index 70daf4b..12e3b69 100644 --- a/Project/Tutorials/03/Tutorial03.cpp +++ b/Project/Tutorials/03/Tutorial03.cpp @@ -115,7 +115,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkShaderModuleCreateFlags flags code.size(), // size_t codeSize - reinterpret_cast(&code[0]) // const uint32_t *pCode + reinterpret_cast(code.data()) // const uint32_t *pCode }; VkShaderModule shader_module; @@ -287,7 +287,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineCreateFlags flags static_cast(shader_stage_create_infos.size()), // uint32_t stageCount - &shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages + shader_stage_create_infos.data(), // const VkPipelineShaderStageCreateInfo *pStages &vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState; &input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState @@ -336,7 +336,7 @@ namespace ApiWithoutSecrets { uint32_t image_count = static_cast(GetSwapChain().Images.size()); Vulkan.GraphicsCommandBuffers.resize( image_count, VK_NULL_HANDLE ); - if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, image_count, &Vulkan.GraphicsCommandBuffers[0] ) ) { + if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, image_count, Vulkan.GraphicsCommandBuffers.data() ) ) { std::cout << "Could not allocate command buffers!" << std::endl; return false; } @@ -547,7 +547,7 @@ namespace ApiWithoutSecrets { vkDeviceWaitIdle( GetDevice() ); if( (Vulkan.GraphicsCommandBuffers.size() > 0) && (Vulkan.GraphicsCommandBuffers[0] != VK_NULL_HANDLE) ) { - vkFreeCommandBuffers( GetDevice(), Vulkan.GraphicsCommandPool, static_cast(Vulkan.GraphicsCommandBuffers.size()), &Vulkan.GraphicsCommandBuffers[0] ); + vkFreeCommandBuffers( GetDevice(), Vulkan.GraphicsCommandPool, static_cast(Vulkan.GraphicsCommandBuffers.size()), Vulkan.GraphicsCommandBuffers.data() ); Vulkan.GraphicsCommandBuffers.clear(); } diff --git a/Project/Tutorials/04/Tutorial04.cpp b/Project/Tutorials/04/Tutorial04.cpp index 53a0db6..17e9d8a 100644 --- a/Project/Tutorials/04/Tutorial04.cpp +++ b/Project/Tutorials/04/Tutorial04.cpp @@ -90,7 +90,7 @@ namespace ApiWithoutSecrets { 1, // uint32_t subpassCount subpass_descriptions, // const VkSubpassDescription *pSubpasses static_cast(dependencies.size()), // uint32_t dependencyCount - &dependencies[0] // const VkSubpassDependency *pDependencies + dependencies.data() // const VkSubpassDependency *pDependencies }; if( vkCreateRenderPass( GetDevice(), &render_pass_create_info, nullptr, &Vulkan.RenderPass ) != VK_SUCCESS ) { @@ -112,7 +112,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkShaderModuleCreateFlags flags code.size(), // size_t codeSize - reinterpret_cast(&code[0]) // const uint32_t *pCode + reinterpret_cast(code.data()) // const uint32_t *pCode }; VkShaderModule shader_module; @@ -203,9 +203,9 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineVertexInputStateCreateFlags flags static_cast(vertex_binding_descriptions.size()), // uint32_t vertexBindingDescriptionCount - &vertex_binding_descriptions[0], // const VkVertexInputBindingDescription *pVertexBindingDescriptions + vertex_binding_descriptions.data(), // const VkVertexInputBindingDescription *pVertexBindingDescriptions static_cast(vertex_attribute_descriptions.size()), // uint32_t vertexAttributeDescriptionCount - &vertex_attribute_descriptions[0] // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions + vertex_attribute_descriptions.data() // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions }; VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = { @@ -287,7 +287,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineDynamicStateCreateFlags flags static_cast(dynamic_states.size()), // uint32_t dynamicStateCount - &dynamic_states[0] // const VkDynamicState *pDynamicStates + dynamic_states.data() // const VkDynamicState *pDynamicStates }; Tools::AutoDeleter pipeline_layout = CreatePipelineLayout(); @@ -300,7 +300,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineCreateFlags flags static_cast(shader_stage_create_infos.size()), // uint32_t stageCount - &shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages + shader_stage_create_infos.data(), // const VkPipelineShaderStageCreateInfo *pStages &vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState; &input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState diff --git a/Project/Tutorials/05/Tutorial05.cpp b/Project/Tutorials/05/Tutorial05.cpp index 5c1f6e6..4a3efe1 100644 --- a/Project/Tutorials/05/Tutorial05.cpp +++ b/Project/Tutorials/05/Tutorial05.cpp @@ -174,7 +174,7 @@ namespace ApiWithoutSecrets { 1, // uint32_t subpassCount subpass_descriptions, // const VkSubpassDescription *pSubpasses static_cast(dependencies.size()), // uint32_t dependencyCount - &dependencies[0] // const VkSubpassDependency *pDependencies + dependencies.data() // const VkSubpassDependency *pDependencies }; if( vkCreateRenderPass( GetDevice(), &render_pass_create_info, nullptr, &Vulkan.RenderPass ) != VK_SUCCESS ) { @@ -196,7 +196,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkShaderModuleCreateFlags flags code.size(), // size_t codeSize - reinterpret_cast(&code[0]) // const uint32_t *pCode + reinterpret_cast(code.data()) // const uint32_t *pCode }; VkShaderModule shader_module; @@ -287,9 +287,9 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineVertexInputStateCreateFlags flags static_cast(vertex_binding_descriptions.size()), // uint32_t vertexBindingDescriptionCount - &vertex_binding_descriptions[0], // const VkVertexInputBindingDescription *pVertexBindingDescriptions + vertex_binding_descriptions.data(), // const VkVertexInputBindingDescription *pVertexBindingDescriptions static_cast(vertex_attribute_descriptions.size()), // uint32_t vertexAttributeDescriptionCount - &vertex_attribute_descriptions[0] // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions + vertex_attribute_descriptions.data() // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions }; VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = { @@ -371,7 +371,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineDynamicStateCreateFlags flags static_cast(dynamic_states.size()), // uint32_t dynamicStateCount - &dynamic_states[0] // const VkDynamicState *pDynamicStates + dynamic_states.data() // const VkDynamicState *pDynamicStates }; Tools::AutoDeleter pipeline_layout = CreatePipelineLayout(); @@ -384,7 +384,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineCreateFlags flags static_cast(shader_stage_create_infos.size()), // uint32_t stageCount - &shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages + shader_stage_create_infos.data(), // const VkPipelineShaderStageCreateInfo *pStages &vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState; &input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState @@ -514,7 +514,7 @@ namespace ApiWithoutSecrets { return false; } - memcpy( staging_buffer_memory_pointer, &vertex_data[0], Vulkan.VertexBuffer.Size ); + memcpy( staging_buffer_memory_pointer, vertex_data.data(), Vulkan.VertexBuffer.Size ); VkMappedMemoryRange flush_range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType diff --git a/Project/Tutorials/06/Tutorial06.cpp b/Project/Tutorials/06/Tutorial06.cpp index 2509499..5c58999 100644 --- a/Project/Tutorials/06/Tutorial06.cpp +++ b/Project/Tutorials/06/Tutorial06.cpp @@ -210,7 +210,7 @@ namespace ApiWithoutSecrets { return false; } - if( !CopyTextureData( &texture_data[0], data_size, width, height ) ) { + if( !CopyTextureData( texture_data.data(), data_size, width, height ) ) { std::cout << "Could not upload texture data to device memory!" << std::endl; return false; } @@ -753,7 +753,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineCreateFlags flags static_cast(shader_stage_create_infos.size()), // uint32_t stageCount - &shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages + shader_stage_create_infos.data(), // const VkPipelineShaderStageCreateInfo *pStages &vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState; &input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState @@ -788,7 +788,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkShaderModuleCreateFlags flags code.size(), // size_t codeSize - reinterpret_cast(&code[0]) // const uint32_t *pCode + reinterpret_cast(code.data()) // const uint32_t *pCode }; VkShaderModule shader_module; @@ -844,7 +844,7 @@ namespace ApiWithoutSecrets { return false; } - memcpy( staging_buffer_memory_pointer, &vertex_data[0], Vulkan.VertexBuffer.Size ); + memcpy( staging_buffer_memory_pointer, vertex_data.data(), Vulkan.VertexBuffer.Size ); VkMappedMemoryRange flush_range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType diff --git a/Project/Tutorials/07/Tutorial07.cpp b/Project/Tutorials/07/Tutorial07.cpp index 2c6cfe0..71d59d3 100644 --- a/Project/Tutorials/07/Tutorial07.cpp +++ b/Project/Tutorials/07/Tutorial07.cpp @@ -210,7 +210,7 @@ namespace ApiWithoutSecrets { return false; } - if( !CopyTextureData( &texture_data[0], data_size, width, height ) ) { + if( !CopyTextureData( texture_data.data(), data_size, width, height ) ) { std::cout << "Could not upload texture data to device memory!" << std::endl; return false; } @@ -658,7 +658,7 @@ namespace ApiWithoutSecrets { } }; - vkUpdateDescriptorSets( GetDevice(), static_cast(descriptor_writes.size()), &descriptor_writes[0], 0, nullptr ); + vkUpdateDescriptorSets( GetDevice(), static_cast(descriptor_writes.size()), descriptor_writes.data(), 0, nullptr ); return true; } @@ -886,7 +886,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkPipelineCreateFlags flags static_cast(shader_stage_create_infos.size()), // uint32_t stageCount - &shader_stage_create_infos[0], // const VkPipelineShaderStageCreateInfo *pStages + shader_stage_create_infos.data(), // const VkPipelineShaderStageCreateInfo *pStages &vertex_input_state_create_info, // const VkPipelineVertexInputStateCreateInfo *pVertexInputState; &input_assembly_state_create_info, // const VkPipelineInputAssemblyStateCreateInfo *pInputAssemblyState nullptr, // const VkPipelineTessellationStateCreateInfo *pTessellationState @@ -921,7 +921,7 @@ namespace ApiWithoutSecrets { nullptr, // const void *pNext 0, // VkShaderModuleCreateFlags flags code.size(), // size_t codeSize - reinterpret_cast(&code[0]) // const uint32_t *pCode + reinterpret_cast(code.data()) // const uint32_t *pCode }; VkShaderModule shader_module; @@ -977,7 +977,7 @@ namespace ApiWithoutSecrets { return false; } - memcpy( staging_buffer_memory_pointer, &vertex_data[0], Vulkan.VertexBuffer.Size ); + memcpy( staging_buffer_memory_pointer, vertex_data.data(), Vulkan.VertexBuffer.Size ); VkMappedMemoryRange flush_range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType