Skip to content

Commit f4f2565

Browse files
committed
Coding - group GL-related methods together, fix misprints in comments
1 parent 9f39b81 commit f4f2565

7 files changed

Lines changed: 219 additions & 219 deletions

File tree

occt-qopenglwidget/OcctQOpenGLWidgetViewer.cpp

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -111,64 +111,6 @@ OcctQOpenGLWidgetViewer::~OcctQOpenGLWidgetViewer()
111111
aDisp.Nullify();
112112
}
113113

114-
// ================================================================
115-
// Function : dumpGlInfo
116-
// ================================================================
117-
void OcctQOpenGLWidgetViewer::dumpGlInfo(bool theIsBasic, bool theToPrint)
118-
{
119-
TColStd_IndexedDataMapOfStringString aGlCapsDict;
120-
myView->DiagnosticInformation(aGlCapsDict,
121-
theIsBasic ? Graphic3d_DiagnosticInfo_Basic : Graphic3d_DiagnosticInfo_Complete);
122-
TCollection_AsciiString anInfo;
123-
for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter(aGlCapsDict); aValueIter.More(); aValueIter.Next())
124-
{
125-
if (!aValueIter.Value().IsEmpty())
126-
{
127-
if (!anInfo.IsEmpty())
128-
anInfo += "\n";
129-
130-
anInfo += aValueIter.Key() + ": " + aValueIter.Value();
131-
}
132-
}
133-
134-
if (theToPrint)
135-
Message::SendInfo(anInfo);
136-
137-
myGlInfo = QString::fromUtf8(anInfo.ToCString());
138-
}
139-
140-
// ================================================================
141-
// Function : initializeGL
142-
// ================================================================
143-
void OcctQOpenGLWidgetViewer::initializeGL()
144-
{
145-
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewer->Driver());
146-
OcctQtTools::qtGlCapsFromSurfaceFormat(aDriver->ChangeOptions(), format());
147-
148-
const Aspect_Drawable aNativeWin = (Aspect_Drawable)winId();
149-
const Graphic3d_Vec2i aViewSize(rect().right() - rect().left(), rect().bottom() - rect().top());
150-
151-
const bool isFirstInit = myView->Window().IsNull();
152-
if (!OcctGlTools::InitializeGlWindow(myView, aNativeWin, aViewSize, devicePixelRatioF()))
153-
{
154-
QMessageBox::critical(0, "Failure", "OpenGl_Context is unable to wrap OpenGL context");
155-
QApplication::exit(1);
156-
return;
157-
}
158-
159-
makeCurrent(); // restore Qt framebuffer
160-
dumpGlInfo(true, true);
161-
if (isFirstInit)
162-
{
163-
myContext->Display(myViewCube, 0, 0, false);
164-
165-
// dummy shape for testing
166-
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(100.0, 50.0, 90.0).Shape();
167-
Handle(AIS_Shape) aShape = new AIS_Shape(aBox);
168-
myContext->Display(aShape, AIS_Shaded, 0, false);
169-
}
170-
}
171-
172114
// ================================================================
173115
// Function : event
174116
// ================================================================
@@ -354,6 +296,87 @@ void OcctQOpenGLWidgetViewer::updateView()
354296
// if (window() != NULL) { window()->update(); }
355297
}
356298

