diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-07-12 23:11:34 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-07-12 23:11:34 +0200 |
| commit | bf762f566f1c8c5e9c636f0d1ad4e485ad322da9 (patch) | |
| tree | 667d1c3bf7a4f5f9c1e8bc0b5d7189ef2a760437 /src/render | |
| parent | f9985a36b345acf3fd4f6a1ad8170a475658fb60 (diff) | |
Fix VRAM memory leak when releasing snapshots
Diffstat (limited to 'src/render')
| -rw-r--r-- | src/render/Framebuffer.cpp | 18 | ||||
| -rw-r--r-- | src/render/Framebuffer.hpp | 2 | ||||
| -rw-r--r-- | src/render/OpenGL.cpp | 9 |
3 files changed, 15 insertions, 14 deletions
diff --git a/src/render/Framebuffer.cpp b/src/render/Framebuffer.cpp index 4a5baf50..90b41a4b 100644 --- a/src/render/Framebuffer.cpp +++ b/src/render/Framebuffer.cpp @@ -2,15 +2,14 @@ #include "OpenGL.hpp" bool CFramebuffer::alloc(int w, int h) { - bool firstAlloc = false; - if (m_iFb == (uint32_t)-1) - { + bool firstAlloc = false; + + if (m_iFb == (uint32_t)-1) { firstAlloc = true; glGenFramebuffers(1, &m_iFb); } - if (m_cTex.m_iTexID == 0) - { + if (m_cTex.m_iTexID == 0) { firstAlloc = true; glGenTextures(1, &m_cTex.m_iTexID); glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); @@ -20,13 +19,11 @@ bool CFramebuffer::alloc(int w, int h) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - if (firstAlloc || m_Size != Vector2D(w, h)) - { + if (firstAlloc || m_Size != Vector2D(w, h)) { glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); - glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0); @@ -37,7 +34,6 @@ bool CFramebuffer::alloc(int w, int h) { glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); - glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0); } @@ -78,3 +74,7 @@ void CFramebuffer::release() { m_cTex.m_iTexID = 0; m_iFb = -1; } + +CFramebuffer::~CFramebuffer() { + release(); +}
\ No newline at end of file diff --git a/src/render/Framebuffer.hpp b/src/render/Framebuffer.hpp index 3d15069d..6af59ca2 100644 --- a/src/render/Framebuffer.hpp +++ b/src/render/Framebuffer.hpp @@ -6,6 +6,8 @@ class CFramebuffer { public: + ~CFramebuffer(); + bool alloc(int w, int h); void bind(); void release(); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 4b2fabea..d60e827e 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -702,8 +702,6 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) { begin(PMONITOR, &fakeDamage, true); - pixman_region32_fini(&fakeDamage); - clear(CColor(0,0,0,0)); // JIC timespec now; @@ -742,9 +740,10 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) { #else glBindFramebuffer(GL_FRAMEBUFFER, m_iCurrentOutputFb); #endif - end(); + pixman_region32_fini(&fakeDamage); + wlr_output_rollback(PMONITOR->output); } @@ -762,8 +761,6 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) { begin(PMONITOR, &fakeDamage, true); - pixman_region32_fini(&fakeDamage); - const auto PFRAMEBUFFER = &m_mLayerFramebuffers[pLayer]; glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y); @@ -792,6 +789,8 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) { end(); + pixman_region32_fini(&fakeDamage); + wlr_output_rollback(PMONITOR->output); } |
