Working on new gui for testbed application

This commit is contained in:
Daniel Chappuis 2016-03-01 07:41:15 +01:00
parent e29794d24f
commit abe178fa1d
4 changed files with 39 additions and 50 deletions

View File

@ -79,22 +79,22 @@ void Gui::init() {
// Update the GUI // Update the GUI
void Gui::update() { void Gui::update() {
double currentTime = glfwGetTime(); // Update Profiling GUI every seconds
if ((currentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) { if ((mApp->mCurrentTime - mTimeSinceLastProfilingDisplay) > TIME_INTERVAL_DISPLAY_PROFILING_INFO) {
mTimeSinceLastProfilingDisplay = currentTime; mTimeSinceLastProfilingDisplay = mApp->mCurrentTime;
mCachedFPS = mApp->mFPS; mCachedFPS = mApp->mFPS;
mCachedUpdateTime = mApp->mUpdateTime; mCachedUpdateTime = mApp->mFrameTime;
mCachedPhysicsUpdateTime = mApp->mPhysicsUpdateTime; mCachedPhysicsUpdateTime = mApp->mPhysicsTime;
} }
// Framerate (FPS) // Framerate (FPS)
mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0)); mFPSLabel->setCaption(std::string("FPS : ") + floatToString(mCachedFPS, 0));
// Update time // Frame time
mUpdateTimeLabel->setCaption(std::string("Update time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1)); mFrameTimeLabel->setCaption(std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1));
// Update time // Physics time
mUpdatePhysicsTimeLabel->setCaption("Update physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1)); mPhysicsTimeLabel->setCaption("Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1));
} }
@ -400,7 +400,7 @@ void Gui::createSettingsPanel() {
CheckBox* checkboxVSync = new CheckBox(mRenderingPanel, "V-Sync"); CheckBox* checkboxVSync = new CheckBox(mRenderingPanel, "V-Sync");
checkboxVSync->setChecked(mApp->mIsVSyncEnabled); checkboxVSync->setChecked(mApp->mIsVSyncEnabled);
checkboxVSync->setCallback([&](bool value) { checkboxVSync->setCallback([&](bool value) {
mApp->mIsVSyncEnabled = value; mApp->enableVSync(value);
}); });
// Enabled/Disable Shadows // Enabled/Disable Shadows
@ -426,10 +426,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
mUpdateTimeLabel = new Label(profilingPanel, std::string("Update time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1),"sans-bold"); mFrameTimeLabel = new Label(profilingPanel, std::string("Frame time (ms) : ") + floatToString(mCachedUpdateTime * 1000.0, 1),"sans-bold");
// Update time // Update time
mUpdatePhysicsTimeLabel = new Label(profilingPanel, "Update physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1),"sans-bold"); mPhysicsTimeLabel = new Label(profilingPanel, "Physics time (ms) : " + floatToString(mCachedPhysicsUpdateTime * 1000.0, 1),"sans-bold");
profilingPanel->setVisible(true); profilingPanel->setVisible(true);
} }

View File

@ -68,8 +68,8 @@ class Gui {
// Profiling panel // Profiling panel
Label* mFPSLabel; Label* mFPSLabel;
Label* mUpdateTimeLabel; Label* mFrameTimeLabel;
Label* mUpdatePhysicsTimeLabel; Label* mPhysicsTimeLabel;
std::vector<CheckBox*> mCheckboxesScenes; std::vector<CheckBox*> mCheckboxesScenes;

View File

@ -51,7 +51,7 @@ const float TestbedApplication::SCROLL_SENSITIVITY = 0.02f;
TestbedApplication::TestbedApplication(bool isFullscreen) TestbedApplication::TestbedApplication(bool isFullscreen)
: Screen(Vector2i(1280, 760), "Testbed ReactPhysics3D", true, isFullscreen), : Screen(Vector2i(1280, 760), "Testbed ReactPhysics3D", true, isFullscreen),
mIsInitialized(false), mFPS(0), mNbFrames(0), mPreviousTime(0), mIsInitialized(false), mFPS(0), mNbFrames(0), mPreviousTime(0),
mUpdateTime(0), mPhysicsUpdateTime(0), mGui(this) { mLastTimeComputedFPS(0), mFrameTime(0), mPhysicsTime(0), mGui(this) {
mCurrentScene = NULL; mCurrentScene = NULL;
mIsMultisamplingActive = true; mIsMultisamplingActive = true;
@ -61,10 +61,12 @@ TestbedApplication::TestbedApplication(bool isFullscreen)
mSinglePhysicsStepDone = false; mSinglePhysicsStepDone = false;
mWindowToFramebufferRatio = Vector2(1, 1); mWindowToFramebufferRatio = Vector2(1, 1);
mIsShadowMappingEnabled = true; mIsShadowMappingEnabled = true;
mIsVSyncEnabled = true; mIsVSyncEnabled = false;
mIsContactPointsDisplayed = false; mIsContactPointsDisplayed = false;
init(); init();
resizeEvent(Vector2i(0, 0));
} }
// Destructor // Destructor
@ -72,12 +74,6 @@ TestbedApplication::~TestbedApplication() {
// Destroy all the scenes // Destroy all the scenes
destroyScenes(); destroyScenes();
// Destroy the window
//glfwDestroyWindow(mWindow);
// Terminate GLFW
//glfwTerminate();
} }
// Initialize the viewer // Initialize the viewer
@ -184,7 +180,7 @@ void TestbedApplication::update() {
} }
// Compute the physics update time // Compute the physics update time
mPhysicsUpdateTime = glfwGetTime() - currentTime; mPhysicsTime = glfwGetTime() - currentTime;
// Compute the interpolation factor // Compute the interpolation factor
float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep); float factor = mTimer.computeInterpolationFactor(mEngineSettings.timeStep);
@ -205,8 +201,6 @@ void TestbedApplication::update() {
void TestbedApplication::drawContents() { void TestbedApplication::drawContents() {
resizeEvent(Vector2i(0, 0));
update(); update();
int bufferWidth, bufferHeight; int bufferWidth, bufferHeight;
@ -219,16 +213,13 @@ void TestbedApplication::drawContents() {
// Render the scene // Render the scene
mCurrentScene->render(); mCurrentScene->render();
// Display the GUI
//Gui::getInstance().render();
// Compute the current framerate
computeFPS();
mGui.update(); mGui.update();
// Check the OpenGL errors // Check the OpenGL errors
checkOpenGLErrors(); checkOpenGLErrors();
// Compute the current framerate
computeFPS();
} }
/// Window resize event handler /// Window resize event handler
@ -251,12 +242,6 @@ bool TestbedApplication::resizeEvent(const Vector2i& size) {
return true; return true;
} }
// Set the dimension of the camera viewport
void TestbedApplication::reshape() {
}
// Change the current scene // Change the current scene
void TestbedApplication::switchScene(Scene* newScene) { void TestbedApplication::switchScene(Scene* newScene) {
@ -271,6 +256,8 @@ void TestbedApplication::switchScene(Scene* newScene) {
// Reset the scene // Reset the scene
mCurrentScene->reset(); mCurrentScene->reset();
resizeEvent(Vector2i(0, 0));
} }
// Check the OpenGL errors // Check the OpenGL errors
@ -310,22 +297,24 @@ void TestbedApplication::computeFPS() {
mCurrentTime = glfwGetTime(); mCurrentTime = glfwGetTime();
// Calculate time passed // Calculate time passed
mUpdateTime = mCurrentTime - mPreviousTime; mFrameTime = mCurrentTime - mPreviousTime;
double timeInterval = mUpdateTime * 1000.0; double timeInterval = (mCurrentTime - mLastTimeComputedFPS) * 1000.0;
// Update the FPS counter each second // Update the FPS counter each second
if(timeInterval > 0.0001) { if(timeInterval > 1000) {
// calculate the number of frames per second // calculate the number of frames per second
mFPS = static_cast<double>(mNbFrames) / timeInterval; mFPS = static_cast<double>(mNbFrames) / timeInterval;
mFPS *= 1000.0; mFPS *= 1000.0;
// Set time
mPreviousTime = mCurrentTime;
// Reset frame count // Reset frame count
mNbFrames = 0; mNbFrames = 0;
mLastTimeComputedFPS = mCurrentTime;
} }
// Set time
mPreviousTime = mCurrentTime;
} }
// GLFW error callback method // GLFW error callback method

View File

@ -80,11 +80,14 @@ class TestbedApplication : public Screen {
/// Previous time for fps computation (in seconds) /// Previous time for fps computation (in seconds)
double mPreviousTime; double mPreviousTime;
/// Last time the FPS have been computed
double mLastTimeComputedFPS;
/// Update time (in seconds) /// Update time (in seconds)
double mUpdateTime; double mFrameTime;
/// Physics update time (in seconds) /// Physics update time (in seconds)
double mPhysicsUpdateTime; double mPhysicsTime;
/// True if multisampling is active /// True if multisampling is active
bool mIsMultisamplingActive; bool mIsMultisamplingActive;
@ -126,9 +129,6 @@ class TestbedApplication : public Screen {
/// Update the simulation by taking a single physics step /// Update the simulation by taking a single physics step
void updateSinglePhysicsStep(); void updateSinglePhysicsStep();
/// Called when the windows is reshaped
void reshape();
/// Check the OpenGL errors /// Check the OpenGL errors
static void checkOpenGLErrorsInternal(const char* file, int line); static void checkOpenGLErrorsInternal(const char* file, int line);
@ -275,13 +275,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