save code

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