+ option to disable navi cube

+ handle destruction of GL context in 3d viewer class
+ fix for OpenGL error message: 'Texture is not valid in the current context. Texture has not been destroyed'
This commit is contained in:
wmayer
2018-05-26 15:32:54 +02:00
parent 322cb29f64
commit 3b4ab88844
9 changed files with 105 additions and 7 deletions

View File

@@ -49,6 +49,22 @@
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_NaviCube">
<property name="text">
<string>Show navigation cube</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowNaviCube</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="CheckBox_useVBO">
<property name="text">
@@ -528,6 +544,7 @@
<tabstops>
<tabstop>CheckBox_CornerCoordSystem</tabstop>
<tabstop>CheckBox_ShowFPS</tabstop>
<tabstop>CheckBox_NaviCube</tabstop>
<tabstop>CheckBox_useVBO</tabstop>
<tabstop>CheckBox_UseAutoRotation</tabstop>
<tabstop>comboNavigationStyle</tabstop>

View File

@@ -86,6 +86,7 @@ void DlgSettings3DViewImp::saveSettings()
CheckBox_CornerCoordSystem->onSave();
CheckBox_ShowFPS->onSave();
CheckBox_useVBO->onSave();
CheckBox_NaviCube->onSave();
CheckBox_UseAutoRotation->onSave();
FloatSpinBox_EyeDistance->onSave();
checkBoxBacklight->onSave();
@@ -103,6 +104,7 @@ void DlgSettings3DViewImp::loadSettings()
CheckBox_CornerCoordSystem->onRestore();
CheckBox_ShowFPS->onRestore();
CheckBox_useVBO->onRestore();
CheckBox_NaviCube->onRestore();
CheckBox_UseAutoRotation->onRestore();
FloatSpinBox_EyeDistance->onRestore();
checkBoxBacklight->onRestore();

View File