299+
// ================================================================
300+
// Function : handleViewRedraw
301+
// ================================================================
302+
void OcctQOpenGLWidgetViewer::handleViewRedraw(const Handle(AIS_InteractiveContext)& theCtx,
303+
const Handle(V3d_View)& theView)
304+
{
305+
AIS_ViewController::handleViewRedraw(theCtx, theView);
306+
if (myToAskNextFrame)
307+
updateView(); // ask more frames for animation
308+
}
309+
310+
#if (OCC_VERSION_HEX >= 0x070700)
311+
// ================================================================
312+
// Function : OnSubviewChanged
313+
// ================================================================
314+
void OcctQOpenGLWidgetViewer::OnSubviewChanged(const Handle(AIS_InteractiveContext)&,
315+
const Handle(V3d_View)&,
316+
const Handle(V3d_View)& theNewView)
317+
{
318+
myFocusView = theNewView;
319+
}
320+
#endif
321+
322+
// ================================================================
323+
// Function : dumpGlInfo
324+
// ================================================================
325+
void OcctQOpenGLWidgetViewer::dumpGlInfo(bool theIsBasic, bool theToPrint)
326+
{
327+
TColStd_IndexedDataMapOfStringString aGlCapsDict;
328+
myView->DiagnosticInformation(aGlCapsDict,
329+
theIsBasic ? Graphic3d_DiagnosticInfo_Basic : Graphic3d_DiagnosticInfo_Complete);
330+
TCollection_AsciiString anInfo;
331+
for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter(aGlCapsDict); aValueIter.More(); aValueIter.Next())
332+
{
333+
if (!aValueIter.Value().IsEmpty())
334+
{
335+
if (!anInfo.IsEmpty())
336+
anInfo += "\n";
337+
338+
anInfo += aValueIter.Key() + ": " + aValueIter.Value();
339+
}
340+
}
341+
342+
if (theToPrint)
343+
Message::SendInfo(anInfo);
344+
345+
myGlInfo = QString::fromUtf8(anInfo.ToCString());
346+
}
347+
348+
// ================================================================
349+
// Function : initializeGL
350+
// ================================================================
351+
void OcctQOpenGLWidgetViewer::initializeGL()
352+
{
353+
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewer->Driver());
354+
OcctQtTools::qtGlCapsFromSurfaceFormat(aDriver->ChangeOptions(), format());
355+
356+
const Aspect_Drawable aNativeWin = (Aspect_Drawable)winId();
357+
const Graphic3d_Vec2i aViewSize(rect().right() - rect().left(), rect().bottom() - rect().top());
358+
359+
const bool isFirstInit = myView->Window().IsNull();
360+
if (!OcctGlTools::InitializeGlWindow(myView, aNativeWin, aViewSize, devicePixelRatioF()))
361+
{
362+
QMessageBox::critical(0, "Failure", "OpenGl_Context is unable to wrap OpenGL context");
363+
QApplication::exit(1);
364+
return;
365+
}
366+
367+
makeCurrent(); // restore Qt framebuffer
368+
dumpGlInfo(true, true);
369+
if (isFirstInit)
370+
{
371+
myContext->Display(myViewCube, 0, 0, false);
372+
373+
// dummy shape for testing
374+
TopoDS_Shape aBox = BRepPrimAPI_MakeBox(100.0, 50.0, 90.0).Shape();
375+
Handle(AIS_Shape) aShape = new AIS_Shape(aBox);
376+
myContext->Display(aShape, AIS_Shaded, 0, false);
377+
}
378+
}
379+
357380
// ================================================================
358381
// Function : paintGL
359382
// ================================================================
@@ -399,26 +422,3 @@ void OcctQOpenGLWidgetViewer::paintGL()
399422
// reset global GL state after OCCT before redrawing Qt
400423
OcctGlTools::ResetGlStateAfterOcct(myView);
401424
}
402-
403-
// ================================================================
404-
// Function : handleViewRedraw
405-
// ================================================================
406-
void OcctQOpenGLWidgetViewer::handleViewRedraw(const Handle(AIS_InteractiveContext)& theCtx,
407-
const Handle(V3d_View)& theView)
408-
{
409-
AIS_ViewController::handleViewRedraw(theCtx, theView);
410-
if (myToAskNextFrame)
411-
updateView(); // ask more frames for animation
412-
}
413-
414-
#if (OCC_VERSION_HEX >= 0x070700)
415-
// ================================================================
416-
// Function : OnSubviewChanged
417-
// ================================================================
418-
void OcctQOpenGLWidgetViewer::OnSubviewChanged(const Handle(AIS_InteractiveContext)&,
419-
const Handle(V3d_View)&,
420-
const Handle(V3d_View)& theNewView)
421-
{
422-
myFocusView = theNewView;
423-
}
424-
#endif

occt-qopenglwidget/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class MyMainWindow : public QMainWindow
168168

