完成动画在设备上播放和切换
This commit is contained in:
@@ -39,7 +39,7 @@ public:
|
||||
void createRenderPass();
|
||||
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime);
|
||||
void createSyncObjects();
|
||||
void drawFrame(long long frameTime);
|
||||
virtual void drawFrame(long long frameTime);
|
||||
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
|
||||
virtual bool isInited() { return inited; }
|
||||
|
||||
@@ -89,4 +89,6 @@ protected:
|
||||
void destroy_texture(Texture texture);
|
||||
std::mutex mtx;
|
||||
long long _lastDrawFrameTime;
|
||||
|
||||
std::mutex changeMotionMtx;
|
||||
};
|
||||
+46
-40
@@ -456,34 +456,7 @@ void FaceApp::create_face_pipelines()
|
||||
VK_CHECK(vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_create_info, nullptr, &m_graphicsPipeline));
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_pool()
|
||||
{
|
||||
// 保守估计:假设每个描述符集可能有多个绑定
|
||||
const uint32_t setsCount = kMaxTexture;
|
||||
//const uint32_t multiplier = 3; // 安全系数
|
||||
|
||||
std::vector<VkDescriptorPoolSize> pool_sizes = {
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = 3
|
||||
},
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = setsCount + 4
|
||||
},
|
||||
// 如果需要其他类型的描述符,在这里添加
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptor_pool_info{};
|
||||
descriptor_pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptor_pool_info.poolSizeCount = static_cast<uint32_t>(pool_sizes.size());
|
||||
descriptor_pool_info.pPoolSizes = pool_sizes.data();
|
||||
descriptor_pool_info.maxSets = setsCount + 7; // 额外预留一些集合
|
||||
descriptor_pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
|
||||
VK_CHECK(vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr, &descriptor_pool));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -553,6 +526,32 @@ void FaceApp::setup_descriptor_set_layout()
|
||||
VK_CHECK(vkCreatePipelineLayout(device, &pipeline_layout_create_info, nullptr, &m_pipelineLayout));
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_pool()
|
||||
{
|
||||
|
||||
std::vector<VkDescriptorPoolSize> pool_sizes = {
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.descriptorCount = kMaxTexture
|
||||
},
|
||||
{
|
||||
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
.descriptorCount = (kMaxTexture + 1)
|
||||
},
|
||||
// 如果需要其他类型的描述符,在这里添加
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo descriptor_pool_info{};
|
||||
descriptor_pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
descriptor_pool_info.poolSizeCount = static_cast<uint32_t>(pool_sizes.size());
|
||||
descriptor_pool_info.pPoolSizes = pool_sizes.data();
|
||||
descriptor_pool_info.maxSets = kMaxTexture + (kMaxTexture + 1);
|
||||
descriptor_pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
|
||||
VK_CHECK(vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr, &descriptor_pool));
|
||||
|
||||
}
|
||||
|
||||
void FaceApp::setup_descriptor_set()
|
||||
{
|
||||
m_descriptor_sets.resize(kMaxTexture);
|
||||
@@ -646,21 +645,10 @@ void FaceApp::setup_descriptor_set()
|
||||
|
||||
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_names.size())
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
}
|
||||
game_time = game_time - actionTime;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::unique_lock<std::mutex> lock_point(mtx_point);
|
||||
|
||||
//Application::render(commandBuffer);
|
||||
|
||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout_bg, 0, 1, &m_descriptor_set_bg, 0, NULL);
|
||||
@@ -926,7 +914,7 @@ void FaceApp::createUniformBuffer()
|
||||
|
||||
|
||||
void FaceApp::create_pipelines_bg()
|
||||
{
|
||||
{
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
|
||||
input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
@@ -1137,6 +1125,23 @@ void FaceApp::SetInitArg(const char* arg)
|
||||
|
||||
}
|
||||
|
||||
void FaceApp::drawFrame(long long frameTime)
|
||||
{
|
||||
std::unique_lock lock(changeMotionMtx);
|
||||
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_names.size())
|
||||
{
|
||||
_curTexIndex = 0;
|
||||
}
|
||||
game_time = game_time - actionTime;
|
||||
}
|
||||
Application::drawFrame(frameTime);
|
||||
}
|
||||
|
||||
void FaceApp::changeMotion(const char* json)
|
||||
{
|
||||
@@ -1150,6 +1155,7 @@ void FaceApp::changeMotion(Motion& motion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
|
||||
_curMotion = motion;
|
||||
for (int i = 0; i < _curMotion.png_names.size(); ++i)
|
||||
{
|
||||
|
||||
+3
-1
@@ -100,7 +100,7 @@ private:
|
||||
VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
|
||||
VkDescriptorSetLayout m_descriptorSetLayout = VK_NULL_HANDLE;
|
||||
vector<VkDescriptorSet> m_descriptor_sets;
|
||||
const int kMaxTexture = 30;
|
||||
const uint32_t kMaxTexture = 30;
|
||||
vector<Texture> m_texs;
|
||||
vector<Texture> m_texs_ex;
|
||||
|
||||
@@ -141,6 +141,8 @@ public:
|
||||
Motion _curMotion;
|
||||
int _curTexIndex = 0;
|
||||
void SetInitArg(const char* arg);
|
||||
|
||||
void drawFrame(long long frameTime)override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user