修复 crash 的问题
This commit is contained in:
@@ -26,6 +26,7 @@ TextureLoading::TextureLoading()
|
|||||||
zoom = -2.5f;
|
zoom = -2.5f;
|
||||||
rotation = { 0.0f, 15.0f, 0.0f };
|
rotation = { 0.0f, 15.0f, 0.0f };
|
||||||
title = "Texture loading";
|
title = "Texture loading";
|
||||||
|
this_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureLoading::~TextureLoading()
|
TextureLoading::~TextureLoading()
|
||||||
@@ -50,6 +51,7 @@ TextureLoading::~TextureLoading()
|
|||||||
vertex_buffer.reset();
|
vertex_buffer.reset();
|
||||||
index_buffer.reset();
|
index_buffer.reset();
|
||||||
uniform_buffer_vs.reset();
|
uniform_buffer_vs.reset();
|
||||||
|
//stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable physical device features required for this example
|
// Enable physical device features required for this example
|
||||||
@@ -507,6 +509,7 @@ void TextureLoading::build_command_buffers()
|
|||||||
|
|
||||||
void TextureLoading::draw()
|
void TextureLoading::draw()
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
ApiVulkanSample::prepare_frame();
|
ApiVulkanSample::prepare_frame();
|
||||||
|
|
||||||
// Command buffer to be submitted to the queue
|
// Command buffer to be submitted to the queue
|
||||||
@@ -916,15 +919,51 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
|||||||
setup_descriptor_set_bg();
|
setup_descriptor_set_bg();
|
||||||
build_command_buffers();
|
build_command_buffers();
|
||||||
prepared = true;
|
prepared = true;
|
||||||
|
//start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void TextureLoading::updateTexture()
|
||||||
|
//{
|
||||||
|
// std::unique_lock<std::mutex> lock(mtx);
|
||||||
|
// std::cout << "Working in thread: " << std::this_thread::get_id() << std::endl;
|
||||||
|
// int width = 640;
|
||||||
|
// int height = 480;
|
||||||
|
// int rowStride;
|
||||||
|
// auto testImage = generateSimpleTestImage(width, height, &rowStride);
|
||||||
|
// size_t dataSize = testImage.size();
|
||||||
|
// processWithVulkan(testImage.data(), width, height, rowStride, dataSize, cam_text);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void TextureLoading::run() {
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
// while (running)
|
||||||
|
// {
|
||||||
|
// updateTexture();
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void TextureLoading::start() {
|
||||||
|
// running = true;
|
||||||
|
// // 启动线程执行 run 方法
|
||||||
|
// workerThread = std::thread(&TextureLoading::run, this);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void TextureLoading::stop() {
|
||||||
|
// running = false;
|
||||||
|
// if (workerThread.joinable()) {
|
||||||
|
// workerThread.join();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
void TextureLoading::render(float delta_time)
|
void TextureLoading::render(float delta_time)
|
||||||
{
|
{
|
||||||
if (!prepared)
|
if (!prepared)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -959,6 +998,7 @@ void TextureLoadProcessWithVulkan(uint8_t* data, int width, int height, int rowS
|
|||||||
|
|
||||||
void TextureLoading::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture)
|
void TextureLoading::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
VkDevice& device = get_device().get_handle();
|
VkDevice& device = get_device().get_handle();
|
||||||
const VkPhysicalDevice& physicalDevice = get_device().get_gpu().get_handle();
|
const VkPhysicalDevice& physicalDevice = get_device().get_gpu().get_handle();
|
||||||
if (out_texture.image == VK_NULL_HANDLE)
|
if (out_texture.image == VK_NULL_HANDLE)
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <ktx.h>
|
#include <ktx.h>
|
||||||
|
|
||||||
#include "api_vulkan_sample.h"
|
#include "api_vulkan_sample.h"
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
// Vertex layout for this example
|
// Vertex layout for this example
|
||||||
struct TextureLoadingVertexStructure
|
struct TextureLoadingVertexStructure
|
||||||
@@ -117,6 +119,16 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void prepare_pipeline_bg();
|
void prepare_pipeline_bg();
|
||||||
|
private:
|
||||||
|
std::thread workerThread;
|
||||||
|
bool running = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//void run();
|
||||||
|
//void start();
|
||||||
|
std::mutex mtx;
|
||||||
|
//void stop();
|
||||||
|
//void updateTexture();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<vkb::Application> create_texture_loading();
|
std::unique_ptr<vkb::Application> create_texture_loading();
|
||||||
|
|||||||
Reference in New Issue
Block a user