I’m using a depth texture array with 4 depth layers for cascaded shadow mapping, with each cascade stored in a separate layer:
// Pseudo Code - Initialization
frameBuffer = new OpenGL FrameBuffer
depthTexture = new OpenGL Texture
glBindTexture(GL_TEXTURE_2D_ARRAY,depthTexture)
glTexImage3D(
GL_TEXTURE_2D_ARRAY,0,GL_DEPTH_COMPONENT24,
texWidth,texHeight,cascadeCount,1,GL_DEPTH_COMPONENT,GL_FLOAT,NULL
)
I then render all shadow casters into each of the cascades, by binding the respective layer to a frame buffer via glFramebufferTextureLayer, then using glDrawElements to render the meshes:
// Pseudo Code - Rendering
frameBuffer.bind()
depthTexture.bind()
foreach shadowCaster {
shadowCaster.bindVertexBuffer()
shadowCaster.bindIndexBuffer()
for i = 0,cascadeCount {
bindCascadeMatrix()
// FPS drop
glFramebufferTextureLayer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,depthTexture,0,i)
glDrawElements(GL_TRIANGLES,shadowCaster.triangleCount(),GL_UNSIGNED_INT,(void*)0)
//
}
}
The combination of these calls causes my FPS to go from 190 to 80. If I disable either call, it goes back to 190.
My assumption is that because each glFramebufferTextureLayer-call accesses the same texture, it blocks and waits for the previous rendering process to finish. Is that correct? If so, what can I do to avoid it?
I’ve tried generating a separate framebuffer for each layer and only calling glFramebufferTextureLayer once for each framebuffer during initialization, then binding the framebuffer during the rendering process, but the result is the same slowdown.