save code
This commit is contained in:
+19
-8
@@ -404,6 +404,17 @@ void Application::createCommandPool() {
|
||||
if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create command pool!");
|
||||
}
|
||||
|
||||
queueFamilyIndices = findQueueFamilies(physicalDevice, surface);
|
||||
|
||||
VkCommandPoolCreateInfo poolInfo_ex{};
|
||||
poolInfo_ex.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
poolInfo_ex.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value();
|
||||
poolInfo_ex.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // 添加标志
|
||||
|
||||
if (vkCreateCommandPool(device, &poolInfo_ex, nullptr, &commandPool_ex) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create command pool!");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::createCommandBuffer()
|
||||
@@ -641,30 +652,30 @@ uint32_t Application::findMemoryType(VkPhysicalDevice physicalDevice, uint32_t t
|
||||
throw std::runtime_error("Failed to find suitable memory type!");
|
||||
}
|
||||
|
||||
void Application::loadTexture(std::string path, Texture& tex, bool srgb)
|
||||
void Application::loadTexture(std::string path, Texture& tex, bool srgb, VkCommandPool pool)
|
||||
{
|
||||
std::vector<unsigned char> data = readFileUnsignedChar(path, false);
|
||||
std::vector<unsigned char> image;
|
||||
unsigned w, h;
|
||||
unsigned error = lodepng::decode(image, w, h, data, LCT_RGBA, 8);
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb);
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb, pool);
|
||||
//return tex;
|
||||
}
|
||||
|
||||
void Application::loadTexture(std::vector<unsigned char>& image_data, size_t image_size, int w, int h, Texture& tex, bool srgb)
|
||||
void Application::loadTexture(std::vector<unsigned char>& image_data, size_t image_size, int w, int h, Texture& tex, bool srgb, VkCommandPool pool)
|
||||
{
|
||||
processWithVulkan(image_data.data(), w, h, w * 4, image_size, tex, srgb);
|
||||
processWithVulkan(image_data.data(), w, h, w * 4, image_size, tex, srgb, pool);
|
||||
//return tex;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void Application::loadTextureExample(std::wstring path, Texture& tex, bool srgb)
|
||||
void Application::loadTextureExample(std::wstring path, Texture& tex, bool srgb, VkCommandPool pool)
|
||||
{
|
||||
std::vector<unsigned char> data = readFileUnsignedCharWin32(path, true);
|
||||
std::vector<unsigned char> image;
|
||||
unsigned w, h;
|
||||
unsigned error = lodepng::decode(image, w, h, data, LCT_RGBA, 8);
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb);
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb, pool);
|
||||
//return tex;
|
||||
}
|
||||
|
||||
@@ -772,7 +783,7 @@ void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice
|
||||
texture.device = device;
|
||||
}
|
||||
|
||||
void Application::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture, bool srgb)
|
||||
void Application::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture, bool srgb, VkCommandPool pool)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
if (out_texture.image == VK_NULL_HANDLE)
|
||||
@@ -781,7 +792,7 @@ void Application::processWithVulkan(uint8_t* data, int width, int height, int ro
|
||||
|
||||
}
|
||||
|
||||
updateTexture(device, physicalDevice, commandPool, graphicsQueue, data, width, height,
|
||||
updateTexture(device, physicalDevice, pool, graphicsQueue, data, width, height,
|
||||
rowStride, dataSize, out_texture);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user