@@ -86,7 +86,7 @@ void PenLayer::setEngine(libscratchcpp::IEngine *newEngine)
8686 m_glF->initializeOpenGLFunctions ();
8787 }
8888
89- createFbo ();
89+ refresh ();
9090
9191 if (m_vao == 0 ) {
9292 // Set up VBO and VAO
@@ -133,7 +133,7 @@ void PenLayer::setHqPen(bool newHqPen)
133133
134134 m_hqPen = newHqPen;
135135 emit hqPenChanged ();
136- createFbo ();
136+ refresh ();
137137}
138138
139139void scratchcpprender::PenLayer::clear ()
@@ -332,6 +332,38 @@ void PenLayer::stamp(IRenderedTarget *target)
332332 update ();
333333}
334334
335+ void PenLayer::refresh ()
336+ {
337+ if (!m_glCtx || !m_surface || !m_engine || !m_glF)
338+ return ;
339+
340+ QOpenGLContext *oldCtx = QOpenGLContext::currentContext ();
341+ QSurface *oldSurface = oldCtx->surface ();
342+
343+ if (oldCtx != m_glCtx) {
344+ oldCtx->doneCurrent ();
345+ m_glCtx->makeCurrent (m_surface);
346+ }
347+
348+ QOpenGLFramebufferObjectFormat fboFormat;
349+ fboFormat.setAttachment (QOpenGLFramebufferObject::CombinedDepthStencil);
350+
351+ QOpenGLFramebufferObject *newFbo = new QOpenGLFramebufferObject (width (), height (), fboFormat);
352+ Q_ASSERT (newFbo->isValid ());
353+
354+ if (m_fbo)
355+ QOpenGLFramebufferObject::blitFramebuffer (newFbo, m_fbo.get ());
356+
357+ m_fbo.reset (newFbo);
358+ m_texture = Texture (m_fbo->texture (), m_fbo->size ());
359+ m_scale = width () / m_engine->stageWidth ();
360+
361+ if (oldCtx != m_glCtx) {
362+ m_glCtx->doneCurrent ();
363+ oldCtx->makeCurrent (oldSurface);
364+ }
365+ }
366+
335367QOpenGLFramebufferObject *PenLayer::framebufferObject () const
336368{
337369 return m_fbo.get ();
@@ -445,43 +477,11 @@ QNanoQuickItemPainter *PenLayer::createItemPainter() const
445477void PenLayer::geometryChange (const QRectF &newGeometry, const QRectF &oldGeometry)
446478{
447479 if (m_hqPen && newGeometry != oldGeometry)
448- createFbo ();
480+ refresh ();
449481
450482 QNanoQuickItem::geometryChange (newGeometry, oldGeometry);
451483}
452484
453- void PenLayer::createFbo ()
454- {
455- if (!m_glCtx || !m_surface || !m_engine || !m_glF)
456- return ;
457-
458- QOpenGLContext *oldCtx = QOpenGLContext::currentContext ();
459- QSurface *oldSurface = oldCtx->surface ();
460-
461- if (oldCtx != m_glCtx) {
462- oldCtx->doneCurrent ();
463- m_glCtx->makeCurrent (m_surface);
464- }
465-
466- QOpenGLFramebufferObjectFormat fboFormat;
467- fboFormat.setAttachment (QOpenGLFramebufferObject::CombinedDepthStencil);
468-
469- QOpenGLFramebufferObject *newFbo = new QOpenGLFramebufferObject (width (), height (), fboFormat);
470- Q_ASSERT (newFbo->isValid ());
471-
472- if (m_fbo)
473- QOpenGLFramebufferObject::blitFramebuffer (newFbo, m_fbo.get ());
474-
475- m_fbo.reset (newFbo);
476- m_texture = Texture (m_fbo->texture (), m_fbo->size ());
477- m_scale = width () / m_engine->stageWidth ();
478-
479- if (oldCtx != m_glCtx) {
480- m_glCtx->doneCurrent ();
481- oldCtx->makeCurrent (oldSurface);
482- }
483- }
484-
485485void PenLayer::updateTexture ()
486486{
487487 if (!m_fbo)
0 commit comments