添加了动画,资源也改为英文名了
@@ -42,9 +42,9 @@ void android_main(struct android_app *pApp) {
|
|||||||
pApp->onAppCmd = handle_cmd;
|
pApp->onAppCmd = handle_cmd;
|
||||||
|
|
||||||
android_app_set_motion_event_filter(pApp, nullptr);
|
android_app_set_motion_event_filter(pApp, nullptr);
|
||||||
|
long long _lastDrawFrameTime = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||||
do {
|
do {
|
||||||
auto ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
auto start_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||||
// Process all pending events before running game logic.
|
// Process all pending events before running game logic.
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
@@ -72,10 +72,16 @@ void android_main(struct android_app *pApp) {
|
|||||||
}
|
}
|
||||||
if(application.isInited())
|
if(application.isInited())
|
||||||
{
|
{
|
||||||
application.drawFrame();
|
auto frameTime = (start_time - _lastDrawFrameTime);
|
||||||
|
_lastDrawFrameTime = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
application.drawFrame(frameTime);
|
||||||
|
}
|
||||||
|
auto end_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
auto function_time = (end_time - start_time);
|
||||||
|
if(function_time < 20)
|
||||||
|
{
|
||||||
|
this_thread::sleep_for(chrono::milliseconds((20-function_time)));
|
||||||
}
|
}
|
||||||
auto end_ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
|
|
||||||
this_thread::sleep_for(chrono::milliseconds((end_ms-ms)));
|
|
||||||
} while (!pApp->destroyRequested);
|
} while (!pApp->destroyRequested);
|
||||||
application.cleanup();
|
application.cleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@@ -127,8 +127,11 @@ void Application::mainLoop()
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
auto cur_time = getCurrentTimeMillis();
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
drawFrame(); // 在这里调用
|
auto functionTime = (cur_time - _lastDrawFrameTime);
|
||||||
|
_lastDrawFrameTime = getCurrentTimeMillis();
|
||||||
|
drawFrame(functionTime); // 在这里调用
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -448,7 +451,7 @@ void Application::createSyncObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex)
|
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime)
|
||||||
{
|
{
|
||||||
VkCommandBufferBeginInfo beginInfo{};
|
VkCommandBufferBeginInfo beginInfo{};
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
@@ -473,7 +476,7 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
|
|||||||
|
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
|
||||||
render(commandBuffer);
|
render(commandBuffer, frameTime);
|
||||||
|
|
||||||
// 结束渲染流程
|
// 结束渲染流程
|
||||||
vkCmdEndRenderPass(commandBuffer);
|
vkCmdEndRenderPass(commandBuffer);
|
||||||
@@ -483,7 +486,7 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::render(VkCommandBuffer commandBuffer)
|
void Application::render(VkCommandBuffer commandBuffer, long long frameTime)
|
||||||
{
|
{
|
||||||
// 绑定图形管线
|
// 绑定图形管线
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
||||||
@@ -492,7 +495,7 @@ void Application::render(VkCommandBuffer commandBuffer)
|
|||||||
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
|
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::drawFrame()
|
void Application::drawFrame(long long frameTime)
|
||||||
{
|
{
|
||||||
// 1. 等待前一帧完成
|
// 1. 等待前一帧完成
|
||||||
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
||||||
@@ -517,7 +520,7 @@ void Application::drawFrame()
|
|||||||
|
|
||||||
// 5. 记录命令缓冲区
|
// 5. 记录命令缓冲区
|
||||||
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
|
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
|
||||||
recordCommandBuffer(commandBuffers[currentFrame], imageIndex);
|
recordCommandBuffer(commandBuffers[currentFrame], imageIndex, frameTime);
|
||||||
|
|
||||||
// 6. 提交命令缓冲区
|
// 6. 提交命令缓冲区
|
||||||
VkSubmitInfo submitInfo{};
|
VkSubmitInfo submitInfo{};
|
||||||
@@ -561,7 +564,6 @@ void Application::drawFrame()
|
|||||||
|
|
||||||
// 8. 前进到下一帧
|
// 8. 前进到下一帧
|
||||||
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||||
_lastDrawFrameTime =
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
|
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ public:
|
|||||||
void createPipelineLayout();
|
void createPipelineLayout();
|
||||||
void createGraphicsPipeline();
|
void createGraphicsPipeline();
|
||||||
void createRenderPass();
|
void createRenderPass();
|
||||||
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);
|
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime);
|
||||||
void createSyncObjects();
|
void createSyncObjects();
|
||||||
void drawFrame();
|
void drawFrame(long long frameTime);
|
||||||
virtual void render(VkCommandBuffer commandBuffer);
|
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
|
||||||
virtual bool isInited() { return inited; }
|
virtual bool isInited() { return inited; }
|
||||||
|
|
||||||
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture, bool srgb);
|
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture, bool srgb);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FaceApp* FaceApp::faceIns = nullptr;
|
FaceApp* FaceApp::faceIns = nullptr;
|
||||||
|
|
||||||
FaceApp::FaceApp(/* args */)
|
FaceApp::FaceApp(/* args */)
|
||||||
@@ -515,8 +514,21 @@ void FaceApp::setup_descriptor_set()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceApp::render(VkCommandBuffer commandBuffer)
|
void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
|
||||||
{
|
{
|
||||||
|
static long long game_time = 0;
|
||||||
|
game_time += frameTime;
|
||||||
|
long long actionTime = (1000 / _initArg.action_fps);
|
||||||
|
if (game_time > actionTime)
|
||||||
|
{
|
||||||
|
_curTexIndex++;
|
||||||
|
if (_curTexIndex >= _curMotion.png_num)
|
||||||
|
{
|
||||||
|
_curTexIndex = 0;
|
||||||
|
}
|
||||||
|
game_time = game_time - actionTime;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
std::unique_lock<std::mutex> lock_point(mtx_point);
|
std::unique_lock<std::mutex> lock_point(mtx_point);
|
||||||
//Application::render(commandBuffer);
|
//Application::render(commandBuffer);
|
||||||
@@ -527,7 +539,8 @@ void FaceApp::render(VkCommandBuffer commandBuffer)
|
|||||||
|
|
||||||
vkCmdPushConstants(commandBuffer, m_pipelineLayout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue);
|
vkCmdPushConstants(commandBuffer, m_pipelineLayout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue);
|
||||||
|
|
||||||
//vkCmdDraw(commandBuffer, 6, 1, 0, 0);
|
vkCmdDraw(commandBuffer, 6, 1, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets[_curTexIndex], 0, NULL);
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets[_curTexIndex], 0, NULL);
|
||||||
@@ -604,8 +617,9 @@ void FaceApp::initVulkan()
|
|||||||
|
|
||||||
uploadVertexData();
|
uploadVertexData();
|
||||||
last_update_time = getCurrentTimeMillis();
|
last_update_time = getCurrentTimeMillis();
|
||||||
faceAppInited = true;
|
|
||||||
|
|
||||||
|
changeMotion(_initArg.motion);
|
||||||
|
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;
|
||||||
@@ -616,6 +630,7 @@ void FaceApp::initVulkan()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//ReceiveFacePoint(floatArray.data(), floatArray.size() / 3, 480, 480);
|
//ReceiveFacePoint(floatArray.data(), floatArray.size() / 3, 480, 480);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,8 +1018,15 @@ void FaceApp::changeMotion(Motion& motion)
|
|||||||
{
|
{
|
||||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||||
loadTexture(path_name, m_texs[i], true);
|
|
||||||
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
||||||
|
#ifdef _WIN32
|
||||||
|
loadTextureExample(path_name, m_texs[i], true);
|
||||||
|
loadTextureExample(path_name_ex, m_texs_ex[i], true);
|
||||||
|
#else
|
||||||
loadTexture(path_name, m_texs[i], true);
|
loadTexture(path_name, m_texs[i], true);
|
||||||
|
loadTexture(path_name, path_name_ex[i], true);
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ struct InitArg
|
|||||||
int action_fps;
|
int action_fps;
|
||||||
float zoom;
|
float zoom;
|
||||||
Motion motion;
|
Motion motion;
|
||||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(InitArg, action_fps, zoom)
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE(InitArg, action_fps, zoom, motion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
void initVulkan() override;
|
void initVulkan() override;
|
||||||
|
|
||||||
|
|
||||||
void render(VkCommandBuffer commandBuffer) override;
|
void render(VkCommandBuffer commandBuffer, long long frameTime) override;
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
#include "FaceApp.h"
|
#include "FaceApp.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
InitArg init_arg;
|
InitArg init_arg;
|
||||||
Motion motion;
|
Motion motion;
|
||||||
motion.type = "底妆";
|
motion.type = "bottom_makeup";
|
||||||
motion.technique = "基础上妆";
|
motion.technique = "base_makeup";
|
||||||
motion.step = "2按压";
|
motion.step = "press2";
|
||||||
motion.show_type = "方向";
|
motion.show_type = "direction";
|
||||||
motion.png_name = "pic";
|
motion.png_name = "demo";
|
||||||
motion.png_num = 3;
|
motion.png_num = 1;
|
||||||
|
#
|
||||||
|
|
||||||
init_arg.motion = motion;
|
init_arg.motion = motion;
|
||||||
|
|
||||||
@@ -22,8 +22,6 @@ int main() {
|
|||||||
//motion.png_name = "pic";
|
//motion.png_name = "pic";
|
||||||
//motion.png_num = 1;
|
//motion.png_num = 1;
|
||||||
|
|
||||||
//init_arg.motions.push_back(motion);
|
|
||||||
|
|
||||||
init_arg.action_fps = 3;
|
init_arg.action_fps = 3;
|
||||||
init_arg.zoom = 1.5f;
|
init_arg.zoom = 1.5f;
|
||||||
|
|
||||||
@@ -32,12 +30,13 @@ int main() {
|
|||||||
FaceApp app;
|
FaceApp app;
|
||||||
app.SetInitArg(json_str.c_str());
|
app.SetInitArg(json_str.c_str());
|
||||||
app.initVulkan();
|
app.initVulkan();
|
||||||
try {
|
app.mainLoop();
|
||||||
app.mainLoop();
|
//try {
|
||||||
} catch (const std::exception& e) {
|
// app.mainLoop();
|
||||||
std::cerr << e.what() << std::endl;
|
//} catch (const std::exception& e) {
|
||||||
return EXIT_FAILURE;
|
// std::cerr << e.what() << std::endl;
|
||||||
}
|
// return EXIT_FAILURE;
|
||||||
|
//}
|
||||||
app.cleanup();
|
app.cleanup();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||