Skip to content

Commit

Permalink
IMGUI BorderNode Fix
Browse files Browse the repository at this point in the history
**JIRA Issue:** Fixes SIM-15143

**Description:** No longer relying on a size comparison to confirm that mainview/superhud should resize, and instead relying on the graphics context of the window sending the resize event. This fixes a bug in Basic Viewer where the border node is incorrectly placed after a resize, if using IMGUI.

**Notes:** Using the size to compare works only when we know the exact size, and it was a shortcut to just comparing graphics contexts.

**Testing Performed:** BasicViewer with and without IMGUI, creating inset then resizing view. SIMDIS with an inset and resizing, no problems before or after. Also tested with Qt View Manager Model test, where we have multiple graphics contexts.
  • Loading branch information
Daniel Emminizer committed Feb 24, 2023
1 parent bd33658 commit ead1470
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
20 changes: 9 additions & 11 deletions SDK/simVis/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BorderNode : public osg::Geode
{
setName("Border Node");
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
geom->setName("simVis::BorderNode Goemetry");
geom->setName("simVis::BorderNode Geometry");
geom->setUseVertexBufferObjects(true);
geom->setDataVariance(osg::Object::DYNAMIC);

Expand Down Expand Up @@ -1005,16 +1005,14 @@ void View::processResize(int width, int height)

// limit the resize processing to the main view that has same height/width as the event report
const osg::Viewport* vp = getCamera()->getViewport();
if (vp && width == vp->width() && height == vp->height())
{
// this is the main view that the resize event was for. Make sure the width and height are
// positive values, else the projection and view matrix gets broken. This can happen in rare
// cases on Linux, NVIDIA driver, Qt 5.9 with osgQt, with external display on laptop where
// the external display is marked primary display. Since this is such a specific use case,
// it's hard to know if there are other cases where the problem shows up, so we just always
// force the width and height to be valid.
setExtents(Extents(this->extents_.x_, this->extents_.y_, simCore::sdkMax(1, width), simCore::sdkMax(1, height)));
}

// this is the main view (or superhud) that the resize event was for. Make sure the width and height
// are positive values, else the projection and view matrix gets broken. This can happen in rare
// cases on Linux, NVIDIA driver, Qt 5.9 with osgQt, with external display on laptop where
// the external display is marked primary display. Since this is such a specific use case,
// it's hard to know if there are other cases where the problem shows up, so we just always
// force the width and height to be valid.
setExtents(Extents(this->extents_.x_, this->extents_.y_, simCore::sdkMax(1, width), simCore::sdkMax(1, height)));
}

void View::setViewManager(simVis::ViewManager* viewman)
Expand Down
8 changes: 5 additions & 3 deletions SDK/simVis/ViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ namespace
// wait until subsequent frame event to resize
else if (resizeView_ && ea.getEventType() == osgGA::GUIEventAdapter::FRAME && aa.asView() == resizeView_)
{
viewMan_->handleResize(width_, height_);
const osg::Camera* camera = resizeView_->getCamera();
viewMan_->handleResize(camera ? camera->getGraphicsContext() : nullptr, width_, height_);
aa.requestRedraw();
resizeView_ = nullptr;
}
Expand Down Expand Up @@ -372,13 +373,14 @@ void ViewManager::sendPostCameraFrameNotifications_()
}
}

void ViewManager::handleResize(int newwidth, int newheight)
void ViewManager::handleResize(const osg::GraphicsContext* gc, int newwidth, int newheight)
{
unsigned int numViews = getNumViews();
for (unsigned int i = 0; i < numViews; ++i)
{
simVis::View* view = getView(i);
if (view)
// Limit processResize() to views that share the same graphics context
if (view && view->getCamera() && view->getCamera()->getGraphicsContext() == gc)
view->processResize(newwidth, newheight);
}
}
Expand Down
4 changes: 3 additions & 1 deletion SDK/simVis/ViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "osgViewer/CompositeViewer"
#include "simCore/Common/Common.h"

namespace osg { class GraphicsContext; }

namespace simVis
{

Expand Down Expand Up @@ -149,7 +151,7 @@ class SDKVIS_EXPORT ViewManager : public osg::Referenced
void removeView(simVis::View* view);

/** Resizes all of the managed views */
void handleResize(int newwidth, int newheight);
void handleResize(const osg::GraphicsContext* gc, int newwidth, int newheight);

/** Gets a list of the managed views. Includes top level and inset views. */
void getViews(std::vector<simVis::View*>& out_views) const;
Expand Down

0 comments on commit ead1470

Please sign in to comment.