309 std::array<VertexBuffer, NUM_GFX>
_arrVB;
314 _bFrameBufferResize{ false }
316 _allValidationLayer =
318 "VK_LAYER_KHRONOS_validation"
320 _allDeviceExtension =
322 VK_KHR_SWAPCHAIN_EXTENSION_NAME
335 void Update(std::vector<DrawCall>& list_dc, std::vector<DrawCall>& list_dc_translucent);
341 const std::vector<DrawCall>& list_dc,
const std::vector<DrawCall>& list_dc_translucent);
350 VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
351 VkDebugUtilsMessageTypeFlagsEXT messageType,
352 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
355 if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
357 else if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
364 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
365 const VkAllocationCallbacks* pAllocator,
366 VkDebugUtilsMessengerEXT* pDebugMessenger)
368 auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,
"vkCreateDebugUtilsMessengerEXT");
370 return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
372 return VK_ERROR_EXTENSION_NOT_PRESENT;
376 VkDebugUtilsMessengerEXT debugMessenger,
377 const VkAllocationCallbacks* pAllocator)
379 auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance,
"vkDestroyDebugUtilsMessengerEXT");
381 func(instance, debugMessenger, pAllocator);
393 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
394 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
398 void CopyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
407 const std::array<VkBuffer, NUM_MIPMAP_2D>& vec_buffer,
408 VkImage image,
const std::array<Size, NUM_MIPMAP_2D>& vec_size);
413 template <
typename T>
415 VkBuffer& vertexBuffer,
416 VkDeviceMemory& vertexBufferMemory)
418 VkDeviceSize bufferSize =
sizeof(
T) * vertices.size();
420 VkBuffer stagingBuffer;
421 VkDeviceMemory stagingBufferMemory;
422 CreateBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
423 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
424 stagingBuffer, stagingBufferMemory);
427 vkMapMemory(_device, stagingBufferMemory, 0, bufferSize, 0, &data);
428 memcpy(data, vertices.data(), (
size_t)bufferSize);
429 vkUnmapMemory(_device, stagingBufferMemory);
432 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
433 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
434 vertexBuffer, vertexBufferMemory);
436 CopyBuffer(stagingBuffer, vertexBuffer, bufferSize);
438 vkDestroyBuffer(_device, stagingBuffer,
nullptr);
439 vkFreeMemory(_device, stagingBufferMemory,
nullptr);
444 template <
typename T>
446 VkBuffer& vertexBuffer, VkDeviceMemory& vertexBufferMemory, VkDeviceSize& bufferSize)
448 bufferSize =
sizeof(
T) * vertex_num;
449 CreateBuffer(bufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
450 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
451 vertexBuffer, vertexBufferMemory);
466 void CreateIndexBuffer(
const std::vector<T>& indices, VkBuffer& indexBuffer, VkDeviceMemory& indexBufferMemory)
468 VkDeviceSize bufferSize =
sizeof(
T) * indices.size();
470 VkBuffer stagingBuffer;
471 VkDeviceMemory stagingBufferMemory;
472 CreateBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
473 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
474 stagingBuffer, stagingBufferMemory);
477 vkMapMemory(_device, stagingBufferMemory, 0, bufferSize, 0, &data);
478 memcpy(data, indices.data(), (
size_t)bufferSize);
479 vkUnmapMemory(_device, stagingBufferMemory);
482 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
483 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
484 indexBuffer, indexBufferMemory);
486 CopyBuffer(stagingBuffer, indexBuffer, bufferSize);
488 vkDestroyBuffer(_device, stagingBuffer,
nullptr);
489 vkFreeMemory(_device, stagingBufferMemory,
nullptr);
494 void CreateImage(uint32_t w, uint32_t h, uint32_t mip_level, VkSampleCountFlagBits numSamples,
495 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties,
496 VkImage& image, VkDeviceMemory& imageMemory);
502 VkImageAspectFlags aspectFlags, uint32_t mip_level);
516 VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mip_level);
521 VkImageTiling tiling, VkFormatFeatureFlags features);
528 return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT;
536 for (
size_t i = 0; i < _allMaterial.size(); ++i)
538 if (_allMaterial[i] == m)
541 size_t id = _allMaterial.size();
543 vkMapMemory(_device, _ubMaterialMemory[
id], 0,
sizeof(m), 0, &data);
544 memcpy(data, &m,
sizeof(m));
545 vkUnmapMemory(_device, _ubMaterialMemory[
id]);
547 _allMaterial.push_back(m);
562 vkDestroyBuffer(_device, model->_indexBuffer,
nullptr);
563 vkFreeMemory(_device, model->_indexBufferMemory,
nullptr);
565 vkDestroyBuffer(_device, model->_vertexBuffer,
nullptr);
566 vkFreeMemory(_device, model->_vertexBufferMemory,
nullptr);
568 delete model->_modelData;
574 return _curPushConstant++;
579 if (
id >= _allPushConstant.size())
581 log(fmt::format(
"超过 推送常量区上限:{}", _allPushConstant.size()));
584 return &_allPushConstant[id];
592 size_t size =
sizeof(
Matrix4) * trans.size();
596 vkMapMemory(_device, _ubBoneMemory[index], 0, size, 0, &data);
597 memcpy(data, trans.data(), size);
598 vkUnmapMemory(_device, _ubBoneMemory[index]);
604 for (
size_t i = 0; i < _mapBoneUse.size(); ++i)
615 assert(_mapBoneUse[
id]);
616 _mapBoneUse[id] =
false;
621 assert(!_mapBoneUse[
id]);
622 _mapBoneUse[id] =
true;
638 void CreateCanvas(
size_t id,
const std::array<Image*, NUM_MIPMAP_2D>& vec_image);
642 if (
id >= _2d._allCanvas.size())
644 return _2d._allCanvas[id];
649 return _2d._allCanvas.size();
663 uint32_t width = _extentSwapChain.width;
664 uint32_t height = _extentSwapChain.height;
665 bool support_blit =
true;
668 VkFormatProperties format_props;
670 vkGetPhysicalDeviceFormatProperties(_physicalDevice, _formatSwapChainImage, &format_props);
671 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
673 log(
"不支持blit,将使用copy替代!");
674 support_blit =
false;
678 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
679 if (!(format_props.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
681 log(
"不支持blit到线性布局image,将使用copy替代!");
682 support_blit =
false;
686 VkImage src_image = _allImageSwapChain[_currentFrame];
689 VkImageCreateInfo create_info{};
690 create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
691 create_info.imageType = VK_IMAGE_TYPE_2D;
692 create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
693 create_info.extent.width = width;
694 create_info.extent.height = height;
695 create_info.extent.depth = 1;
696 create_info.arrayLayers = 1;
697 create_info.mipLevels = 1;
698 create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
699 create_info.samples = VK_SAMPLE_COUNT_1_BIT;
700 create_info.tiling = VK_IMAGE_TILING_LINEAR;
701 create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
704 if (vkCreateImage(_device, &create_info,
nullptr, &dst_image) != VK_SUCCESS)
710 VkMemoryRequirements memRequirements;
711 VkMemoryAllocateInfo memAllocInfo{};
712 VkDeviceMemory dstImageMemory;
713 vkGetImageMemoryRequirements(_device, dst_image, &memRequirements);
714 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
715 memAllocInfo.allocationSize = memRequirements.size;
717 memAllocInfo.memoryTypeIndex =
FindMemoryType(memRequirements.memoryTypeBits,
718 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
719 if (vkAllocateMemory(_device, &memAllocInfo,
nullptr, &dstImageMemory) != VK_SUCCESS)
724 if (vkBindImageMemory(_device, dst_image, dstImageMemory, 0) != VK_SUCCESS)
732 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1);
736 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1);
746 VkImageBlit imageBlitRegion{};
747 imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
748 imageBlitRegion.srcSubresource.layerCount = 1;
749 imageBlitRegion.srcOffsets[1] = blitSize;
750 imageBlitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
751 imageBlitRegion.dstSubresource.layerCount = 1;
752 imageBlitRegion.dstOffsets[1] = blitSize;
756 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
757 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
764 VkImageCopy imageCopyRegion{};
765 imageCopyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
766 imageCopyRegion.srcSubresource.layerCount = 1;
767 imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
768 imageCopyRegion.dstSubresource.layerCount = 1;
769 imageCopyRegion.extent.width = width;
770 imageCopyRegion.extent.height = height;
771 imageCopyRegion.extent.depth = 1;
775 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
776 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
784 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 1);
788 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, 1);
792 VkImageSubresource sub_res{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
793 VkSubresourceLayout sub_res_layout;
794 vkGetImageSubresourceLayout(_device, dst_image, &sub_res, &sub_res_layout);
798 vkMapMemory(_device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (
void**)&data);
799 data += sub_res_layout.offset;
802 bool color_bgr =
false;
805 std::vector<VkFormat> formatsBGR = { VK_FORMAT_B8G8R8A8_SRGB, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SNORM };
806 color_bgr = (std::find(formatsBGR.begin(), formatsBGR.end(), _formatSwapChainImage) != formatsBGR.end());
809 uint32_t* p = image->
GetData();
811 for (uint32_t y = 0; y < height; y++)
813 uint32_t* row = (uint32_t*)data;
814 for (uint32_t x = 0; x < width; x++)
819 *p = 0xff000000 | (abgr << 8 >> 8);
828 data += sub_res_layout.rowPitch;
834 vkUnmapMemory(_device, dstImageMemory);
835 vkFreeMemory(_device, dstImageMemory,
nullptr);
836 vkDestroyImage(_device, dst_image,
nullptr);
842 uint32_t width = tex.
_width;
844 bool support_blit =
true;
847 VkFormatProperties format_props;
849 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
850 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
852 log(
"不支持blit,将使用copy替代!");
853 support_blit =
false;
857 vkGetPhysicalDeviceFormatProperties(_physicalDevice, VK_FORMAT_R8G8B8A8_UNORM, &format_props);
858 if (!(format_props.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
860 log(
"不支持blit到线性布局image,将使用copy替代!");
861 support_blit =
false;
865 VkImageCreateInfo create_info{};
866 create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
867 create_info.imageType = VK_IMAGE_TYPE_2D;
868 create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
869 create_info.extent.width = width;
870 create_info.extent.height = height;
871 create_info.extent.depth = 1;
872 create_info.arrayLayers = 1;
873 create_info.mipLevels = 1;
874 create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
875 create_info.samples = VK_SAMPLE_COUNT_1_BIT;
876 create_info.tiling = VK_IMAGE_TILING_LINEAR;
877 create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
880 if (vkCreateImage(_device, &create_info,
nullptr, &dst_image) != VK_SUCCESS)
886 VkMemoryRequirements memRequirements;
887 VkMemoryAllocateInfo memAllocInfo{};
888 VkDeviceMemory dstImageMemory;
889 vkGetImageMemoryRequirements(_device, dst_image, &memRequirements);
890 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
891 memAllocInfo.allocationSize = memRequirements.size;
893 memAllocInfo.memoryTypeIndex =
FindMemoryType(memRequirements.memoryTypeBits,
894 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
895 if (vkAllocateMemory(_device, &memAllocInfo,
nullptr, &dstImageMemory) != VK_SUCCESS)
900 if (vkBindImageMemory(_device, dst_image, dstImageMemory, 0) != VK_SUCCESS)
910 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1);
914 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1);
924 VkImageBlit imageBlitRegion{};
925 imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
926 imageBlitRegion.srcSubresource.layerCount = 1;
927 imageBlitRegion.srcOffsets[1] = blitSize;
928 imageBlitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
929 imageBlitRegion.dstSubresource.layerCount = 1;
930 imageBlitRegion.dstOffsets[1] = blitSize;
934 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
935 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
942 VkImageCopy imageCopyRegion{};
943 imageCopyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
944 imageCopyRegion.srcSubresource.layerCount = 1;
945 imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
946 imageCopyRegion.dstSubresource.layerCount = 1;
947 imageCopyRegion.extent.width = width;
948 imageCopyRegion.extent.height = height;
949 imageCopyRegion.extent.depth = 1;
953 src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
954 dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
962 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 1);
966 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1);
970 VkImageSubresource sub_res{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
971 VkSubresourceLayout sub_res_layout;
972 vkGetImageSubresourceLayout(_device, dst_image, &sub_res, &sub_res_layout);
976 vkMapMemory(_device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (
void**)&data);
977 data += sub_res_layout.offset;
980 uint32_t* p = image->
GetData();
982 for (uint32_t y = 0; y < height; y++)
984 uint32_t* row = (uint32_t*)data;
985 for (uint32_t x = 0; x < width; x++)
991 data += sub_res_layout.rowPitch;
997 vkUnmapMemory(_device, dstImageMemory);
998 vkFreeMemory(_device, dstImageMemory,
nullptr);
999 vkDestroyImage(_device, dst_image,
nullptr);
1003 void GenerateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels);
1011 return _2d._renderInfo;
1028 vkDeviceWaitIdle(_device);
1029 _release_swap_chain();
1038 for (
auto& iter : _allMulModel)
1040 for (
Model* model : iter)
1046 vkDestroySampler(_device, _textureSampler,
nullptr);
1047 for (
auto& iter : _allTexture3D)
1049 iter.Delete(_device);
1054 vkDestroyBuffer(_device, _ubMaterial[i],
nullptr);
1055 vkFreeMemory(_device, _ubMaterialMemory[i],
nullptr);
1061 vkDestroyBuffer(_device, _uniformBuffers[i],
nullptr);
1062 vkFreeMemory(_device, _uniformBuffersMemory[i],
nullptr);
1064 vkDestroyDescriptorPool(_device, _descriptorPool,
nullptr);
1065 vkDestroyDescriptorSetLayout(_device, _descriptorSetLayout,
nullptr);
1069 vkDestroyBuffer(_device, _ubBone[i],
nullptr);
1070 vkFreeMemory(_device, _ubBoneMemory[i],
nullptr);
1072 vkDestroyDescriptorPool(_device, _descriptorPoolBone,
nullptr);
1073 vkDestroyDescriptorSetLayout(_device, _descriptorSetLayoutBone,
nullptr);
1077 vkDestroySemaphore(_device, _allSemaphoreImageAvailable[i],
nullptr);
1078 vkDestroySemaphore(_device, _allSemaphoreRenderFinished[i],
nullptr);
1079 vkDestroyFence(_device, _allFenceInFlight[i],
nullptr);
1082 vkDestroyCommandPool(_device, _commandPool,
nullptr);
1084 vkDestroyPipeline(_device, _graphicsPipeline,
nullptr);
1085 vkDestroyPipelineLayout(_device, _pipelineLayout,
nullptr);
1087 vkDestroyPipeline(_device, _graphicsPipelineBone,
nullptr);
1088 vkDestroyPipelineLayout(_device, _pipelineLayoutBone,
nullptr);
1090 vkDestroyRenderPass(_device, _renderPass,
nullptr);
1093 vkDestroySurfaceKHR(_instance, _surface,
nullptr);
1094 vkDestroyDevice(_device,
nullptr);
1099 vkDestroyInstance(_instance,
nullptr);
1102 VkInstance _instance;
1103 std::vector<VkExtensionProperties> _allExtension;
1104 std::vector<VkLayerProperties> _allLayer;
1105 std::vector<const char*> _allValidationLayer;
1106 VkPhysicalDevice _physicalDevice;
1107 std::vector<VkPhysicalDevice> _allPhysicalDevice;
1109 VkQueue _graphicsQueue;
1110 VkSurfaceKHR _surface;
1111 VkQueue _presentQueue;
1112 std::vector<const char*> _allDeviceExtension;
1113 VkSwapchainKHR _swapChain;
1114 std::vector<VkImage> _allImageSwapChain;
1115 VkFormat _formatSwapChainImage;
1116 VkExtent2D _extentSwapChain;
1117 std::vector<VkImageView> _allImageViewSwapChain;
1118 VkRenderPass _renderPass;
1119 VkPipelineLayout _pipelineLayout;
1120 VkPipelineLayout _pipelineLayoutBone;
1121 VkPipeline _graphicsPipeline;
1122 VkPipeline _graphicsPipelineBone;
1123 std::vector<VkFramebuffer> _allFrameBufferSwapChain;
1124 VkCommandPool _commandPool;
1125 std::vector<VkCommandBuffer> _allCommandBuffer;
1126 std::vector<VkSemaphore> _allSemaphoreImageAvailable;
1127 std::vector<VkSemaphore> _allSemaphoreRenderFinished;
1128 std::vector<VkFence> _allFenceInFlight;
1129 uint32_t _currentFrame;
1130 bool _bFrameBufferResize;
1131 VkDebugUtilsMessengerEXT _debugMessenger;
1132 VkDescriptorSetLayout _descriptorSetLayout;
1133 VkDescriptorSetLayout _descriptorSetLayoutBone;
1134 std::vector<VkBuffer> _uniformBuffers;
1135 std::vector<VkDeviceMemory> _uniformBuffersMemory;
1136 VkDescriptorPool _descriptorPool;
1137 VkDescriptorPool _descriptorPoolBone;
1138 std::vector<VkDescriptorSet> _descriptorSets;
1139 std::vector<VkDescriptorSet> _descriptorSetsBone;
1140 VkSampler _textureSampler;
1141 VkImage _depthImage;
1142 VkDeviceMemory _depthImageMemory;
1143 VkImageView _depthImageView;
1144 std::array<PushConstantData, NUM_MAX_ACTOR> _allPushConstant;
1145 size_t _curPushConstant;
1148 std::vector<Texture> _allTexture3D;
1149 std::unordered_map<std::string, size_t> _mapPath2Texture;
1150 std::vector<VkBuffer> _ubMaterial;
1151 std::vector<VkDeviceMemory> _ubMaterialMemory;
1152 std::vector<Material> _allMaterial;
1153 std::vector<VkBuffer> _ubBone;
1154 std::vector<VkDeviceMemory> _ubBoneMemory;
1155 std::vector<bool> _mapBoneUse;
1156 std::vector<Primitive> _allPrimitive;
1157 VkSampleCountFlagBits _msaaSamples;
1158 VkImage _colorImage;
1159 VkDeviceMemory _colorImageMemory;
1160 VkImageView _colorImageView;
1166 std::vector<std::vector<Model*>> _allMulModel;
1170 _curPushConstant = 0;
1172 _camera = &_cameraDefault;
1177 _create_debug_messenger();
1178 _create_surface(window);
1180 _create_physical_device();
1181 _create_logical_device();
1182 _create_swap_chain(window);
1183 _create_image_view();
1185 _create_render_pass();
1186 _create_descriptor_set_layout();
1187 _create_graphics_pipeline();
1189 _create_descriptor_set_layout_bone();
1190 _create_graphics_pipeline_bone();
1192 _create_command_pool();
1193 _create_color_resources();
1194 _create_depth_resources();
1195 _create_frame_buffer();
1197 _create_texture_sampler();
1201 _create_uniform_buffers();
1202 _create_descriptor_pool();
1203 _create_descriptor_sets();
1207 _create_descriptor_pool_bone();
1208 _create_descriptor_sets_bone();
1210 _create_command_buffer();
1211 _create_sync_objects();
1217 _mapPath2Texture[
""] = 0;
1220 ModelObjectMaterial m;
1221 m._material._diffuseAlbedo = { 1.0f, 1.0f, 1.0f ,1.0f };
1222 m._material._fresnelR0 = { 0.01f, 0.01f, 0.01f };
1223 m._material._roughness = 0.25f;
1224 m._materialName =
"默认材质";
1225 m._pathTexDiffuse =
"";
1226 m._pathTexNormal =
"";
1228 assert(id_mat == 0);
1234 void _check_extension();
1236 std::vector<const char*> _get_required_extensions();
1238 void _create_instance();
1240 void _check_layer();
1242 bool _check_validation_layer();
1245 void _create_debug_messenger()
1249 VkDebugUtilsMessengerCreateInfoEXT createInfo;
1253 nullptr, &_debugMessenger) != VK_SUCCESS)
1261 void _create_physical_device();
1264 bool _is_device_suitable(VkPhysicalDevice device);
1266 bool _check_device_extension(VkPhysicalDevice device);
1268 QueueFamilyIndices _find_queue_families(VkPhysicalDevice device);
1271 void _create_logical_device();
1274 void _create_surface(GLFWwindow* window);
1277 SwapChainSupportDetails _query_swap_chain_support(VkPhysicalDevice device);
1279 VkSurfaceFormatKHR _choose_swap_surface_format(
const std::vector<VkSurfaceFormatKHR>& availableFormats);
1281 VkPresentModeKHR _choose_swap_present_mode(
const std::vector<VkPresentModeKHR>& availablePresentModes);
1284 VkExtent2D _choose_swap_extent(
const VkSurfaceCapabilitiesKHR& capabilities,
1285 GLFWwindow* window);
1288 void _create_swap_chain(GLFWwindow* window);
1290 void _create_image_view();
1293 void _create_render_pass();
1295 void _create_graphics_pipeline();
1298 void _create_descriptor_set_layout_bone();
1299 void _create_graphics_pipeline_bone();
1300 void _create_descriptor_pool_bone();
1301 void _create_descriptor_sets_bone();
1302 void _create_ub_bone();
1305 void _create_frame_buffer();
1308 void _create_command_pool();
1310 void _create_command_buffer();
1313 void _create_sync_objects();
1316 void _record_command_buffer(VkCommandBuffer command_buffer, uint32_t index_image,
1317 const std::vector<DrawCall>& list_dc,
const std::vector<DrawCall>& list_dc_translucent);
1320 void _rebuild_swap_chain(GLFWwindow* window);
1322 void _release_swap_chain();
1326 void _create_descriptor_set_layout();
1329 void _create_uniform_buffers();
1332 void _update_uniform_buffer(uint32_t currentImage);
1335 void _create_descriptor_pool();
1338 void _create_descriptor_sets();
1341 void _create_texture_sampler();
1343 void _create_depth_resources();
1345 void _create_color_resources()
1347 VkFormat colorFormat = _formatSwapChainImage;
1349 CreateImage(_extentSwapChain.width, _extentSwapChain.height, 1, _msaaSamples, colorFormat,
1350 VK_IMAGE_TILING_OPTIMAL,
1351 VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
1352 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, _colorImage, _colorImageMemory);
1353 _colorImageView =
CreateImageView(_colorImage, colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1);
1461 return _allMulModel[i];
1465 _allMulModel.push_back(vec);