@@ -408,8 +408,16 @@ QOpenGLFramebufferObject* OcctQQuickFramebufferViewer::Renderer::createFramebuff
408408{
409409 QOpenGLFramebufferObjectFormat aQFormat;
410410 aQFormat.setAttachment (QOpenGLFramebufferObject::CombinedDepthStencil);
411- // aQFormat.setInternalTextureFormat(isSrgb ? GL_SRGB8_ALPHA8 ? GL_RGBA8);
411+ // aQFormat.setInternalTextureFormat(GL_RGBA8);
412412 // aQFormat.setSamples(4); do not create MSAA buffer here
413+
414+ /* #if (QT_VERSION_MAJOR > 5) || (QT_VERSION_MAJOR == 5 && QT_VERSION_MINOR >= 10)
415+ const QQuickWindow* aQWindow = window();
416+ const QSurfaceFormat aQtGlFormat = aQWindow->format();
417+ if (aQtGlFormat.colorSpace() == QSurfaceFormat::sRGBColorSpace)
418+ aQFormat.setInternalTextureFormat(GL_SRGB8_ALPHA8);
419+ #endif*/
420+
413421 return new QOpenGLFramebufferObject (theSize, aQFormat);
414422}
415423
@@ -438,13 +446,10 @@ void OcctQQuickFramebufferViewer::Renderer::render()
438446// ================================================================
439447// Function : synchronize
440448// ================================================================
441- void OcctQQuickFramebufferViewer::synchronize (QOpenGLFramebufferObject* theFbo )
449+ void OcctQQuickFramebufferViewer::synchronize (QOpenGLFramebufferObject* )
442450{
443451 // this method will be called from GL rendering thread while GUI thread is locked,
444452 // the place to sycnhronize GUI / GL rendering states
445-
446- if (myView.IsNull () || myView->Window ().IsNull ())
447- initializeGL (theFbo);
448453}
449454
450455// ================================================================
@@ -456,9 +461,17 @@ void OcctQQuickFramebufferViewer::initializeGL(QOpenGLFramebufferObject* theFbo)
456461 if (theFbo == nullptr )
457462 return ;
458463
464+ const Graphic3d_Vec2i aViewSize (theFbo->size ().width (), theFbo->size ().height ());
459465 const QQuickWindow* aQWindow = window ();
460- const QSize aRect = theFbo->size ();
461- const Graphic3d_Vec2i aViewSize (aRect.width (), aRect.height ());
466+ const QSurfaceFormat aQtGlFormat = aQWindow->format ();
467+
468+ Handle (OpenGl_GraphicDriver) aDriver = Handle (OpenGl_GraphicDriver)::DownCast (myViewer->Driver ());
469+ aDriver->ChangeOptions ().contextDebug = aQtGlFormat.testOption (QSurfaceFormat::DebugContext);
470+ aDriver->ChangeOptions ().contextSyncDebug = aDriver->Options ().contextDebug ;
471+ aDriver->ChangeOptions ().contextCompatible = aQtGlFormat.profile () != QSurfaceFormat::CoreProfile;
472+ aDriver->ChangeOptions ().buffersDeepColor = aQtGlFormat.redBufferSize () == 10
473+ && aQtGlFormat.greenBufferSize () == 10
474+ && aQtGlFormat.blueBufferSize () == 10 ;
462475
463476 Aspect_Drawable aNativeWin = aQWindow != nullptr ? (Aspect_Drawable)aQWindow->winId () : 0 ;
464477#ifdef _WIN32
@@ -468,7 +481,7 @@ void OcctQQuickFramebufferViewer::initializeGL(QOpenGLFramebufferObject* theFbo)
468481#endif
469482
470483 Handle (OpenGl_Context) aGlCtx = new OpenGl_Context ();
471- if (!aGlCtx->Init (myIsCoreProfile ))
484+ if (!aGlCtx->Init (!aDriver-> Options (). contextCompatible ))
472485 {
473486 Message::SendFail () << " Error: OpenGl_Context is unable to wrap OpenGL context" ;
474487 QMessageBox::critical (0 , " Failure" , " OpenGl_Context is unable to wrap OpenGL context" );
@@ -512,7 +525,7 @@ void OcctQQuickFramebufferViewer::render(QOpenGLFramebufferObject* theFbo)
512525{
513526 // this method is called from GL rendering thread;
514527 // accessing GUI items is not allowed here!
515- if (theFbo == nullptr || myView.IsNull () || myView-> Window (). IsNull () )
528+ if (theFbo == nullptr || myView.IsNull ())
516529 return ;
517530
518531 QQuickWindow* aQWindow = window ();
@@ -524,7 +537,12 @@ void OcctQQuickFramebufferViewer::render(QOpenGLFramebufferObject* theFbo)
524537#endif
525538
526539 Standard_Mutex::Sentry aLock (myViewerMutex);
527- if (myView->Window ()->NativeHandle () != aNativeWin)
540+ if (myView->Window ().IsNull ())
541+ {
542+ initializeGL (theFbo);
543+ theFbo->bind ();
544+ }
545+ else if (myView->Window ()->NativeHandle () != aNativeWin)
528546 {
529547 // workaround window recreation done by Qt on monitor (QScreen) disconnection
530548 Message::SendWarning () << " Native window handle has changed by QQuickWindow!" ;
0 commit comments