save code
This commit is contained in:
+26
-17
@@ -53,23 +53,32 @@ void Application::createSurface() {
|
|||||||
|
|
||||||
void Application::initVulkan()
|
void Application::initVulkan()
|
||||||
{
|
{
|
||||||
initWindow();
|
if (!_applicationInited)
|
||||||
createInstance(); // 创建 Vulkan 实例
|
{
|
||||||
setupDebugMessenger(); // 在这里调用
|
initWindow();
|
||||||
createSurface(); // 创建窗口表面
|
createInstance(); // 创建 Vulkan 实例
|
||||||
pickPhysicalDevice(physicalDevice, surface); // 选择物理设备
|
setupDebugMessenger(); // 在这里调用
|
||||||
createLogicalDevice(); // 创建逻辑设备
|
createSurface(); // 创建窗口表面
|
||||||
createSwapChain(); // 创建交换链
|
pickPhysicalDevice(physicalDevice, surface); // 选择物理设备
|
||||||
createImageViews(); // 创建交换链图像视图
|
createLogicalDevice(); // 创建逻辑设备
|
||||||
createRenderPass(); // 创建渲染流程
|
createSwapChain(); // 创建交换链
|
||||||
createPipelineLayout(); // 在这里调用
|
createImageViews(); // 创建交换链图像视图
|
||||||
createGraphicsPipeline(); // 创建图形管线
|
createRenderPass(); // 创建渲染流程
|
||||||
createFramebuffers(); // 创建帧缓冲区
|
createPipelineLayout(); // 在这里调用
|
||||||
createCommandPool(); // 创建命令池
|
createGraphicsPipeline(); // 创建图形管线
|
||||||
createCommandBuffer(); // 创建命令缓冲区
|
createFramebuffers(); // 创建帧缓冲区
|
||||||
createSyncObjects(); // 创建同步对象
|
createCommandPool(); // 创建命令池
|
||||||
_lastDrawFrameTime = getCurrentTimeMillis();
|
createCommandBuffer(); // 创建命令缓冲区
|
||||||
inited = true;
|
createSyncObjects(); // 创建同步对象
|
||||||
|
_lastDrawFrameTime = getCurrentTimeMillis();
|
||||||
|
_applicationInited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_sceondInited) {
|
||||||
|
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||||
|
createSurface();
|
||||||
|
_sceondInited = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::createImageViews() {
|
void Application::createImageViews() {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
void createSyncObjects();
|
void createSyncObjects();
|
||||||
virtual void drawFrame(long long frameTime);
|
virtual void drawFrame(long long frameTime);
|
||||||
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
|
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
|
||||||
virtual bool isInited() { return inited; }
|
virtual bool isInited() { return _applicationInited; }
|
||||||
|
|
||||||
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path);
|
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& texture, bool srgb, VkCommandPool pool, std::string tex_path);
|
||||||
|
|
||||||
@@ -77,8 +77,9 @@ public:
|
|||||||
std::vector<VkFence> imagesInFlight; // 跟踪每个图像的使用状态
|
std::vector<VkFence> imagesInFlight; // 跟踪每个图像的使用状态
|
||||||
int currentFrame = 0;
|
int currentFrame = 0;
|
||||||
int MAX_FRAMES_IN_FLIGHT = 2;
|
int MAX_FRAMES_IN_FLIGHT = 2;
|
||||||
bool inited = false;
|
bool _applicationInited = false;
|
||||||
|
|
||||||
|
bool _sceondInited = true;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void loadTexture(std::string path, Texture& tex, bool srgb, VkCommandPool pool);
|
void loadTexture(std::string path, Texture& tex, bool srgb, VkCommandPool pool);
|
||||||
@@ -99,4 +100,6 @@ protected:
|
|||||||
long long _lastDrawFrameTime;
|
long long _lastDrawFrameTime;
|
||||||
|
|
||||||
std::mutex changeMotionMtx;
|
std::mutex changeMotionMtx;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
+45
-41
@@ -778,60 +778,64 @@ void FaceApp::initVulkan()
|
|||||||
{
|
{
|
||||||
Application::initVulkan();
|
Application::initVulkan();
|
||||||
|
|
||||||
createVmaAllocator();
|
if (!_faceAppInited)
|
||||||
LoadOBJ("face_picture_3dmax.obj", obj_vertices, obj_indices);
|
|
||||||
//m_texs_left.resize(kTextureMax);
|
|
||||||
//m_texs_right.resize(kTextureMax);
|
|
||||||
if (kThick)
|
|
||||||
{
|
{
|
||||||
m_texs_thick.resize(kTextureMax);
|
createVmaAllocator();
|
||||||
}
|
LoadOBJ("face_picture_3dmax.obj", obj_vertices, obj_indices);
|
||||||
|
//m_texs_left.resize(kTextureMax);
|
||||||
std::vector<unsigned char> data = readFileUnsignedChar("dummy.png", false);
|
//m_texs_right.resize(kTextureMax);
|
||||||
unsigned error = lodepng::decode(dummy_data, dummy_w, dummy_h, data, LCT_RGBA, 8);
|
|
||||||
|
|
||||||
for (int i = 0; i < kTextureInit; ++i)
|
|
||||||
{
|
|
||||||
//string id_str = std::to_string(i);
|
|
||||||
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_left[i], true, commandPool, "dummy.png_left_" + id_str);
|
|
||||||
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_right[i], true, commandPool, "dummy.png_right_" + id_str);
|
|
||||||
if (kThick)
|
if (kThick)
|
||||||
{
|
{
|
||||||
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_thick[i], true, commandPool, "dummy.png_thick_" + id_str);
|
m_texs_thick.resize(kTextureMax);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
loadTexture("out.png", tex_bg, true, commandPool);
|
std::vector<unsigned char> data = readFileUnsignedChar("dummy.png", false);
|
||||||
createVertexBuffer();
|
unsigned error = lodepng::decode(dummy_data, dummy_w, dummy_h, data, LCT_RGBA, 8);
|
||||||
createUniformBuffer();
|
|
||||||
setup_descriptor_pool();
|
|
||||||
|
|
||||||
setup_descriptor_set_layout();
|
for (int i = 0; i < kTextureInit; ++i)
|
||||||
setup_descriptor_set();
|
{
|
||||||
create_face_pipelines();
|
//string id_str = std::to_string(i);
|
||||||
|
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_left[i], true, commandPool, "dummy.png_left_" + id_str);
|
||||||
|
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_right[i], true, commandPool, "dummy.png_right_" + id_str);
|
||||||
|
if (kThick)
|
||||||
|
{
|
||||||
|
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_thick[i], true, commandPool, "dummy.png_thick_" + id_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setup_descriptor_set_layout_bg();
|
loadTexture("out.png", tex_bg, true, commandPool);
|
||||||
setup_descriptor_set_bg();
|
createVertexBuffer();
|
||||||
create_pipelines_bg();
|
createUniformBuffer();
|
||||||
|
setup_descriptor_pool();
|
||||||
|
|
||||||
uploadVertexData();
|
setup_descriptor_set_layout();
|
||||||
last_update_time = getCurrentTimeMillis();
|
setup_descriptor_set();
|
||||||
|
create_face_pipelines();
|
||||||
|
|
||||||
//changeMotion(_initArg.motion);
|
setup_descriptor_set_layout_bg();
|
||||||
Start();
|
setup_descriptor_set_bg();
|
||||||
|
create_pipelines_bg();
|
||||||
|
|
||||||
|
uploadVertexData();
|
||||||
|
last_update_time = getCurrentTimeMillis();
|
||||||
|
|
||||||
|
//changeMotion(_initArg.motion);
|
||||||
|
Start();
|
||||||
|
_faceAppInited = true;
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
std::vector<float> floatArray;
|
std::vector<float> floatArray;
|
||||||
std::string& str = HardCodeData::Get().face_result_point_str;
|
std::string& str = HardCodeData::Get().face_result_point_str;
|
||||||
std::stringstream ss(str);
|
std::stringstream ss(str);
|
||||||
std::string token;
|
std::string token;
|
||||||
while (std::getline(ss, token, ',')) {
|
while (std::getline(ss, token, ',')) {
|
||||||
floatArray.push_back(std::stof(token));
|
floatArray.push_back(std::stof(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
//ReceiveFacePoint(floatArray.data(), floatArray.size() / 3, 480, 480);
|
//ReceiveFacePoint(floatArray.data(), floatArray.size() / 3, 480, 480);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceApp::Start()
|
void FaceApp::Start()
|
||||||
@@ -1470,7 +1474,7 @@ string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
|
|||||||
|
|
||||||
void FaceApp::loadMotionThread()
|
void FaceApp::loadMotionThread()
|
||||||
{
|
{
|
||||||
while (!_running)
|
while (!isInited())
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -71,7 +71,7 @@ public:
|
|||||||
static FaceApp* Get() { return faceIns; }
|
static FaceApp* Get() { return faceIns; }
|
||||||
void update_face_vertex_buffer(float* pos, int pointCount);
|
void update_face_vertex_buffer(float* pos, int pointCount);
|
||||||
|
|
||||||
virtual bool isInited() override { return inited; }
|
virtual bool isInited() override { return _applicationInited && _faceAppInited && _sceondInited; }
|
||||||
virtual void cleanup() override;
|
virtual void cleanup() override;
|
||||||
|
|
||||||
Texture tex_bg = {};
|
Texture tex_bg = {};
|
||||||
@@ -210,6 +210,7 @@ public:
|
|||||||
void StopMotion();
|
void StopMotion();
|
||||||
|
|
||||||
void ResumeMotion();
|
void ResumeMotion();
|
||||||
|
bool _faceAppInited = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-1
@@ -179,6 +179,7 @@ int main() {
|
|||||||
//threadRun = true;
|
//threadRun = true;
|
||||||
//std::thread t(threadFunction);
|
//std::thread t(threadFunction);
|
||||||
app.mainLoop();
|
app.mainLoop();
|
||||||
|
app._sceondInited = false;
|
||||||
//threadRun = false;
|
//threadRun = false;
|
||||||
//t.join();
|
//t.join();
|
||||||
//try {
|
//try {
|
||||||
@@ -194,7 +195,7 @@ int main() {
|
|||||||
s_motions.motions.push_back(motions["11"]);
|
s_motions.motions.push_back(motions["11"]);
|
||||||
j = s_motions;
|
j = s_motions;
|
||||||
s = j.dump();
|
s = j.dump();
|
||||||
|
app.initVulkan();
|
||||||
app.preLoadMotionList(s, CppCallback2);
|
app.preLoadMotionList(s, CppCallback2);
|
||||||
app.mainLoop();
|
app.mainLoop();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user