Frame rate independent animation updates
This commit is contained in:
parent
710ff2d511
commit
e502785b1f
5 changed files with 76 additions and 59 deletions
|
|
@ -60,7 +60,7 @@ public:
|
||||||
struct android_app* app;
|
struct android_app* app;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
float frameTimer = 0;
|
float frameTimer = 1.0f;
|
||||||
|
|
||||||
struct Texture {
|
struct Texture {
|
||||||
VkSampler sampler;
|
VkSampler sampler;
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ public:
|
||||||
|
|
||||||
void updateUniformBuffers()
|
void updateUniformBuffers()
|
||||||
{
|
{
|
||||||
computeUbo.deltaT = (1.0f / 60.0f) * 4.0f;
|
computeUbo.deltaT = (1.0f / frameTimer) * 0.15f;
|
||||||
computeUbo.destX = sin(glm::radians(timer*360.0)) * 0.75f;
|
computeUbo.destX = sin(glm::radians(timer*360.0)) * 0.75f;
|
||||||
computeUbo.destY = cos(glm::radians(timer*360.0)) * 0.10f;
|
computeUbo.destY = cos(glm::radians(timer*360.0)) * 0.10f;
|
||||||
uint8_t *pData;
|
uint8_t *pData;
|
||||||
|
|
@ -314,8 +314,8 @@ public:
|
||||||
pipelineCreateInfo.renderPass = renderPass;
|
pipelineCreateInfo.renderPass = renderPass;
|
||||||
|
|
||||||
// Additive blending
|
// Additive blending
|
||||||
blendAttachmentState.colorWriteMask = 0xF;
|
|
||||||
blendAttachmentState.blendEnable = VK_TRUE;
|
blendAttachmentState.blendEnable = VK_TRUE;
|
||||||
|
blendAttachmentState.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||||
blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
|
blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
|
||||||
blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||||
blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||||
|
|
@ -323,6 +323,7 @@ public:
|
||||||
blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||||
blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA;
|
blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_DST_ALPHA;
|
||||||
|
|
||||||
|
|
||||||
err = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid);
|
err = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
@ -714,6 +715,33 @@ public:
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
// Render frame
|
||||||
|
if (prepared)
|
||||||
|
{
|
||||||
|
startTiming();
|
||||||
|
if (animating)
|
||||||
|
{
|
||||||
|
if (animStart > 0.0f)
|
||||||
|
{
|
||||||
|
animStart -= 0.15f * (1.0f / frameTimer);
|
||||||
|
}
|
||||||
|
if ((animate) & (animStart <= 0.0f))
|
||||||
|
{
|
||||||
|
timer += 0.5f * (1.0f / frameTimer);
|
||||||
|
if (timer > 1.0)
|
||||||
|
{
|
||||||
|
timer -= 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
draw();
|
||||||
|
endTiming();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int32_t handleInput(struct android_app* app, AInputEvent* event)
|
static int32_t handleInput(struct android_app* app, AInputEvent* event)
|
||||||
|
|
@ -759,7 +787,6 @@ void android_main(struct android_app* state)
|
||||||
{
|
{
|
||||||
VulkanExample *engine = new VulkanExample();
|
VulkanExample *engine = new VulkanExample();
|
||||||
|
|
||||||
//memset(&engine, 0, sizeof(engine));
|
|
||||||
state->userData = engine;
|
state->userData = engine;
|
||||||
state->onAppCmd = handleCommand;
|
state->onAppCmd = handleCommand;
|
||||||
state->onInputEvent = handleInput;
|
state->onInputEvent = handleInput;
|
||||||
|
|
@ -790,26 +817,6 @@ void android_main(struct android_app* state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render frame
|
engine->render();
|
||||||
if (engine->prepared)
|
|
||||||
{
|
|
||||||
if (engine->animating)
|
|
||||||
{
|
|
||||||
if (engine->animStart > 0.0f)
|
|
||||||
{
|
|
||||||
engine->animStart -= (1.0f / 60.0f) * 5.0f;
|
|
||||||
}
|
|
||||||
if ((engine->animate) & (engine->animStart <= 0.0f))
|
|
||||||
{
|
|
||||||
engine->timer += (1.0f / 60.0f) * 0.1f;
|
|
||||||
if (engine->timer > 1.0)
|
|
||||||
{
|
|
||||||
engine->timer -= 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
engine->updateUniformBuffers();
|
|
||||||
}
|
|
||||||
engine->draw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -611,6 +611,27 @@ public:
|
||||||
err = swapChain.queuePresent(queue, currentBuffer, semaphores.submitSignal);
|
err = swapChain.queuePresent(queue, currentBuffer, semaphores.submitSignal);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
if (prepared)
|
||||||
|
{
|
||||||
|
startTiming();
|
||||||
|
if (animating)
|
||||||
|
{
|
||||||
|
// Update rotation
|
||||||
|
state.rotation.y += 0.05f * frameTimer;
|
||||||
|
if (state.rotation.y > 360.0f)
|
||||||
|
{
|
||||||
|
state.rotation.y -= 360.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
draw();
|
||||||
|
endTiming();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int32_t handleInput(struct android_app* app, AInputEvent* event)
|
static int32_t handleInput(struct android_app* app, AInputEvent* event)
|
||||||
|
|
@ -656,7 +677,6 @@ void android_main(struct android_app* state)
|
||||||
{
|
{
|
||||||
VulkanExample *engine = new VulkanExample();
|
VulkanExample *engine = new VulkanExample();
|
||||||
|
|
||||||
//memset(&engine, 0, sizeof(engine));
|
|
||||||
state->userData = engine;
|
state->userData = engine;
|
||||||
state->onAppCmd = handleCommand;
|
state->onAppCmd = handleCommand;
|
||||||
state->onInputEvent = handleInput;
|
state->onInputEvent = handleInput;
|
||||||
|
|
@ -687,21 +707,6 @@ void android_main(struct android_app* state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render frame
|
engine->render();
|
||||||
if (engine->prepared)
|
|
||||||
{
|
|
||||||
if (engine->animating)
|
|
||||||
{
|
|
||||||
// Update rotation
|
|
||||||
engine->state.rotation.y += 0.25f;
|
|
||||||
if (engine->state.rotation.y > 360.0f)
|
|
||||||
{
|
|
||||||
engine->state.rotation.y -= 360.0f;
|
|
||||||
|
|
||||||
}
|
|
||||||
engine->updateUniformBuffers();
|
|
||||||
}
|
|
||||||
engine->draw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -570,6 +570,26 @@ public:
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
if (prepared)
|
||||||
|
{
|
||||||
|
startTiming();
|
||||||
|
if (animating)
|
||||||
|
{
|
||||||
|
// Update rotation
|
||||||
|
state.rotation.y += 0.15f * frameTimer;
|
||||||
|
if (state.rotation.y > 360.0f)
|
||||||
|
{
|
||||||
|
state.rotation.y -= 360.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
draw();
|
||||||
|
endTiming();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -616,7 +636,6 @@ void android_main(struct android_app* state)
|
||||||
{
|
{
|
||||||
VulkanExample *engine = new VulkanExample();
|
VulkanExample *engine = new VulkanExample();
|
||||||
|
|
||||||
//memset(&engine, 0, sizeof(engine));
|
|
||||||
state->userData = engine;
|
state->userData = engine;
|
||||||
state->onAppCmd = handleCommand;
|
state->onAppCmd = handleCommand;
|
||||||
state->onInputEvent = handleInput;
|
state->onInputEvent = handleInput;
|
||||||
|
|
@ -647,21 +666,7 @@ void android_main(struct android_app* state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render frame
|
engine->render();
|
||||||
if (engine->prepared)
|
|
||||||
{
|
|
||||||
if (engine->animating)
|
|
||||||
{
|
|
||||||
// Update rotation
|
|
||||||
engine->state.rotation.y += 0.5f;
|
|
||||||
if (engine->state.rotation.y > 360.0f)
|
|
||||||
{
|
|
||||||
engine->state.rotation.y -= 360.0f;
|
|
||||||
|
|
||||||
}
|
|
||||||
engine->updateUniformBuffers();
|
|
||||||
}
|
|
||||||
engine->draw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ struct VulkanExample
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
struct saved_state state;
|
struct saved_state state;
|
||||||
float frameTimer;
|
float frameTimer = 0;
|
||||||
|
|
||||||
// Vulkan
|
// Vulkan
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue