3
0
mirror of https://github.com/hyprwm/Hyprland.git synced 2026-02-05 17:15:39 +00:00

renderer: minor framebuffer and renderbuffer changes (#12831)

* framebuffer: dont release if format or size changes

we dont have to release and recreate both the texture and framebuffer if
size or format changes, we can just bind the texture and call glTexImage2D
with the new format and size.

* framebuffer: set the alloced viewport size

if monitor size mismatch with the allocated m_size its going to set a
mismatched viewport and cause rendering issues. and if they are
mismatching there is a missing alloc call.

* renderbuffer: cleanup unneded binds

the renderbuffer is attached to the fbo and trying to rebind it in
bind() is causing unnecessery state changes, just bind the fbo.

add safeguard in the destructor, the constructor can return early on
failure and leave m_rbo empty or m_image as EGL_NO_IMAGE_KHR.
This commit is contained in:
Tom Englund
2026-01-03 15:13:01 +01:00
committed by GitHub
parent ee67278038
commit fab3370254
3 changed files with 12 additions and 19 deletions

View File

@ -9,13 +9,10 @@ bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) {
bool firstAlloc = false;
RASSERT((w > 0 && h > 0), "cannot alloc a FB with negative / zero size! (attempted {}x{})", w, h);
uint32_t glFormat = NFormatUtils::drmFormatToGL(drmFormat);
uint32_t glType = NFormatUtils::glFormatToType(glFormat);
if (drmFormat != m_drmFormat || m_size != Vector2D{w, h})
release();
m_drmFormat = drmFormat;
const uint32_t glFormat = NFormatUtils::drmFormatToGL(drmFormat);
const uint32_t glType = NFormatUtils::glFormatToType(glFormat);
const bool sizeChanged = (m_size != Vector2D(w, h));
const bool formatChanged = (drmFormat != m_drmFormat);
if (!m_tex) {
m_tex = makeShared<CTexture>();
@ -34,7 +31,7 @@ bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) {
firstAlloc = true;
}
if (firstAlloc || m_size != Vector2D(w, h)) {
if (firstAlloc || sizeChanged || formatChanged) {
m_tex->bind();
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
@ -80,7 +77,7 @@ void CFramebuffer::bind() {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fb);
if (g_pHyprOpenGL)
g_pHyprOpenGL->setViewport(0, 0, g_pHyprOpenGL->m_renderData.pMonitor->m_pixelSize.x, g_pHyprOpenGL->m_renderData.pMonitor->m_pixelSize.y);
g_pHyprOpenGL->setViewport(0, 0, m_size.x, m_size.y);
else
glViewport(0, 0, m_size.x, m_size.y);
}

View File

@ -16,9 +16,12 @@ CRenderbuffer::~CRenderbuffer() {
unbind();
m_framebuffer.release();
glDeleteRenderbuffers(1, &m_rbo);
g_pHyprOpenGL->m_proc.eglDestroyImageKHR(g_pHyprOpenGL->m_eglDisplay, m_image);
if (m_rbo)
glDeleteRenderbuffers(1, &m_rbo);
if (m_image != EGL_NO_IMAGE_KHR)
g_pHyprOpenGL->m_proc.eglDestroyImageKHR(g_pHyprOpenGL->m_eglDisplay, m_image);
}
CRenderbuffer::CRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t format) : m_hlBuffer(buffer), m_drmFormat(format) {
@ -58,16 +61,10 @@ bool CRenderbuffer::good() {
}
void CRenderbuffer::bind() {
glBindRenderbuffer(GL_RENDERBUFFER, m_rbo);
bindFB();
}
void CRenderbuffer::bindFB() {
m_framebuffer.bind();
}
void CRenderbuffer::unbind() {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
m_framebuffer.unbind();
}

View File

@ -14,7 +14,6 @@ class CRenderbuffer {
bool good();
void bind();
void bindFB();
void unbind();
CFramebuffer* getFB();
uint32_t getFormat();
@ -31,4 +30,4 @@ class CRenderbuffer {
struct {
CHyprSignalListener destroyBuffer;
} m_listeners;
};
};