I'm currently writing a render pass which renders to a framebuffer with attached color and depth attachments. Before the pass starts, it needs to clear the depth attachment to a set value. I'm trying to accomplish this with glClearNamedFramebufferfv(fbo, GL_DEPTH, 0, &depth_value)
. However, this seems to only work if glDepthMask
was set to true before/not set to 'false'.
I find it a bit weird to have the clear operation depend on global pipeline state (or perhaps I have worked with Vulkan a bit too long before this task), so I'd first like to ask whether this is indeed how it works (the spec says "enable or disable writing into the depth buffer", not just rendering, so it seems to be intended).
The second question would then be if there are alternatives that don't rely/respect this global flag. Since the underlying FBO attachment is a texture and not a renderbuffer, could I use glClearTexImage
instead or does this also respect glDepthMask
? Are there performance costs when clearing a texture like this instead of via the framebuffer?
Thank you in advance