@@ -537,7 +537,7 @@ class ExampleMetaballs : public entry::AppI
537537 m_program = bgfx::createProgram (vsh, fsh, true /* destroy shaders when program is destroyed */ );
538538
539539 m_grid = new Grid[kMaxDims *kMaxDims *kMaxDims ];
540- m_timeOffset = bx::getHPCounter ();
540+ m_frameTime. reset ();
541541
542542 imguiCreate ();
543543 }
@@ -564,6 +564,9 @@ class ExampleMetaballs : public entry::AppI
564564
565565 if (!entry::processEvents (m_width, m_height, m_debug, m_reset, &m_mouseState) )
566566 {
567+ m_frameTime.frame ();
568+ const float time = bx::toSeconds<float >(m_frameTime.getDurationTime () );
569+
567570 imguiBeginFrame (m_mouseState.m_mx
568571 , m_mouseState.m_my
569572 , (m_mouseState.m_buttons [entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0 )
@@ -606,14 +609,6 @@ class ExampleMetaballs : public entry::AppI
606609 // if no other draw calls are submitted to view 0.
607610 bgfx::touch (0 );
608611
609- int64_t now = bx::getHPCounter ();
610- static int64_t last = now;
611- const int64_t frameTime = now - last;
612- last = now;
613- const double freq = double (bx::getHPFrequency () );
614- const double toMs = 1000.0 /freq;
615- float time = (float )( (now - m_timeOffset)/double (bx::getHPFrequency () ) );
616-
617612 const bx::Vec3 at = { 0 .0f , 0 .0f , 0 .0f };
618613 const bx::Vec3 eye = { 0 .0f , 0 .0f , -50 .0f };
619614
@@ -632,9 +627,9 @@ class ExampleMetaballs : public entry::AppI
632627
633628 // Stats.
634629 uint32_t numVertices = 0 ;
635- int64_t profUpdate = 0 ;
636- int64_t profNormal = 0 ;
637- int64_t profTriangulate = 0 ;
630+ bx::Ticks profUpdate = bx::InitZero ;
631+ bx::Ticks profNormal = bx::InitZero ;
632+ bx::Ticks profTriangulate = bx::InitZero ;
638633
639634 // Allocate 32K vertices in transient vertex buffer.
640635 uint32_t maxVertices = (32 <<10 );
@@ -651,7 +646,7 @@ class ExampleMetaballs : public entry::AppI
651646 sphere[ii][3 ] = 1 .0f /(3 .0f + (bx::sin (time*(ii*0 .13f ) )*0 .5f +0 .5f )*0 .9f );
652647 }
653648
654- profUpdate = bx::getHPCounter ();
649+ profUpdate = bx::getNow ();
655650
656651 for (uint32_t zz = 0 ; zz < numDims; ++zz)
657652 {
@@ -685,9 +680,9 @@ class ExampleMetaballs : public entry::AppI
685680 }
686681 }
687682
688- profUpdate = bx::getHPCounter () - profUpdate;
683+ profUpdate = bx::getNow () - profUpdate;
689684
690- profNormal = bx::getHPCounter ();
685+ profNormal = bx::getNow ();
691686
692687 for (uint32_t zz = 1 ; zz < numDims-1 ; ++zz)
693688 {
@@ -712,9 +707,9 @@ class ExampleMetaballs : public entry::AppI
712707 }
713708 }
714709
715- profNormal = bx::getHPCounter () - profNormal;
710+ profNormal = bx::getNow () - profNormal;
716711
717- profTriangulate = bx::getHPCounter ();
712+ profTriangulate = bx::getNow ();
718713
719714 PosNormalColorVertex* vertex = (PosNormalColorVertex*)tvb.data ;
720715
@@ -772,7 +767,7 @@ class ExampleMetaballs : public entry::AppI
772767 }
773768 }
774769
775- profTriangulate = bx::getHPCounter () - profTriangulate;
770+ profTriangulate = bx::getNow () - profTriangulate;
776771
777772 float mtx[16 ];
778773 bx::mtxRotateXY (mtx, time*0 .67f , time);
@@ -804,10 +799,10 @@ class ExampleMetaballs : public entry::AppI
804799 );
805800
806801 ImGui::Text (" Num vertices:" ); ImGui::SameLine (100 ); ImGui::Text (" %5d (%6.4f%%)" , numVertices, float (numVertices)/maxVertices * 100 );
807- ImGui::Text (" Update:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , double (profUpdate)*toMs );
808- ImGui::Text (" Calc normals:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , double (profNormal)*toMs );
809- ImGui::Text (" Triangulate:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , double (profTriangulate)*toMs );
810- ImGui::Text (" Frame:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , double (frameTime)*toMs );
802+ ImGui::Text (" Update:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , bx::toMilliseconds< double > (profUpdate) );
803+ ImGui::Text (" Calc normals:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , bx::toMilliseconds< double > (profNormal) );
804+ ImGui::Text (" Triangulate:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , bx::toMilliseconds< double > (profTriangulate) );
805+ ImGui::Text (" Frame:" ); ImGui::SameLine (100 ); ImGui::Text (" % 7.3f[ms]" , bx::toMilliseconds< double >(m_frameTime. getDeltaTime () ) );
811806
812807 ImGui::End ();
813808
@@ -832,7 +827,8 @@ class ExampleMetaballs : public entry::AppI
832827 bgfx::ProgramHandle m_program;
833828
834829 Grid* m_grid;
835- int64_t m_timeOffset;
830+
831+ FrameTime m_frameTime;
836832};
837833
838834} // namespace
0 commit comments