From cbde4c90da3a0b2607afb20ce0f29010c175a7ac Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Sun, 20 Jan 2019 23:30:46 +0100 Subject: [PATCH] optimise property usage for camera using local static for ratio. --- src/Viewer/PUICamera.cxx | 15 ++++++++------- src/Viewer/PUICamera.hxx | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Viewer/PUICamera.cxx b/src/Viewer/PUICamera.cxx index cee1b03ae..e8f65858c 100644 --- a/src/Viewer/PUICamera.cxx +++ b/src/Viewer/PUICamera.cxx @@ -90,6 +90,8 @@ protected: #endif +double PUICamera::pixelRatio; + class PUIDrawable : public osg::Drawable { public: @@ -285,9 +287,8 @@ void PUICamera::puGetWindowSize(int* width, int* height) return; osg::Viewport* vport = camera->getViewport(); - const double ratio = fgGetDouble("/sim/rendering/gui-pixel-ratio", 1.0); - *width = static_cast(vport->width() / ratio); - *height = static_cast(vport->height() / ratio); + *width = static_cast(vport->width() / pixelRatio); + *height = static_cast(vport->height() / pixelRatio); } void PUICamera::initPUI() @@ -296,10 +297,10 @@ void PUICamera::initPUI() PUICamera::puGetWindowSize, nullptr); puRealInit(); } - PUICamera::PUICamera() : osg::Camera() { + pixelRatio = 1.0; } void PUICamera::init(osg::Group* parent) @@ -388,9 +389,9 @@ void PUICamera::manuallyResizeFBO(int width, int height) void PUICamera::resizeUi(int width, int height) { - double ratio = fgGetDouble("/sim/rendering/gui-pixel-ratio", 1.0); - const int scaledWidth = static_cast(width / ratio); - const int scaledHeight = static_cast(height / ratio); + pixelRatio = fgGetDouble("/sim/rendering/gui-pixel-ratio", 1.0); + const int scaledWidth = static_cast(width / pixelRatio); + const int scaledHeight = static_cast(height / pixelRatio); setViewport(0, 0, scaledWidth, scaledHeight); #if OSG_VERSION_LESS_THAN(3,4,0) diff --git a/src/Viewer/PUICamera.hxx b/src/Viewer/PUICamera.hxx index f3bdd7bee..5c6d90879 100644 --- a/src/Viewer/PUICamera.hxx +++ b/src/Viewer/PUICamera.hxx @@ -47,7 +47,7 @@ private: class UpdateViewportAndFBOAfterTextureResizeCallback; UpdateViewportAndFBOAfterTextureResizeCallback* _resizeCullCallback = nullptr; #endif - + static double pixelRatio; void manuallyResizeFBO(int width, int height); osg::Texture2D* _fboTexture = nullptr;