169169
int main(int theNbArgs, char** theArgVec)
170170
{
171-
// before creaing QApplication: define platform plugin to load (e.g. xcb on Linux)
171+
// before creating QApplication: define platform plugin to load (e.g. xcb on Linux)
172172
// and graphic driver (e.g. desktop OpenGL with desired profile/surface)
173173
OcctQtTools::qtGlPlatformSetup();
174174
QApplication aQApp(theNbArgs, theArgVec);

occt-qt-tools/OcctQtTools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void OcctQtTools::qtGlPlatformSetup()
3939
//
4040
#else
4141
// Qt6 tries to use Wayland platform by default, which is incompatible with OCCT depending on Xlib;
42-
// Force 'xcb' platform plugin (alternatively, could be passed QApplication as '-platfom xcb' argument).
42+
// Force 'xcb' platform plugin (alternatively, could be passed QApplication as '-platform xcb' argument).
4343
OSD_Environment aQpaPlat("QT_QPA_PLATFORM");
4444
if (aQpaPlat.Value().IsEmpty())
4545
{
@@ -110,7 +110,7 @@ QSurfaceFormat OcctQtTools::qtGlSurfaceFormat(QSurfaceFormat::OpenGLContextProfi
110110
if (aProfile == QSurfaceFormat::CoreProfile)
111111
aGlFormat.setVersion(4, 5);
112112

113-
// request sRGBColorSpace colorspace to meet OCCT expectations or use OcctQtFrameBuffer fallback.
113+
// request sRGBColorSpace color-space to meet OCCT expectations or use OcctQtFrameBuffer fallback.
114114
/*#if (QT_VERSION_MAJOR > 5) || (QT_VERSION_MAJOR == 5 && QT_VERSION_MINOR >= 10)
115115
aGlFormat.setColorSpace(QSurfaceFormat::sRGBColorSpace);
116116
#endif*/

occt-qt-tools/OcctQtTools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class OpenGl_Caps;
1717
//! Auxiliary tools between Qt and OCCT definitions.
1818
namespace OcctQtTools
1919
{
20-
//! Perform global Qt platform setup - to be called befor QApplication creation.
20+
//! Perform global Qt platform setup - to be called before QApplication creation.
2121
//! Defines platform plugin to load (e.g. xcb on Linux)
2222
//! and graphic driver (e.g. desktop OpenGL with desired profile/surface).
2323
void qtGlPlatformSetup();

occt-qtquick/OcctQQuickFramebufferViewer.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ OcctQQuickFramebufferViewer::OcctQQuickFramebufferViewer(QQuickItem* theParent)
7979

8080
// QtQuick item setup
8181
setAcceptedMouseButtons(Qt::AllButtons);
82-
//setAcceptTouchEvents(true); // necessary to recieve QTouchEvent events
82+
//setAcceptTouchEvents(true); // necessary to receive QTouchEvent events
8383
setAcceptHoverEvents(true);
8484
setMirrorVertically(true);
8585

@@ -112,33 +112,6 @@ OcctQQuickFramebufferViewer::~OcctQQuickFramebufferViewer()
112112
aDisp.Nullify();
113113
}
114114

115-
// ================================================================
116-
// Function : dumpGlInfo
117-
// ================================================================
118-
void OcctQQuickFramebufferViewer::dumpGlInfo(bool theIsBasic, bool theToPrint)
119-
{
120-
TColStd_IndexedDataMapOfStringString aGlCapsDict;
121-
myView->DiagnosticInformation(aGlCapsDict,
122-
theIsBasic ? Graphic3d_DiagnosticInfo_Basic : Graphic3d_DiagnosticInfo_Complete);
123-
TCollection_AsciiString anInfo;
124-
for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter(aGlCapsDict); aValueIter.More(); aValueIter.Next())
125-
{
126-
if (!aValueIter.Value().IsEmpty())
127-
{
128-
if (!anInfo.IsEmpty())
129-
anInfo += "\n";
130-
131-
anInfo += aValueIter.Key() + ": " + aValueIter.Value();
132-
}
133-
}
134-
135-
if (theToPrint)
136-
Message::SendInfo(anInfo);
137-
138-
myGlInfo = QString::fromUtf8(anInfo.ToCString());
139-
Q_EMIT glInfoChanged();
140-
}
141-
142115
// ================================================================
143116
// Function : event
144117
// ================================================================
@@ -434,13 +407,40 @@ void OcctQQuickFramebufferViewer::Renderer::render()
434407
myViewer->render(framebufferObject());
435408
}
436409

410+
// ================================================================
411+
// Function : dumpGlInfo
412+
// ================================================================
413+
void OcctQQuickFramebufferViewer::dumpGlInfo(bool theIsBasic, bool theToPrint)
414+
{
415+
TColStd_IndexedDataMapOfStringString aGlCapsDict;
416+
myView->DiagnosticInformation(aGlCapsDict,
417+
theIsBasic ? Graphic3d_DiagnosticInfo_Basic : Graphic3d_DiagnosticInfo_Complete);
418+
TCollection_AsciiString anInfo;
419+
for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter(aGlCapsDict); aValueIter.More(); aValueIter.Next())
420+
{
421+
if (!aValueIter.Value().IsEmpty())
422+
{
423+
if (!anInfo.IsEmpty())
424+
anInfo += "\n";
425+
426+
anInfo += aValueIter.Key() + ": " + aValueIter.Value();
427+
}
428+
}
429+
430+
if (theToPrint)
431+
Message::SendInfo(anInfo);
432+
433+
myGlInfo = QString::fromUtf8(anInfo.ToCString());
434+
Q_EMIT glInfoChanged();
435+
}
436+
437437
// ================================================================
438438
// Function : synchronize
439439
// ================================================================
440440
void OcctQQuickFramebufferViewer::synchronize(QOpenGLFramebufferObject* )
441441
{
442442
// this method will be called from GL rendering thread while GUI thread is locked,
443-
// the place to sycnhronize GUI / GL rendering states
443+
// the place to synchronize GUI / GL rendering states
444444
if (myGlBackColor.first)
445445
{
446446
myGlBackColor.first = false;

occt-qtquick/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
int main(int theNbArgs, char** theArgVec)
1616
{
17-
// before creaing QApplication: define platform plugin to load (e.g. xcb on Linux)
17+
// before creating QApplication: define platform plugin to load (e.g. xcb on Linux)
1818
// and graphic driver (e.g. desktop OpenGL with desired profile/surface)
1919
OcctQtTools::qtGlPlatformSetup();
2020

2121
// Qt by default will attempt offloading rendering
2222
// into a separate working thread (QSGRenderThread) on some systems,
23-
// which requires addition of multithreading synchronization mechanism
23+
// which requires addition of multi-threading synchronization mechanism
2424
// when dealing with OCCT 3D Viewer from GUI thread.
2525
// Uncomment following lines if these complexities are undesired
2626
// to ask Qt managing rendering from GUI thread.

0 commit comments

Comments
 (0)