perf(gl): drop the unused depth/stencil buffers from window and FBOs

The GL window asked for a 24-bit depth and 8-bit stencil buffer, and
every acrylic Framebuffer attached a DEPTH24_STENCIL8 renderbuffer the
size of its color texture. Nothing uses them: no code enables depth or
stencil tests (the ImGui GL3 backend disables both), every blit and
readback is color-only, and only Framebuffer::clear() also cleared the
depth buffer, which nothing read. The window and every FBO, including
the full-size capture FBO, carried that memory, and the FBO
renderbuffers were reallocated on every resize.

Now:
- the window requests depth 0 and stencil 0 explicitly (SDL3 requests a
  depth buffer by default when the attributes are simply removed);
  alpha 8 stays for the transparent window;
- Framebuffer has no renderbuffer, and clear() clears color only;
- a permanent startup log line,
  "GL default framebuffer: depth=N stencil=N", reports what the driver
  provided; "(no attachment)" marks a failed query, which is how some
  drivers report a buffer that does not exist.

The log shows depth=0 stencil=0 both offscreen and on WSLg X11, where
"Window transparency enabled by compositor" is still logged, with no
framebuffer-incomplete errors. Screenshot sweeps at 1280x720 and
2560x1440, and a glass run with ui_opacity 0.6 and blur on (so panels go
through the FBO blur), match the previous build within noise. The
driver-side memory saving itself was not measured. DX11 is unaffected:
its swap chain has no depth buffer.

Not verifiable here: macOS (an NSOpenGL 3.2 core context with a
transparent window).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 06:05:07 -05:00
co-authored by Claude Opus 5.5
parent 73f7f33a4b
commit f970cae193
3 changed files with 9 additions and 19 deletions
+8 -2
View File
@@ -1233,8 +1233,9 @@ int main(int argc, char* argv[])
// Create window with graphics context
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
// Nothing in the app uses depth/stencil (ImGui + acrylic are color-only): request none.
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_TRANSPARENT);
@@ -1268,6 +1269,11 @@ int main(int argc, char* argv[])
}
SDL_GL_MakeCurrent(window, gl_context);
{ int d = -1, s = -1;
const bool okd = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &d);
const bool oks = SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &s);
DEBUG_LOGF("GL default framebuffer: depth=%d%s stencil=%d%s\n",
d, okd ? "" : " (no attachment)", s, oks ? "" : " (no attachment)"); }
SDL_GL_SetSwapInterval(1); // Enable vsync
bool backdrop_active = false;
+1 -16
View File
@@ -35,14 +35,12 @@ Framebuffer::~Framebuffer()
Framebuffer::Framebuffer(Framebuffer&& other) noexcept
: fbo_(other.fbo_)
, colorTexture_(other.colorTexture_)
, depthRbo_(other.depthRbo_)
, width_(other.width_)
, height_(other.height_)
, isComplete_(other.isComplete_)
{
other.fbo_ = 0;
other.colorTexture_ = 0;
other.depthRbo_ = 0;
other.width_ = 0;
other.height_ = 0;
other.isComplete_ = false;
@@ -55,14 +53,12 @@ Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept
fbo_ = other.fbo_;
colorTexture_ = other.colorTexture_;
depthRbo_ = other.depthRbo_;
width_ = other.width_;
height_ = other.height_;
isComplete_ = other.isComplete_;
other.fbo_ = 0;
other.colorTexture_ = 0;
other.depthRbo_ = 0;
other.width_ = 0;
other.height_ = 0;
other.isComplete_ = false;
@@ -104,19 +100,12 @@ bool Framebuffer::init(int width, int height, bool useFloat16)
// Attach color texture to framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture_, 0);
// Create depth renderbuffer (optional, but good for completeness)
glGenRenderbuffers(1, &depthRbo_);
glBindRenderbuffer(GL_RENDERBUFFER, depthRbo_);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRbo_);
// Check completeness
isComplete_ = checkComplete();
// Unbind
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (!isComplete_) {
DEBUG_LOGF("Framebuffer::init - Framebuffer is not complete!\n");
@@ -146,10 +135,6 @@ void Framebuffer::cleanup()
glDeleteTextures(1, &colorTexture_);
colorTexture_ = 0;
}
if (depthRbo_) {
glDeleteRenderbuffers(1, &depthRbo_);
depthRbo_ = 0;
}
if (fbo_) {
glDeleteFramebuffers(1, &fbo_);
fbo_ = 0;
@@ -194,7 +179,7 @@ void Framebuffer::unbind()
void Framebuffer::clear(float r, float g, float b, float a)
{
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
}
void Framebuffer::blitFrom(GLuint srcFbo, int srcX, int srcY, int srcWidth, int srcHeight,
-1
View File
@@ -125,7 +125,6 @@ private:
GLuint fbo_ = 0;
GLuint colorTexture_ = 0;
GLuint depthRbo_ = 0; // Renderbuffer for depth (optional)
int width_ = 0;
int height_ = 0;