@@ -253,6 +253,7 @@ public:
bool m_MouseDown = false;
bool m_Dragging = false;
bool m_MightDrag = false;
NaviCube::Corner m_Corner = NaviCube::TopRightCorner;
QtGLFramebufferObject* m_PickingFramebuffer;
@@ -287,6 +288,9 @@ bool NaviCube::processSoEvent(const SoEvent* ev) {
return m_NaviCubeImplementation->processSoEvent(ev);
}
void NaviCube::setCorner(Corner c) {
m_NaviCubeImplementation->m_Corner = c;
}
NaviCubeImplementation::NaviCubeImplementation(
Gui::View3DInventorViewer* viewer) {
@@ -748,8 +752,24 @@ void NaviCubeImplementation::handleResize() {
m_CubeWidgetPosY = view[1] - (m_PrevHeight - m_CubeWidgetPosY);
}
else { // initial position
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
switch (m_Corner) {
case NaviCube::TopLeftCorner:
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
break;
case NaviCube::TopRightCorner:
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
break;
case NaviCube::BottomLeftCorner:
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
break;
case NaviCube::BottomRightCorner:
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
break;
}
}
m_PrevWidth = view[0];
m_PrevHeight = view[1];

View File

@@ -35,10 +35,17 @@ class NaviCubeImplementation;
class NaviCube {
public:
enum Corner {
TopLeftCorner,
TopRightCorner,
BottomLeftCorner,
BottomRightCorner
};
NaviCube(Gui::View3DInventorViewer* viewer) ;
virtual ~NaviCube();
void drawNaviCube();
bool processSoEvent(const SoEvent* ev);
void setCorner(Corner);
private:
NaviCubeImplementation* m_NaviCubeImplementation;
};

View File

@@ -98,6 +98,7 @@
#if QT_VERSION >= 0x050000
#include <QWindow>
#include <QGuiApplication>
#include <QMetaObject>
#endif
@@ -168,8 +169,8 @@ public:
}
void initializeGL()
{
#if defined (_DEBUG) && 0
QOpenGLContext *context = QOpenGLContext::currentContext();
#if defined (_DEBUG) && 0
if (context && context->hasExtension(QByteArrayLiteral("GL_KHR_debug"))) {
QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
connect(logger, &QOpenGLDebugLogger::messageLogged, this, &CustomGLWidget::handleLoggedMessage);
@@ -178,8 +179,18 @@ public:
logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
#endif
if (context) {
connect(context, &QOpenGLContext::aboutToBeDestroyed,
this, &CustomGLWidget::aboutToDestroyGLContext, Qt::DirectConnection);
}
connect(this, &CustomGLWidget::resized, this, &CustomGLWidget::slotResized);
}
void aboutToDestroyGLContext()
{
QMetaObject::invokeMethod(parent(), "aboutToDestroyGLContext",
Qt::DirectConnection,
QGenericReturnArgument());
}
bool event(QEvent *e)
{
// If a debug logger is activated then Qt's default implementation
@@ -315,6 +326,11 @@ QuarterWidget::replaceViewport()
#endif
}
void
QuarterWidget::aboutToDestroyGLContext()
{
}
/*! destructor */
QuarterWidget::~QuarterWidget()
{

View File

@@ -191,6 +191,7 @@ Q_SIGNALS:
private Q_SLOTS:
void replaceViewport();
virtual void aboutToDestroyGLContext();
protected:
virtual void paintEvent(QPaintEvent*);

View File

@@ -168,6 +168,7 @@ View3DInventor::View3DInventor(Gui::Document* pcDocument, QWidget* parent,
OnChange(*hGrp,"BackgroundColor4");
OnChange(*hGrp,"UseBackgroundColorMid");
OnChange(*hGrp,"ShowFPS");
OnChange(*hGrp,"ShowNaviCube");
OnChange(*hGrp,"UseVBO");
OnChange(*hGrp,"Orthographic");
OnChange(*hGrp,"HeadlightColor");
@@ -361,6 +362,9 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
else if (strcmp(Reason,"ShowFPS") == 0) {
_viewer->setEnabledFPSCounter(rGrp.GetBool("ShowFPS",false));
}
else if (strcmp(Reason,"ShowNaviCube") == 0) {
_viewer->setEnabledNaviCube(rGrp.GetBool("ShowNaviCube",true));
}
else if (strcmp(Reason,"UseVBO") == 0) {
_viewer->setEnabledVBO(rGrp.GetBool("UseVBO",false));
}

View File

@@ -120,6 +120,7 @@
#include <Quarter/eventhandlers/EventFilter.h>
#include <Quarter/devices/InputDevice.h>
#include "View3DViewerPy.h"
#include <Gui/NaviCube.h>
#include <Inventor/draggers/SoCenterballDragger.h>
#include <Inventor/annex/Profiler/SoProfiler.h>
@@ -533,11 +534,14 @@ void View3DInventorViewer::init()
mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap);
panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y);
naviCube = new NaviCube(this);
naviCubeEnabled = true;
}
View3DInventorViewer::~View3DInventorViewer()
{
delete naviCube;
// to prevent following OpenGL error message: "Texture is not valid in the current context. Texture has not been destroyed"
aboutToDestroyGLContext();
// cleanup
this->backgroundroot->unref();
this->backgroundroot = 0;
@@ -571,6 +575,18 @@ View3DInventorViewer::~View3DInventorViewer()
}
}
void View3DInventorViewer::aboutToDestroyGLContext()
{
if (naviCube) {
QtGLWidget* gl = qobject_cast<QtGLWidget*>(this->viewport());
if (gl)
gl->makeCurrent();
delete naviCube;
naviCube = 0;
naviCubeEnabled = false;
}
}
void View3DInventorViewer::setDocument(Gui::Document* pcDocument)
{
// write the document the viewer belongs to to the selection node
@@ -823,6 +839,16 @@ bool View3DInventorViewer::isEnabledVBO() const
return vboEnabled;
}
void View3DInventorViewer::setEnabledNaviCube(bool on)
{
naviCubeEnabled = on;
}
bool View3DInventorViewer::isEnabledNaviCube(void) const
{
return naviCubeEnabled;
}
void View3DInventorViewer::setAxisCross(bool on)
{
SoNode* scene = getSceneGraph();
@@ -1733,7 +1759,8 @@ void View3DInventorViewer::renderScene(void)
draw2DString(stream.str().c_str(), SbVec2s(10,10), SbVec2f(0.1f,0.1f));
}
naviCube->drawNaviCube();
if (naviCubeEnabled)
naviCube->drawNaviCube();
#if 0 // this breaks highlighting of edges
glEnable(GL_LIGHTING);
@@ -1816,7 +1843,7 @@ void View3DInventorViewer::selectAll()
bool View3DInventorViewer::processSoEvent(const SoEvent* ev)
{
if (naviCube->processSoEvent(ev))
if (naviCubeEnabled && naviCube->processSoEvent(ev))
return true;
if (isRedirectedToSceneGraph()) {
SbBool processed = inherited::processSoEvent(ev);

View File

@@ -38,7 +38,6 @@
#include <QImage>
#include <Gui/Selection.h>
#include <Gui/NaviCube.h>
class SoTranslation;
class SoTransform;
@@ -55,6 +54,7 @@ class SbBox2s;
class SoVectorizeAction;
class QImage;
class SoGroup;
class NaviCube;
namespace Gui {
@@ -344,6 +344,8 @@ public:
bool hasAxisCross(void);
void setEnabledFPSCounter(bool b);
void setEnabledNaviCube(bool b);
bool isEnabledNaviCube(void) const;
void setEnabledVBO(bool b);
bool isEnabledVBO() const;
@@ -395,6 +397,7 @@ private:
void drawAxisCross(void);
static void drawArrow(void);
void setCursorRepresentation(int mode);
void aboutToDestroyGLContext();
private:
NaviCube* naviCube;
@@ -428,6 +431,7 @@ private:
//stuff needed to draw the fps counter
bool fpsEnabled;
bool vboEnabled;
SbBool naviCubeEnabled;
SbBool editing;
QCursor editCursor, zoomCursor, panCursor, spinCursor;