-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve fps counter #1886
Merged
Merged
Improve fps counter #1886
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1a834a6
Added auto averaging fps counter to vtk ui actor class
GabrielNakamoto fa483f2
Added RENDER_UI_ONLY check when updating ui fps counter
GabrielNakamoto 42bc7e4
Changed UpdateFpsValue() in vtk UI actor class to use a deque for a s…
GabrielNakamoto e42a67c
Fixed elapsed time argument name, shouldn't be microseconds
GabrielNakamoto 447a9c0
Added variable to track total frame time and used it to average the m…
GabrielNakamoto 9ba0170
Added fps counter test file, removed unnecessary include
GabrielNakamoto 4666687
Changed tabs to spaces, style changes
GabrielNakamoto 78a67bb
Indentation fix
GabrielNakamoto fd30857
More indentation changes
GabrielNakamoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <vtkNew.h> | ||
#include <vtkObjectFactory.h> | ||
|
||
#include "vtkF3DUIActor.h" | ||
|
||
#include <iostream> | ||
|
||
// subclass to retrieve internal protected values | ||
class vtkF3DTestUIActor : public vtkF3DUIActor | ||
{ | ||
public: | ||
static vtkF3DTestUIActor* New(); | ||
vtkTypeMacro(vtkF3DTestUIActor, vtkF3DUIActor); | ||
|
||
size_t GetNumberOfFrameTimes() { return this->FrameTimes.size(); } | ||
double GetTotalFrameTimes() { return this->TotalFrameTimes; } | ||
int GetFpsValue() { return this->FpsValue; } | ||
}; | ||
|
||
vtkObjectFactoryNewMacro(vtkF3DTestUIActor); | ||
|
||
int TestF3DFpsCounter(int argc, char* argv[]) | ||
{ | ||
vtkNew<vtkF3DTestUIActor> uiActor; | ||
|
||
// add 1000 frames at 0.01s | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
uiActor->UpdateFpsValue(0.01); | ||
} | ||
|
||
// make sure only the 100 last records are kept | ||
if (uiActor->GetNumberOfFrameTimes() > 100) | ||
{ | ||
std::cerr << "Number of frame times must be at most 100" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// make sure only the total time kept doesn't exceed 1 second | ||
if (uiActor->GetTotalFrameTimes() > 1.0) | ||
{ | ||
std::cerr << "Number of total frame times must be at most 1.0" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// make sure the FPS value is exactly 100 | ||
if (uiActor->GetFpsValue() != 100) | ||
{ | ||
std::cerr << "Number of FPS value must be exactly 100" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1541,20 +1541,26 @@ void vtkF3DRenderer::Render() | |||||||||||||
|
||||||||||||||
auto cpuElapsed = std::chrono::high_resolution_clock::now() - cpuStart; | ||||||||||||||
|
||||||||||||||
// Get CPU frame per seconds | ||||||||||||||
int fps = static_cast<int>(std::round( | ||||||||||||||
1.0 / (std::chrono::duration_cast<std::chrono::microseconds>(cpuElapsed).count() * 1e-6))); | ||||||||||||||
vtkInformation *info = this->GetInformation(); | ||||||||||||||
|
||||||||||||||
bool uiOnly = info->Get(vtkF3DRenderPass::RENDER_UI_ONLY()); | ||||||||||||||
|
||||||||||||||
if (!uiOnly) | ||||||||||||||
{ | ||||||||||||||
// Get CPU frame time | ||||||||||||||
double elapsedTime = std::chrono::duration_cast<std::chrono::microseconds>(cpuElapsed).count() * 1e-6; | ||||||||||||||
|
||||||||||||||
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) | ||||||||||||||
glEndQuery(GL_TIME_ELAPSED); | ||||||||||||||
GLint elapsed; | ||||||||||||||
glGetQueryObjectiv(this->Timer, GL_QUERY_RESULT, &elapsed); | ||||||||||||||
glEndQuery(GL_TIME_ELAPSED); | ||||||||||||||
GLint elapsed; | ||||||||||||||
glGetQueryObjectiv(this->Timer, GL_QUERY_RESULT, &elapsed); | ||||||||||||||
mwestphal marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+1554
to
+1556
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
// Get min between CPU frame per seconds and GPU frame per seconds | ||||||||||||||
fps = std::min(fps, static_cast<int>(std::round(1.0 / (elapsed * 1e-9)))); | ||||||||||||||
// Get min between CPU frame time and GPU frame time | ||||||||||||||
elapsedTime = std::min(elapsedTime, elapsed * 1e-9); | ||||||||||||||
mwestphal marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+1558
to
+1559
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
#endif | ||||||||||||||
|
||||||||||||||
this->UIActor->SetFpsValue(fps); | ||||||||||||||
this->UIActor->UpdateFpsValue(elapsedTime); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
//---------------------------------------------------------------------------- | ||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.