@@ -86,7 +86,7 @@ void PenLayer::setEngine(libscratchcpp::IEngine *newEngine)
86
86
m_glF->initializeOpenGLFunctions ();
87
87
}
88
88
89
- createFbo ();
89
+ refresh ();
90
90
91
91
if (m_vao == 0 ) {
92
92
// Set up VBO and VAO
@@ -133,7 +133,7 @@ void PenLayer::setHqPen(bool newHqPen)
133
133
134
134
m_hqPen = newHqPen;
135
135
emit hqPenChanged ();
136
- createFbo ();
136
+ refresh ();
137
137
}
138
138
139
139
void scratchcpprender::PenLayer::clear ()
@@ -332,6 +332,38 @@ void PenLayer::stamp(IRenderedTarget *target)
332
332
update ();
333
333
}
334
334
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
+
335
367
QOpenGLFramebufferObject *PenLayer::framebufferObject () const
336
368
{
337
369
return m_fbo.get ();
@@ -445,43 +477,11 @@ QNanoQuickItemPainter *PenLayer::createItemPainter() const
445
477
void PenLayer::geometryChange (const QRectF &newGeometry, const QRectF &oldGeometry)
446
478
{
447
479
if (m_hqPen && newGeometry != oldGeometry)
448
- createFbo ();
480
+ refresh ();
449
481
450
482
QNanoQuickItem::geometryChange (newGeometry, oldGeometry);
451
483
}
452
484
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
-
485
485
void PenLayer::updateTexture ()
486
486
{
487
487
if (!m_fbo)
0 commit comments