Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:15:50

0001 // Copyright (c) 2018 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Graphic3d_FrameStatsData_HeaderFile
0015 #define _Graphic3d_FrameStatsData_HeaderFile
0016 
0017 #include <NCollection_Array1.hxx>
0018 #include <Graphic3d_FrameStatsCounter.hxx>
0019 #include <Graphic3d_FrameStatsTimer.hxx>
0020 #include <OSD_Timer.hxx>
0021 #include <NCollection_LinearVector.hxx>
0022 
0023 //! Data frame definition.
0024 class Graphic3d_FrameStatsData
0025 {
0026 public:
0027   DEFINE_STANDARD_ALLOC
0028 
0029   //! Returns FPS (frames per seconds, elapsed time).
0030   //! This number indicates an actual frame rate averaged for several frames within UpdateInterval()
0031   //! duration, basing on a real elapsed time between updates.
0032   double FrameRate() const { return myFps; }
0033 
0034   //! Returns CPU FPS (frames per seconds, CPU time).
0035   //! This number indicates a PREDICTED frame rate,
0036   //! basing on CPU elapsed time between updates and NOT real elapsed time (which might include
0037   //! periods of CPU inactivity). Number is expected to be greater then actual frame rate returned
0038   //! by FrameRate(). Values significantly greater actual frame rate indicate that rendering is
0039   //! limited by GPU performance (CPU is stalled in-between), while values around actual frame rate
0040   //! indicate rendering being limited by CPU performance (GPU is stalled in-between).
0041   double FrameRateCpu() const { return myFpsCpu; }
0042 
0043   //! Returns FPS for immediate redraws.
0044   double ImmediateFrameRate() const { return myFpsImmediate; }
0045 
0046   //! Returns CPU FPS for immediate redraws.
0047   double ImmediateFrameRateCpu() const { return myFpsCpuImmediate; }
0048 
0049   //! Get counter value.
0050   size_t CounterValue(Graphic3d_FrameStatsCounter theIndex) const { return myCounters[theIndex]; }
0051 
0052   //! Get counter value.
0053   size_t operator[](Graphic3d_FrameStatsCounter theIndex) const { return CounterValue(theIndex); }
0054 
0055   //! Get timer value.
0056   double TimerValue(Graphic3d_FrameStatsTimer theIndex) const { return myTimers[theIndex]; }
0057 
0058   //! Get timer value.
0059   double operator[](Graphic3d_FrameStatsTimer theIndex) const { return TimerValue(theIndex); }
0060 
0061   //! Empty constructor.
0062   Standard_EXPORT Graphic3d_FrameStatsData();
0063 
0064   //! Copy constructor.
0065   Standard_EXPORT Graphic3d_FrameStatsData(const Graphic3d_FrameStatsData& theOther);
0066 
0067   //! Move constructor.
0068   Standard_EXPORT Graphic3d_FrameStatsData(Graphic3d_FrameStatsData&& theOther) noexcept;
0069 
0070   //! Assignment operator.
0071   Standard_EXPORT Graphic3d_FrameStatsData& operator=(const Graphic3d_FrameStatsData& theOther);
0072 
0073   //! Assignment with move operator.
0074   Standard_EXPORT Graphic3d_FrameStatsData& operator=(Graphic3d_FrameStatsData&& theOther) noexcept;
0075 
0076   //! Reset data.
0077   Standard_EXPORT void Reset();
0078 
0079   //! Fill with maximum values.
0080   Standard_EXPORT void FillMax(const Graphic3d_FrameStatsData& theOther);
0081 
0082 protected:
0083   NCollection_LinearVector<size_t> myCounters;  //!< counters
0084   NCollection_LinearVector<double> myTimers;    //!< timers
0085   NCollection_LinearVector<double> myTimersMin; //!< minimal values of timers
0086   NCollection_LinearVector<double> myTimersMax; //!< maximum values of timers
0087   double                           myFps;    //!< FPS     meter (frames per seconds, elapsed time)
0088   double                           myFpsCpu; //!< CPU FPS meter (frames per seconds, CPU time)
0089   double                           myFpsImmediate;    //!< FPS     meter for immediate redraws
0090   double                           myFpsCpuImmediate; //!< CPU FPS meter for immediate redraws
0091 };
0092 
0093 //! Temporary data frame definition.
0094 class Graphic3d_FrameStatsDataTmp : public Graphic3d_FrameStatsData
0095 {
0096 public:
0097   //! Empty constructor.
0098   Standard_EXPORT Graphic3d_FrameStatsDataTmp();
0099 
0100   //! Compute average data considering the amount of rendered frames.
0101   Standard_EXPORT void FlushTimers(size_t theNbFrames, bool theIsFinal);
0102 
0103   //! Reset data.
0104   Standard_EXPORT void Reset();
0105 
0106   //! Assignment operator (skip copying irrelevant properties).
0107   void operator=(const Graphic3d_FrameStatsData& theOther)
0108   {
0109     Graphic3d_FrameStatsData::operator=(theOther);
0110   }
0111 
0112   //! Returns FPS (frames per seconds, elapsed time).
0113   double& ChangeFrameRate() { return myFps; }
0114 
0115   //! Returns CPU FPS (frames per seconds, CPU time).
0116   double& ChangeFrameRateCpu() { return myFpsCpu; }
0117 
0118   //! Returns FPS for immediate redraws.
0119   double& ChangeImmediateFrameRate() { return myFpsImmediate; }
0120 
0121   //! Returns CPU FPS for immediate redraws.
0122   double& ChangeImmediateFrameRateCpu() { return myFpsCpuImmediate; }
0123 
0124   //! Return a timer object for time measurements.
0125   OSD_Timer& ChangeTimer(Graphic3d_FrameStatsTimer theTimer) { return myOsdTimers[theTimer]; }
0126 
0127   //! Get counter value.
0128   size_t& ChangeCounterValue(Graphic3d_FrameStatsCounter theIndex) { return myCounters[theIndex]; }
0129 
0130   //! Modify counter value.
0131   size_t& operator[](Graphic3d_FrameStatsCounter theIndex) { return ChangeCounterValue(theIndex); }
0132 
0133   //! Modify timer value.
0134   double& ChangeTimerValue(Graphic3d_FrameStatsTimer theIndex) { return myTimers[theIndex]; }
0135 
0136   //! Modify timer value.
0137   double& operator[](Graphic3d_FrameStatsTimer theIndex) { return ChangeTimerValue(theIndex); }
0138 
0139 protected:
0140   NCollection_LinearVector<OSD_Timer> myOsdTimers;  //!< precise timers for time measurements
0141   NCollection_LinearVector<double>    myTimersPrev; //!< previous timers values
0142 };
0143 
0144 #endif // _Graphic3d_FrameStatsData_HeaderFile