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:
+8
-2
@@ -1233,8 +1233,9 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// Create window with graphics context
|
// Create window with graphics context
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
// Nothing in the app uses depth/stencil (ImGui + acrylic are color-only): request none.
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
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_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);
|
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);
|
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
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
|
||||||
bool backdrop_active = false;
|
bool backdrop_active = false;
|
||||||
|
|||||||
@@ -35,14 +35,12 @@ Framebuffer::~Framebuffer()
|
|||||||
Framebuffer::Framebuffer(Framebuffer&& other) noexcept
|
Framebuffer::Framebuffer(Framebuffer&& other) noexcept
|
||||||
: fbo_(other.fbo_)
|
: fbo_(other.fbo_)
|
||||||
, colorTexture_(other.colorTexture_)
|
, colorTexture_(other.colorTexture_)
|
||||||
, depthRbo_(other.depthRbo_)
|
|
||||||
, width_(other.width_)
|
, width_(other.width_)
|
||||||
, height_(other.height_)
|
, height_(other.height_)
|
||||||
, isComplete_(other.isComplete_)
|
, isComplete_(other.isComplete_)
|
||||||
{
|
{
|
||||||
other.fbo_ = 0;
|
other.fbo_ = 0;
|
||||||
other.colorTexture_ = 0;
|
other.colorTexture_ = 0;
|
||||||
other.depthRbo_ = 0;
|
|
||||||
other.width_ = 0;
|
other.width_ = 0;
|
||||||
other.height_ = 0;
|
other.height_ = 0;
|
||||||
other.isComplete_ = false;
|
other.isComplete_ = false;
|
||||||
@@ -55,14 +53,12 @@ Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept
|
|||||||
|
|
||||||
fbo_ = other.fbo_;
|
fbo_ = other.fbo_;
|
||||||
colorTexture_ = other.colorTexture_;
|
colorTexture_ = other.colorTexture_;
|
||||||
depthRbo_ = other.depthRbo_;
|
|
||||||
width_ = other.width_;
|
width_ = other.width_;
|
||||||
height_ = other.height_;
|
height_ = other.height_;
|
||||||
isComplete_ = other.isComplete_;
|
isComplete_ = other.isComplete_;
|
||||||
|
|
||||||
other.fbo_ = 0;
|
other.fbo_ = 0;
|
||||||
other.colorTexture_ = 0;
|
other.colorTexture_ = 0;
|
||||||
other.depthRbo_ = 0;
|
|
||||||
other.width_ = 0;
|
other.width_ = 0;
|
||||||
other.height_ = 0;
|
other.height_ = 0;
|
||||||
other.isComplete_ = false;
|
other.isComplete_ = false;
|
||||||
@@ -104,19 +100,12 @@ bool Framebuffer::init(int width, int height, bool useFloat16)
|
|||||||
// Attach color texture to framebuffer
|
// Attach color texture to framebuffer
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture_, 0);
|
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
|
// Check completeness
|
||||||
isComplete_ = checkComplete();
|
isComplete_ = checkComplete();
|
||||||
|
|
||||||
// Unbind
|
// Unbind
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
||||||
|
|
||||||
if (!isComplete_) {
|
if (!isComplete_) {
|
||||||
DEBUG_LOGF("Framebuffer::init - Framebuffer is not complete!\n");
|
DEBUG_LOGF("Framebuffer::init - Framebuffer is not complete!\n");
|
||||||
@@ -146,10 +135,6 @@ void Framebuffer::cleanup()
|
|||||||
glDeleteTextures(1, &colorTexture_);
|
glDeleteTextures(1, &colorTexture_);
|
||||||
colorTexture_ = 0;
|
colorTexture_ = 0;
|
||||||
}
|
}
|
||||||
if (depthRbo_) {
|
|
||||||
glDeleteRenderbuffers(1, &depthRbo_);
|
|
||||||
depthRbo_ = 0;
|
|
||||||
}
|
|
||||||
if (fbo_) {
|
if (fbo_) {
|
||||||
glDeleteFramebuffers(1, &fbo_);
|
glDeleteFramebuffers(1, &fbo_);
|
||||||
fbo_ = 0;
|
fbo_ = 0;
|
||||||
@@ -194,7 +179,7 @@ void Framebuffer::unbind()
|
|||||||
void Framebuffer::clear(float r, float g, float b, float a)
|
void Framebuffer::clear(float r, float g, float b, float a)
|
||||||
{
|
{
|
||||||
glClearColor(r, g, b, 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,
|
void Framebuffer::blitFrom(GLuint srcFbo, int srcX, int srcY, int srcWidth, int srcHeight,
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ private:
|
|||||||
|
|
||||||
GLuint fbo_ = 0;
|
GLuint fbo_ = 0;
|
||||||
GLuint colorTexture_ = 0;
|
GLuint colorTexture_ = 0;
|
||||||
GLuint depthRbo_ = 0; // Renderbuffer for depth (optional)
|
|
||||||
|
|
||||||
int width_ = 0;
|
int width_ = 0;
|
||||||
int height_ = 0;
|
int height_ = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user