308 std::array<VertexBuffer, NUM_GFX>
_arrVB;
313 _bFrameBufferResize{ false }
315 _allValidationLayer =
317 "VK_LAYER_KHRONOS_validation"
319 _allDeviceExtension =
321 VK_KHR_SWAPCHAIN_EXTENSION_NAME
334 void Update(std::vector<DrawCall>& list_dc, std::vector<DrawCall>& list_dc_translucent);
340 const std::vector<DrawCall>& list_dc,
const std::vector<DrawCall>& list_dc_translucent);
349 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
350 VkDebugUtilsMessageTypeFlagsEXT messageType,
351 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
354 if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
356 else if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
363 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
364 const VkAllocationCallbacks* pAllocator,
365 VkDebugUtilsMessengerEXT* pDebugMessenger)
367 auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,
"vkCreateDebugUtilsMessengerEXT");
369 return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
371 return VK_ERROR_EXTENSION_NOT_PRESENT;
375 VkDebugUtilsMessengerEXT debugMessenger,
376 const VkAllocationCallbacks* pAllocator)
378 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,
"vkDestroyDebugUtilsMessengerEXT");
380 func(instance, debugMessenger, pAllocator);
392 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
393 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
397 void CopyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
406 const std::array<VkBuffer, NUM_MIPMAP_2D>& vec_buffer,
407 VkImage image,
const std::array<Size, NUM_MIPMAP_2D>& vec_size);
412 template <
typename T>
414 VkBuffer& vertexBuffer,
415 VkDeviceMemory& vertexBufferMemory)
417 VkDeviceSize bufferSize =
sizeof(
T) * vertices.size();
419 VkBuffer stagingBuffer;
420 VkDeviceMemory stagingBufferMemory;
421 CreateBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
422 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
423 stagingBuffer, stagingBufferMemory);
426 vkMapMemory(_device, stagingBufferMemory, 0, bufferSize, 0, &data);
427 memcpy(data, vertices.data(), (
size_t)bufferSize);
428 vkUnmapMemory(_device, stagingBufferMemory);
431 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
432 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
433 vertexBuffer, vertexBufferMemory);
435 CopyBuffer(stagingBuffer, vertexBuffer, bufferSize);
437 vkDestroyBuffer(_device, stagingBuffer,
nullptr);
438 vkFreeMemory(_device, stagingBufferMemory,
nullptr);
443 template <
typename T>
445 VkBuffer& vertexBuffer, VkDeviceMemory& vertexBufferMemory, VkDeviceSize& bufferSize)
447 bufferSize =
sizeof(
T) * vertex_num;
448 CreateBuffer(bufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
449 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
450 vertexBuffer, vertexBufferMemory);
465 void CreateIndexBuffer(
const std::vector<T>& indices, VkBuffer& indexBuffer, VkDeviceMemory& indexBufferMemory)
467 VkDeviceSize bufferSize =
sizeof(
T) * indices.size();
469 VkBuffer stagingBuffer;
470 VkDeviceMemory stagingBufferMemory;
471 CreateBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
472 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
473 stagingBuffer, stagingBufferMemory);
476 vkMapMemory(_device, stagingBufferMemory, 0, bufferSize, 0, &data);
477 memcpy(data, indices.data(), (
size_t)bufferSize);
478 vkUnmapMemory(_device, stagingBufferMemory);
481 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
482 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
483 indexBuffer, indexBufferMemory);
485 CopyBuffer(stagingBuffer, indexBuffer, bufferSize);
487 vkDestroyBuffer(_device, stagingBuffer,
nullptr);
488 vkFreeMemory(_device, stagingBufferMemory,
nullptr);
493 void CreateImage(uint32_t w, uint32_t h, uint32_t mip_level, VkSampleCountFlagBits numSamples,
494 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties,
495 VkImage& image, VkDeviceMemory& imageMemory);
501 VkImageAspectFlags aspectFlags, uint32_t mip_level);
515 VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mip_level);
520 VkImageTiling tiling, VkFormatFeatureFlags features);
527 return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT;
535 for (
size_t i = 0; i < _allMaterial.size(); ++i)
537 if (_allMaterial[i] == m)
540 size_t id = _allMaterial.size();
542 vkMapMemory(_device, _ubMaterialMemory[
id], 0,
sizeof(m), 0, &data);
543 memcpy(data, &m,
sizeof(m));
544 vkUnmapMemory(_device, _ubMaterialMemory[
id]);
546 _allMaterial.push_back(m);
561 vkDestroyBuffer(_device, model->_indexBuffer,
nullptr);
562 vkFreeMemory(_device, model->_indexBufferMemory,
nullptr);
564 vkDestroyBuffer(_device, model->_vertexBuffer,
nullptr);
565 vkFreeMemory(_device, model->_vertexBufferMemory,
nullptr);
567 delete model->_modelData;
573 return _curPushConstant++;
578 if (
id >= _allPushConstant.size())
580 log(fmt::format(
"超过 推送常量区上限:{}", _allPushConstant.size()));
583 return &_allPushConstant[id];
591 size_t size =
sizeof(
Matrix4) * trans.size();
595 vkMapMemory(_device, _ubBoneMemory[index], 0, size, 0, &data);
596 memcpy(data, trans.data(), size);
597 vkUnmapMemory(_device, _ubBoneMemory[index]);
603 for (
size_t i = 0; i < _mapBoneUse.size(); ++i)
614 assert(_mapBoneUse[
id]);
615 _mapBoneUse[id] =
false;
620 assert(!_mapBoneUse[
id]);
621 _mapBoneUse[id] =
true;
637 void CreateCanvas(
size_t id,
const std::array<Image*, NUM_MIPMAP_2D>& vec_image);
641 if (
id >= _2d._allCanvas.size())
643 return _2d._allCanvas[id];
648 return _2d._allCanvas.size();
662 uint32_t width = _extentSwapChain.width;
663 uint32_t height = _extentSwapChain.height;
664 bool support_blit =
true;
667 VkFormatProperties format_props;
669 vkGetPhysicalDeviceFormatProperties(_physicalDevice, _formatSwapChainImage, &format_props);
670 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
672 log(
"不支持blit,将使用copy替代!");
673 support_blit =
false;
677 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
678 if (!(format_props.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
680 log(
"不支持blit到线性布局image,将使用copy替代!");
681 support_blit =
false;
685 VkImage src_image = _allImageSwapChain[_currentFrame];
688 VkImageCreateInfo create_info{};
689 create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
690 create_info.imageType = VK_IMAGE_TYPE_2D;
691 create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
692 create_info.extent.width = width;
693 create_info.extent.height = height;
694 create_info.extent.depth = 1;
695 create_info.arrayLayers = 1;
696 create_info.mipLevels = 1;
697 create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
698 create_info.samples = VK_SAMPLE_COUNT_1_BIT;
699 create_info.tiling = VK_IMAGE_TILING_LINEAR;
700 create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
703 if (vkCreateImage(_device, &create_info,
nullptr, &dst_image) != VK_SUCCESS)
709 VkMemoryRequirements memRequirements;
710 VkMemoryAllocateInfo memAllocInfo{};
711 VkDeviceMemory dstImageMemory;
712 vkGetImageMemoryRequirements(_device, dst_image, &memRequirements);
713 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
714 memAllocInfo.allocationSize = memRequirements.size;
716 memAllocInfo.memoryTypeIndex =
FindMemoryType(memRequirements.memoryTypeBits,
717 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
718 if (vkAllocateMemory(_device, &memAllocInfo,
nullptr, &dstImageMemory) != VK_SUCCESS)
723 if (vkBindImageMemory(_device, dst_image, dstImageMemory, 0) != VK_SUCCESS)
731 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1);
735 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1);
745 VkImageBlit imageBlitRegion{};
746 imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
747 imageBlitRegion.srcSubresource.layerCount = 1;
748 imageBlitRegion.srcOffsets[1] = blitSize;
749 imageBlitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
750 imageBlitRegion.dstSubresource.layerCount = 1;
751 imageBlitRegion.dstOffsets[1] = blitSize;
755 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
756 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
763 VkImageCopy imageCopyRegion{};
764 imageCopyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
765 imageCopyRegion.srcSubresource.layerCount = 1;
766 imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
767 imageCopyRegion.dstSubresource.layerCount = 1;
768 imageCopyRegion.extent.width = width;
769 imageCopyRegion.extent.height = height;
770 imageCopyRegion.extent.depth = 1;
774 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
775 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
783 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 1);
787 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, 1);
791 VkImageSubresource sub_res{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
792 VkSubresourceLayout sub_res_layout;
793 vkGetImageSubresourceLayout(_device, dst_image, &sub_res, &sub_res_layout);
797 vkMapMemory(_device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (
void**)&data);
798 data += sub_res_layout.offset;
801 bool color_bgr =
false;
804 std::vector<VkFormat> formatsBGR = { VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SNORM };
805 color_bgr = (std::find(formatsBGR.begin(), formatsBGR.end(), _formatSwapChainImage) != formatsBGR.end());
808 uint32_t* p = image->
GetData();
810 for (uint32_t y = 0; y < height; y++)
812 uint32_t* row = (uint32_t*)data;
813 for (uint32_t x = 0; x < width; x++)
818 *p = 0xff000000 | (abgr << 8 >> 8);
827 data += sub_res_layout.rowPitch;
833 vkUnmapMemory(_device, dstImageMemory);
834 vkFreeMemory(_device, dstImageMemory,
nullptr);
835 vkDestroyImage(_device, dst_image,
nullptr);
841 uint32_t width = tex.
_width;
843 bool support_blit =
true;
846 VkFormatProperties format_props;
848 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
849 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
851 log(
"不支持blit,将使用copy替代!");
852 support_blit =
false;
856 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
857 if (!(format_props.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
859 log(
"不支持blit到线性布局image,将使用copy替代!");
860 support_blit =
false;
864 VkImageCreateInfo create_info{};
865 create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
866 create_info.imageType = VK_IMAGE_TYPE_2D;
867 create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
868 create_info.extent.width = width;
869 create_info.extent.height = height;
870 create_info.extent.depth = 1;
871 create_info.arrayLayers = 1;
872 create_info.mipLevels = 1;
873 create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
874 create_info.samples = VK_SAMPLE_COUNT_1_BIT;
875 create_info.tiling = VK_IMAGE_TILING_LINEAR;
876 create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
879 if (vkCreateImage(_device, &create_info,
nullptr, &dst_image) != VK_SUCCESS)
885 VkMemoryRequirements memRequirements;
886 VkMemoryAllocateInfo memAllocInfo{};
887 VkDeviceMemory dstImageMemory;
888 vkGetImageMemoryRequirements(_device, dst_image, &memRequirements);
889 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
890 memAllocInfo.allocationSize = memRequirements.size;
892 memAllocInfo.memoryTypeIndex =
FindMemoryType(memRequirements.memoryTypeBits,
893 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
894 if (vkAllocateMemory(_device, &memAllocInfo,
nullptr, &dstImageMemory) != VK_SUCCESS)
899 if (vkBindImageMemory(_device, dst_image, dstImageMemory, 0) != VK_SUCCESS)
909 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1);
913 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1);
923 VkImageBlit imageBlitRegion{};
924 imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
925 imageBlitRegion.srcSubresource.layerCount = 1;
926 imageBlitRegion.srcOffsets[1] = blitSize;
927 imageBlitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
928 imageBlitRegion.dstSubresource.layerCount = 1;
929 imageBlitRegion.dstOffsets[1] = blitSize;
933 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
934 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
941 VkImageCopy imageCopyRegion{};
942 imageCopyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
943 imageCopyRegion.srcSubresource.layerCount = 1;
944 imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
945 imageCopyRegion.dstSubresource.layerCount = 1;
946 imageCopyRegion.extent.width = width;
947 imageCopyRegion.extent.height = height;
948 imageCopyRegion.extent.depth = 1;
952 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
953 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
961 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 1);
965 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1);
969 VkImageSubresource sub_res{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
970 VkSubresourceLayout sub_res_layout;
971 vkGetImageSubresourceLayout(_device, dst_image, &sub_res, &sub_res_layout);
975 vkMapMemory(_device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (
void**)&data);
976 data += sub_res_layout.offset;
979 uint32_t* p = image->
GetData();
981 for (uint32_t y = 0; y < height; y++)
983 uint32_t* row = (uint32_t*)data;
984 for (uint32_t x = 0; x < width; x++)
990 data += sub_res_layout.rowPitch;
996 vkUnmapMemory(_device, dstImageMemory);
997 vkFreeMemory(_device, dstImageMemory,
nullptr);
998 vkDestroyImage(_device, dst_image,
nullptr);
1002 void GenerateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels);
1010 return _2d._renderInfo;
1027 vkDeviceWaitIdle(_device);
1028 _release_swap_chain();
1037 for (
auto& iter : _allMulModel)
1039 for (
Model* model : iter)
1045 vkDestroySampler(_device, _textureSampler,
nullptr);
1046 for (
auto& iter : _allTexture3D)
1048 iter.Delete(_device);
1053 vkDestroyBuffer(_device, _ubMaterial[i],
nullptr);
1054 vkFreeMemory(_device, _ubMaterialMemory[i],
nullptr);
1060 vkDestroyBuffer(_device, _uniformBuffers[i],
nullptr);
1061 vkFreeMemory(_device, _uniformBuffersMemory[i],
nullptr);
1063 vkDestroyDescriptorPool(_device, _descriptorPool,
nullptr);
1064 vkDestroyDescriptorSetLayout(_device, _descriptorSetLayout,
nullptr);
1068 vkDestroyBuffer(_device, _ubBone[i],
nullptr);
1069 vkFreeMemory(_device, _ubBoneMemory[i],
nullptr);
1071 vkDestroyDescriptorPool(_device, _descriptorPoolBone,
nullptr);
1072 vkDestroyDescriptorSetLayout(_device, _descriptorSetLayoutBone,
nullptr);
1076 vkDestroySemaphore(_device, _allSemaphoreImageAvailable[i],
nullptr);
1077 vkDestroySemaphore(_device, _allSemaphoreRenderFinished[i],
nullptr);
1078 vkDestroyFence(_device, _allFenceInFlight[i],
nullptr);
1081 vkDestroyCommandPool(_device, _commandPool,
nullptr);
1083 vkDestroyPipeline(_device, _graphicsPipeline,
nullptr);
1084 vkDestroyPipelineLayout(_device, _pipelineLayout,
nullptr);
1086 vkDestroyPipeline(_device, _graphicsPipelineBone,
nullptr);
1087 vkDestroyPipelineLayout(_device, _pipelineLayoutBone,
nullptr);
1089 vkDestroyRenderPass(_device, _renderPass,
nullptr);
1092 vkDestroySurfaceKHR(_instance, _surface,
nullptr);
1093 vkDestroyDevice(_device,
nullptr);
1098 vkDestroyInstance(_instance,
nullptr);
1101 VkInstance _instance;
1102 std::vector<VkExtensionProperties> _allExtension;
1103 std::vector<VkLayerProperties> _allLayer;
1104 std::vector<const char*> _allValidationLayer;
1105 VkPhysicalDevice _physicalDevice;
1106 std::vector<VkPhysicalDevice> _allPhysicalDevice;
1108 VkQueue _graphicsQueue;
1109 VkSurfaceKHR _surface;
1110 VkQueue _presentQueue;
1111 std::vector<const char*> _allDeviceExtension;
1112 VkSwapchainKHR _swapChain;
1113 std::vector<VkImage> _allImageSwapChain;
1114 VkFormat _formatSwapChainImage;
1115 VkExtent2D _extentSwapChain;
1116 std::vector<VkImageView> _allImageViewSwapChain;
1117 VkRenderPass _renderPass;
1118 VkPipelineLayout _pipelineLayout;
1119 VkPipelineLayout _pipelineLayoutBone;
1120 VkPipeline _graphicsPipeline;
1121 VkPipeline _graphicsPipelineBone;
1122 std::vector<VkFramebuffer> _allFrameBufferSwapChain;
1123 VkCommandPool _commandPool;
1124 std::vector<VkCommandBuffer> _allCommandBuffer;
1125 std::vector<VkSemaphore> _allSemaphoreImageAvailable;
1126 std::vector<VkSemaphore> _allSemaphoreRenderFinished;
1127 std::vector<VkFence> _allFenceInFlight;
1128 uint32_t _currentFrame;
1129 bool _bFrameBufferResize;
1130 VkDebugUtilsMessengerEXT _debugMessenger;
1131 VkDescriptorSetLayout _descriptorSetLayout;
1132 VkDescriptorSetLayout _descriptorSetLayoutBone;
1133 std::vector<VkBuffer> _uniformBuffers;
1134 std::vector<VkDeviceMemory> _uniformBuffersMemory;
1135 VkDescriptorPool _descriptorPool;
1136 VkDescriptorPool _descriptorPoolBone;
1137 std::vector<VkDescriptorSet> _descriptorSets;
1138 std::vector<VkDescriptorSet> _descriptorSetsBone;
1139 VkSampler _textureSampler;
1140 VkImage _depthImage;
1141 VkDeviceMemory _depthImageMemory;
1142 VkImageView _depthImageView;
1143 std::array<PushConstantData, NUM_MAX_ACTOR> _allPushConstant;
1144 size_t _curPushConstant;
1147 std::vector<Texture> _allTexture3D;
1148 std::unordered_map<std::string, size_t> _mapPath2Texture;
1149 std::vector<VkBuffer> _ubMaterial;
1150 std::vector<VkDeviceMemory> _ubMaterialMemory;
1151 std::vector<Material> _allMaterial;
1152 std::vector<VkBuffer> _ubBone;
1153 std::vector<VkDeviceMemory> _ubBoneMemory;
1154 std::vector<bool> _mapBoneUse;
1155 std::vector<Primitive> _allPrimitive;
1156 VkSampleCountFlagBits _msaaSamples;
1157 VkImage _colorImage;
1158 VkDeviceMemory _colorImageMemory;
1159 VkImageView _colorImageView;
1165 std::vector<std::vector<Model*>> _allMulModel;
1169 _curPushConstant = 0;
1171 _camera = &_cameraDefault;
1176 _create_debug_messenger();
1177 _create_surface(window);
1179 _create_physical_device();
1180 _create_logical_device();
1181 _create_swap_chain(window);
1182 _create_image_view();
1184 _create_render_pass();
1185 _create_descriptor_set_layout();
1186 _create_graphics_pipeline();
1188 _create_descriptor_set_layout_bone();
1189 _create_graphics_pipeline_bone();
1191 _create_command_pool();
1192 _create_color_resources();
1193 _create_depth_resources();
1194 _create_frame_buffer();
1196 _create_texture_sampler();
1200 _create_uniform_buffers();
1201 _create_descriptor_pool();
1202 _create_descriptor_sets();
1206 _create_descriptor_pool_bone();
1207 _create_descriptor_sets_bone();
1209 _create_command_buffer();
1210 _create_sync_objects();
1216 _mapPath2Texture[
""] = 0;
1219 ModelObjectMaterial m;
1220 m._material._diffuseAlbedo = { 1.0f, 1.0f, 1.0f ,1.0f };
1221 m._material._fresnelR0 = { 0.01f, 0.01f, 0.01f };
1222 m._material._roughness = 0.25f;
1223 m._materialName =
"默认材质";
1224 m._pathTexDiffuse =
"";
1225 m._pathTexNormal =
"";
1227 assert(id_mat == 0);
1233 void _check_extension();
1235 std::vector<const char*> _get_required_extensions();
1237 void _create_instance();
1239 void _check_layer();
1241 bool _check_validation_layer();
1244 void _create_debug_messenger()
1248 VkDebugUtilsMessengerCreateInfoEXT createInfo;
1252 nullptr, &_debugMessenger) != VK_SUCCESS)
1260 void _create_physical_device();
1263 bool _is_device_suitable(VkPhysicalDevice device);
1265 bool _check_device_extension(VkPhysicalDevice device);
1267 QueueFamilyIndices _find_queue_families(VkPhysicalDevice device);
1270 void _create_logical_device();
1273 void _create_surface(GLFWwindow* window);
1276 SwapChainSupportDetails _query_swap_chain_support(VkPhysicalDevice device);
1278 VkSurfaceFormatKHR _choose_swap_surface_format(
const std::vector<VkSurfaceFormatKHR>& availableFormats);
1280 VkPresentModeKHR _choose_swap_present_mode(
const std::vector<VkPresentModeKHR>& availablePresentModes);
1283 VkExtent2D _choose_swap_extent(
const VkSurfaceCapabilitiesKHR& capabilities,
1284 GLFWwindow* window);
1287 void _create_swap_chain(GLFWwindow* window);
1289 void _create_image_view();
1292 void _create_render_pass();
1294 void _create_graphics_pipeline();
1297 void _create_descriptor_set_layout_bone();
1298 void _create_graphics_pipeline_bone();
1299 void _create_descriptor_pool_bone();
1300 void _create_descriptor_sets_bone();
1301 void _create_ub_bone();
1304 void _create_frame_buffer();
1307 void _create_command_pool();
1309 void _create_command_buffer();
1312 void _create_sync_objects();
1315 void _record_command_buffer(VkCommandBuffer command_buffer, uint32_t index_image,
1316 const std::vector<DrawCall>& list_dc,
const std::vector<DrawCall>& list_dc_translucent);
1319 void _rebuild_swap_chain(GLFWwindow* window);
1321 void _release_swap_chain();
1325 void _create_descriptor_set_layout();
1328 void _create_uniform_buffers();
1331 void _update_uniform_buffer(uint32_t currentImage);
1334 void _create_descriptor_pool();
1337 void _create_descriptor_sets();
1340 void _create_texture_sampler();
1342 void _create_depth_resources();
1344 void _create_color_resources()
1346 VkFormat colorFormat = _formatSwapChainImage;
1348 CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _msaaSamples, colorFormat,
1349 VK_IMAGE_TILING_OPTIMAL,
1350 VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
1351 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, _colorImage, _colorImageMemory);
1352 _colorImageView =
CreateImageView(_colorImage, colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1);
1460 return _allMulModel[i];
1464 _allMulModel.push_back(vec);