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
|
view roughly every 50 ms; this is to support animations
|
||||||
such as progress bars while keeping the system load
|
such as progress bars while keeping the system load
|
||||||
reasonably low */
|
reasonably low */
|
||||||
std::thread refresh_thread = std::thread(
|
/*std::thread refresh_thread = std::thread(
|
||||||
[&]() {
|
[&]() {
|
||||||
std::chrono::milliseconds time(50);
|
std::chrono::milliseconds time(50);
|
||||||
while (__mainloop_active) {
|
while (__mainloop_active) {
|
||||||
|
@ -63,7 +63,7 @@ void mainloop() {
|
||||||
glfwPostEmptyEvent();
|
glfwPostEmptyEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (__mainloop_active) {
|
while (__mainloop_active) {
|
||||||
|
@ -87,14 +87,15 @@ void mainloop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for mouse/keyboard or empty refresh events */
|
/* Wait for mouse/keyboard or empty refresh events */
|
||||||
glfwWaitEvents();
|
//glfwWaitEvents();
|
||||||
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
std::cerr << "Caught exception in main loop: " << e.what() << std::endl;
|
std::cerr << "Caught exception in main loop: " << e.what() << std::endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_thread.join();
|
//refresh_thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void leave() {
|
void leave() {
|
||||||
|
|
|
@ -64,14 +64,6 @@ void Gui::init() {
|
||||||
|
|
||||||
mApp->setVisible(true);
|
mApp->setVisible(true);
|
||||||
mApp->performLayout();
|
mApp->performLayout();
|
||||||
//window->center();
|
|
||||||
|
|
||||||
|
|
||||||
// Init UI
|
|
||||||
/*if (!imguiRenderGLInit("DroidSans.ttf")) {
|
|
||||||
fprintf(stderr, "Could not init GUI renderer.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
mTimeSinceLastProfilingDisplay = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
@ -91,11 +83,10 @@ void Gui::update() {
|
||||||
mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0));
|
mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0));
|
||||||
|
|
||||||
// Frame time
|
// 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
|
// 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() {
|
void Gui::createSimulationPanel() {
|
||||||
|
@ -426,10 +417,10 @@ void Gui::createProfilingPanel() {
|
||||||
mFPSLabel = new Label(profilingPanel, std::string("FPS : ") + floatToString(mCachedFPS, 0),"sans-bold");
|
mFPSLabel = new Label(profilingPanel, std::string("FPS : ") + floatToString(mCachedFPS, 0),"sans-bold");
|
||||||
|
|
||||||
// Update time
|
// 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
|
// 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);
|
profilingPanel->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,11 +213,12 @@ void TestbedApplication::drawContents() {
|
||||||
// Render the scene
|
// Render the scene
|
||||||
mCurrentScene->render();
|
mCurrentScene->render();
|
||||||
|
|
||||||
mGui.update();
|
|
||||||
|
|
||||||
// Check the OpenGL errors
|
// Check the OpenGL errors
|
||||||
checkOpenGLErrors();
|
checkOpenGLErrors();
|
||||||
|
|
||||||
|
|
||||||
|
mGui.update();
|
||||||
|
|
||||||
// Compute the current framerate
|
// Compute the current framerate
|
||||||
computeFPS();
|
computeFPS();
|
||||||
}
|
}
|
||||||
|
@ -291,6 +292,12 @@ void TestbedApplication::checkOpenGLErrorsInternal(const char* file, int line) {
|
||||||
// Compute the FPS
|
// Compute the FPS
|
||||||
void TestbedApplication::computeFPS() {
|
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++;
|
mNbFrames++;
|
||||||
|
|
||||||
// Get the number of seconds since start
|
// 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);
|
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
|
// Callback method to receive scrolling events
|
||||||
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
void TestbedApplication::scroll(GLFWwindow* window, double xAxis, double yAxis) {
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,7 @@ class TestbedApplication : public Screen {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~TestbedApplication();
|
virtual ~TestbedApplication();
|
||||||
|
|
||||||
|
virtual void drawAll();
|
||||||
virtual void drawContents();
|
virtual void drawContents();
|
||||||
|
|
||||||
/// Window resize event handler
|
/// Window resize event handler
|
||||||
|
@ -275,13 +276,13 @@ inline void TestbedApplication::displayContactPoints(bool display) {
|
||||||
|
|
||||||
// Enable/Disable Vertical synchronization
|
// Enable/Disable Vertical synchronization
|
||||||
inline void TestbedApplication::enableVSync(bool enable) {
|
inline void TestbedApplication::enableVSync(bool enable) {
|
||||||
/*mIsVSyncEnabled = enable;
|
mIsVSyncEnabled = enable;
|
||||||
if (mIsVSyncEnabled) {
|
if (mIsVSyncEnabled) {
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glfwSwapInterval(0);
|
glfwSwapInterval(0);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user