修改renderloop,视频创建完成后退出,关闭UI绘制
parent
d4beea0076
commit
9bdb87ea59
|
@ -51,11 +51,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
|||
|
||||
std::vector<const char*> instanceExtensions = { };
|
||||
|
||||
if (settings.headless)
|
||||
{
|
||||
instanceExtensions.push_back("VK_EXT_headless_surface");
|
||||
}
|
||||
else
|
||||
if (!settings.headless)
|
||||
{
|
||||
instanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
// Enable surface extensions depending on os
|
||||
|
@ -334,166 +330,11 @@ void VulkanExampleBase::renderFrame()
|
|||
|
||||
void VulkanExampleBase::renderLoop()
|
||||
{
|
||||
destWidth = width;
|
||||
destHeight = height;
|
||||
#if defined(_WIN32)
|
||||
MSG msg;
|
||||
bool quitMessageReceived = false;
|
||||
while (!quitMessageReceived) {
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
if (msg.message == WM_QUIT) {
|
||||
quitMessageReceived = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!IsIconic(window)) {
|
||||
renderFrame();
|
||||
}
|
||||
}
|
||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
while (1)
|
||||
while (!signal.imageSequenceToVideoComplete)
|
||||
{
|
||||
int ident;
|
||||
int events;
|
||||
struct android_poll_source* source;
|
||||
bool destroy = false;
|
||||
|
||||
focused = true;
|
||||
|
||||
while ((ident = ALooper_pollAll(focused ? 0 : -1, NULL, &events, (void**)&source)) >= 0)
|
||||
{
|
||||
if (source != NULL)
|
||||
{
|
||||
source->process(androidApp, source);
|
||||
}
|
||||
if (androidApp->destroyRequested != 0)
|
||||
{
|
||||
LOGD("Android app destroy requested");
|
||||
destroy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// App destruction requested
|
||||
// Exit loop, example will be destroyed in application main
|
||||
if (destroy)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Render frame
|
||||
if (prepared)
|
||||
{
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
render();
|
||||
frameCounter++;
|
||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||
frameTimer = tDiff / 1000.0f;
|
||||
camera.update(frameTimer);
|
||||
fpsTimer += (float)tDiff;
|
||||
if (fpsTimer > 1000.0f)
|
||||
{
|
||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||
fpsTimer = 0.0f;
|
||||
frameCounter = 0;
|
||||
}
|
||||
|
||||
// Check gamepad state
|
||||
const float deadZone = 0.0015f;
|
||||
// todo : check if gamepad is present
|
||||
// todo : time based and relative axis positions
|
||||
if (camera.type != Camera::CameraType::firstperson)
|
||||
{
|
||||
// Rotate
|
||||
if (std::abs(gamePadState.axisLeft.x) > deadZone) {
|
||||
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
|
||||
}
|
||||
if (std::abs(gamePadState.axisLeft.y) > deadZone) {
|
||||
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
|
||||
}
|
||||
} else {
|
||||
camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
|
||||
}
|
||||
}
|
||||
renderFrame();
|
||||
}
|
||||
#elif defined(_DIRECT2DISPLAY)
|
||||
while (!quit)
|
||||
{
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
render();
|
||||
frameCounter++;
|
||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||
frameTimer = tDiff / 1000.0f;
|
||||
camera.update(frameTimer);
|
||||
fpsTimer += (float)tDiff;
|
||||
if (fpsTimer > 1000.0f)
|
||||
{
|
||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||
fpsTimer = 0.0f;
|
||||
frameCounter = 0;
|
||||
}
|
||||
}
|
||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
||||
while (!quit)
|
||||
{
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
|
||||
while (wl_display_prepare_read(display) != 0)
|
||||
wl_display_dispatch_pending(display);
|
||||
wl_display_flush(display);
|
||||
wl_display_read_events(display);
|
||||
wl_display_dispatch_pending(display);
|
||||
|
||||
render();
|
||||
frameCounter++;
|
||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||
frameTimer = tDiff / 1000.0f;
|
||||
camera.update(frameTimer);
|
||||
fpsTimer += (float)tDiff;
|
||||
if (fpsTimer > 1000.0f)
|
||||
{
|
||||
wl_shell_surface_set_title(shell_surface, title.c_str());
|
||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||
fpsTimer = 0.0f;
|
||||
frameCounter = 0;
|
||||
}
|
||||
}
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
xcb_flush(connection);
|
||||
while (!quit)
|
||||
{
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
xcb_generic_event_t *event;
|
||||
while ((event = xcb_poll_for_event(connection)))
|
||||
{
|
||||
handleEvent(event);
|
||||
free(event);
|
||||
}
|
||||
render();
|
||||
frameCounter++;
|
||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||
frameTimer = tDiff / 1000.0f;
|
||||
camera.update(frameTimer);
|
||||
fpsTimer += (float)tDiff;
|
||||
if (fpsTimer > 1000.0f)
|
||||
{
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE,
|
||||
window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
|
||||
title.size(), title.c_str());
|
||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||
fpsTimer = 0.0f;
|
||||
frameCounter = 0;
|
||||
}
|
||||
}
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
[NSApp run];
|
||||
#endif
|
||||
// Flush device to make sure all resources can be freed
|
||||
vkDeviceWaitIdle(device);
|
||||
}
|
||||
|
@ -1821,6 +1662,7 @@ void VulkanExampleBase::setupFrameBuffer()
|
|||
/*
|
||||
MSAA
|
||||
*/
|
||||
VkFormat colorFormat = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
if (settings.multiSampling) {
|
||||
// Check if device supports requested sample count for color and depth frame buffer
|
||||
//assert((deviceProperties.limits.framebufferColorSampleCounts >= sampleCount) && (deviceProperties.limits.framebufferDepthSampleCounts >= sampleCount));
|
||||
|
@ -1828,7 +1670,7 @@ void VulkanExampleBase::setupFrameBuffer()
|
|||
VkImageCreateInfo imageCI{};
|
||||
imageCI.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCI.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCI.format = swapChain.colorFormat;
|
||||
imageCI.format = colorFormat;
|
||||
imageCI.extent.width = width;
|
||||
imageCI.extent.height = height;
|
||||
imageCI.extent.depth = 1;
|
||||
|
@ -1859,7 +1701,7 @@ void VulkanExampleBase::setupFrameBuffer()
|
|||
imageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
imageViewCI.image = multisampleTarget.color.image;
|
||||
imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
imageViewCI.format = swapChain.colorFormat;
|
||||
imageViewCI.format = colorFormat;
|
||||
imageViewCI.components.r = VK_COMPONENT_SWIZZLE_R;
|
||||
imageViewCI.components.g = VK_COMPONENT_SWIZZLE_G;
|
||||
imageViewCI.components.b = VK_COMPONENT_SWIZZLE_B;
|
||||
|
@ -1959,11 +1801,13 @@ void VulkanExampleBase::setupFrameBuffer()
|
|||
VkImageView attachments[4];
|
||||
|
||||
if (settings.multiSampling) {
|
||||
|
||||
attachments[0] = multisampleTarget.color.view;
|
||||
attachments[2] = multisampleTarget.depth.view;
|
||||
attachments[3] = depthStencil.view;
|
||||
}
|
||||
else {
|
||||
|
||||
attachments[1] = depthStencil.view;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,13 @@ public:
|
|||
bool paused = false;
|
||||
uint32_t lastFPS = 0;
|
||||
|
||||
struct Signal
|
||||
{
|
||||
bool imageSequenceOutputComplete = false;
|
||||
bool imageSequenceToVideoComplete = false;
|
||||
|
||||
}signal;
|
||||
|
||||
struct Settings {
|
||||
bool validation = true; // 校验层开关
|
||||
bool fullscreen = false; // 全屏开关
|
||||
|
@ -121,7 +128,7 @@ public:
|
|||
bool headless = false; // 无头开关
|
||||
bool outputPNGimage = false;
|
||||
bool enableSaveToImageSequeue = true; // 图片序列开关(暂时弃用)
|
||||
uint32_t outputFrameCount = 100; // 图片序列结束帧
|
||||
uint32_t outputFrameCount = 50; // 图片序列结束帧
|
||||
bool takeScreenShot = false; // 截屏(暂时弃用)
|
||||
uint32_t startFrameCount = 1; // 图片序列开始帧
|
||||
|
||||
|
|
Binary file not shown.
|
@ -183,7 +183,7 @@ PlumageRender::PlumageRender()
|
|||
}
|
||||
|
||||
// User interface
|
||||
gui->draw(currentCB);
|
||||
//gui->draw(currentCB);
|
||||
|
||||
vkCmdEndRenderPass(currentCB);
|
||||
VK_CHECK_RESULT(vkEndCommandBuffer(currentCB));
|
||||
|
@ -1905,10 +1905,11 @@ PlumageRender::PlumageRender()
|
|||
std::cout << commandLine << std::endl;
|
||||
std::system(commandLine.c_str());
|
||||
|
||||
signal.imageSequenceToVideoComplete = true;
|
||||
|
||||
std::cout << "vidoe codec complete,saved in:" << resultVideoPath << std::endl;
|
||||
std::cout << "star to clean up image sequence" << std::endl;
|
||||
removeImageSequence();
|
||||
signal.imageSequenceToVideoComplete = true;
|
||||
}
|
||||
|
||||
void PlumageRender::removeImageSequence()
|
||||
|
|
|
@ -55,12 +55,7 @@ public:
|
|||
|
||||
} info ;
|
||||
|
||||
struct Signal
|
||||
{
|
||||
bool imageSequenceOutputComplete = false;
|
||||
bool imageSequenceToVideoComplete = false;
|
||||
|
||||
}signal;
|
||||
|
||||
|
||||
struct Models
|
||||
|
|
Loading…
Reference in New Issue