Skip to content

Commit 4ad39b7

Browse files
committed
PenLayer: Do not create FBO in stamp()
1 parent 9717697 commit 4ad39b7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/penlayer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ PenLayer::~PenLayer()
3737
// Delete vertex array and buffer
3838
m_glF->glDeleteVertexArrays(1, &m_vao);
3939
m_glF->glDeleteBuffers(1, &m_vbo);
40+
41+
// Delete stamp FBO
42+
m_glF->glDeleteFramebuffers(1, &m_stampFbo);
4043
}
4144
}
4245

@@ -99,6 +102,9 @@ void PenLayer::setEngine(libscratchcpp::IEngine *newEngine)
99102

100103
m_glF->glBindVertexArray(0);
101104
m_glF->glBindBuffer(GL_ARRAY_BUFFER, 0);
105+
106+
// Create stamp FBO
107+
m_glF->glGenFramebuffers(1, &m_stampFbo);
102108
}
103109

104110
clear();
@@ -268,14 +274,12 @@ void PenLayer::stamp(IRenderedTarget *target)
268274
m_painter->endFrame();
269275

270276
// Create a FBO for the current texture
271-
unsigned int fbo;
272-
m_glF->glGenFramebuffers(1, &fbo);
273-
m_glF->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
277+
m_glF->glBindFramebuffer(GL_FRAMEBUFFER, m_stampFbo);
274278
m_glF->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.handle(), 0);
275279

276280
if (m_glF->glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
277281
qWarning() << "error: framebuffer incomplete (stamp " + target->scratchTarget()->name() + ")";
278-
m_glF->glDeleteFramebuffers(1, &fbo);
282+
m_glF->glBindFramebuffer(GL_FRAMEBUFFER, 0);
279283
return;
280284
}
281285

@@ -308,7 +312,6 @@ void PenLayer::stamp(IRenderedTarget *target)
308312
m_glF->glBindVertexArray(0);
309313
m_glF->glBindBuffer(GL_ARRAY_BUFFER, 0);
310314
m_glF->glBindFramebuffer(GL_FRAMEBUFFER, 0);
311-
m_glF->glDeleteFramebuffers(1, &fbo);
312315

313316
m_glF->glEnable(GL_SCISSOR_TEST);
314317

src/penlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PenLayer : public IPenLayer
6060
void updateTexture();
6161

6262
static std::unordered_map<libscratchcpp::IEngine *, IPenLayer *> m_projectPenLayers;
63+
static inline GLuint m_stampFbo = 0;
6364
bool m_antialiasingEnabled = true;
6465
libscratchcpp::IEngine *m_engine = nullptr;
6566
bool m_hqPen = false;

0 commit comments

Comments
 (0)