Fix issue with fixed framerate in nanogui
This commit is contained in:
parent
abe178fa1d
commit
97436877fb
|
@ -55,7 +55,7 @@ void mainloop() {
|
|||
view roughly every 50 ms; this is to support animations
|
||||
such as progress bars while keeping the system load
|
||||
reasonably low */
|
||||
std::thread refresh_thread = std::thread(
|
||||
/*std::thread refresh_thread = std::thread(
|
||||
[&]() {
|
||||
std::chrono::milliseconds time(50);
|
||||
while (__mainloop_active) {
|
||||
|
@ -63,7 +63,7 @@ void mainloop() {
|
|||
glfwPostEmptyEvent();
|
||||
}
|
||||
}
|
||||
);
|
||||
);*/
|
||||
|
||||
try {
|
||||
while (__mainloop_active) {
|
||||
|
@ -87,14 +87,15 @@ void mainloop() {
|
|||
}
|
||||
|
||||
/* Wait for mouse/keyboard or empty refresh events */
|
||||
glfwWaitEvents();
|
||||
//glfwWaitEvents();
|
||||
glfwPollEvents();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Caught exception in main loop: " << e.what() << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
refresh_thread.join();
|
||||
//refresh_thread.join();
|
||||
}
|
||||
|
||||
void leave() {
|
||||
|
|
|
@ -64,14 +64,6 @@ void Gui::init() {
|
|||
|
||||
mApp->setVisible(true);
|
||||
mApp->performLayout();
|
||||
//window->center();
|
||||
|
||||
|
||||
// Init UI
|
||||
/*if (!imguiRenderGLInit("DroidSans.ttf")) {
|
||||
fprintf(stderr, "Could not init GUI renderer.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}*/
|
||||
|
||||
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
||||
}
|
||||
|
@ -91,11 +83,10 @@ void Gui::update() {
|
|||
mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0));
|
||||
|
||||
// Frame time
|
||||
mFrameTimeLabel->setCaption(std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1));
|
||||
mFrameTimeLabel->setCaption(std::string("Frame time : ") + floatToString(mCachedUpdateTime * 1000.0, 1) + std::string(" ms"));
|
||||
|
||||
// Physics time
|
||||
mPhysicsTimeLabel->setCaption("Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1));
|
||||
|
||||
mPhysicsTimeLabel->setCaption(std::string("Physics time : ") + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1) + std::string(" ms"));
|
||||
}
|
||||
|
||||
void Gui::createSimulationPanel() {
|
||||
|
@ -426,10 +417,10 @@ void Gui::createProfilingPanel() {
|
|||
mFPSLabel = new Label(profilingPanel, std::string("FPS : ") + floatToString(mCachedFPS, 0),"sans-bold");
|
||||
|
||||
// Update time
|
||||
mFrameTimeLabel = new Label(profilingPanel, std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1),"sans-bold");
|
||||
mFrameTimeLabel = new Label(profilingPanel, std::string("Frame time : ") + floatToString(mCachedUpdateTime * 1000.0, 1) + std::string(" ms"),"sans-bold");
|
||||
|
||||
// Update time
|
||||
mPhysicsTimeLabel = new Label(profilingPanel, "Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1),"sans-bold");
|
||||
mPhysicsTimeLabel = new Label(profilingPanel, std::string("Physics time : ") + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1) + std::string(" ms"),"sans-bold");
|
||||
|
||||
profilingPanel->setVisible(true);
|
||||
}
|
||||
|
|
|
@ -213,11 +213,12 @@ void TestbedApplication::drawContents() {
|
|||
// Render the scene
|
||||
mCurrentScene->render();
|
||||
|
||||
mGui.update();
|
||||
|
||||
// Check the OpenGL errors
|
||||
checkOpenGLErrors();
|
||||
|
||||
|
||||
mGui.update();
|
||||
|
||||
// Compute the current framerate
|
||||
computeFPS();
|
||||
}
|
||||
|
@ -291,6 +292,12 @@ void TestbedApplication::checkOpenGLErrorsInternal(const char* file, int line) {
|
|||
// Compute the FPS
|
||||
void TestbedApplication::computeFPS() {
|
||||
|
||||
// Note : By default the nanogui library is using glfwWaitEvents() to process
|
||||
// events and sleep to target a framerate of 50 ms (using a thread
|
||||
// sleeping). However, for games we prefer to use glfwPollEvents()
|
||||
// instead and remove the update. Therefore the file common.cpp of the
|
||||
// nanogui library has been modified to have a faster framerate
|
||||
|
||||
mNbFrames++;
|
||||
|
||||
// Get the number of seconds since start
|
||||
|
@ -386,6 +393,16 @@ bool TestbedApplication::scrollEvent(const Vector2i &p, const Vector2f &rel) {
|
|||
return mCurrentScene->scrollingEvent(rel[0], rel[1], SCROLL_SENSITIVITY);
|
||||
}
|
||||
|
||||
void TestbedApplication::drawAll() {
|
||||
glClearColor(mBackground[0], mBackground[1], mBackground[2], 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
drawContents();
|
||||
drawWidgets();
|
||||
|
||||
glfwSwapBuffers(mGLFWWindow);
|
||||
}
|
||||
|
||||
// Callback method to receive scrolling events
|
||||
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
||||
|
||||
|
|
|
@ -190,6 +190,7 @@ class TestbedApplication : public Screen {
|
|||
/// Destructor
|
||||
virtual ~TestbedApplication();
|
||||
|
||||
virtual void drawAll();
|
||||
virtual void drawContents();
|
||||
|
||||
/// Window resize event handler
|
||||
|
@ -275,13 +276,13 @@ inline void TestbedApplication::displayContactPoints(bool display) {
|
|||
|
||||
// Enable/Disable Vertical synchronization
|
||||
inline void TestbedApplication::enableVSync(bool enable) {
|
||||
/*mIsVSyncEnabled = enable;
|
||||
mIsVSyncEnabled = enable;
|
||||
if (mIsVSyncEnabled) {
|
||||
glfwSwapInterval(1);
|
||||
}
|
||||
else {
|
||||
glfwSwapInterval(0);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user