In order to support shadow mapping for point lights, I need to render my depth values to the 6 sides of a cubemap.
My init function looks like this:
public void init(int width, int height) {
fboId = GL30.glGenFramebuffers();
GL11.glEnable(GL13.GL_TEXTURE_CUBE_MAP);
cubeMap = GL11.glGenTextures();
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, cubeMap);
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP,
GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP,
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S,
GL11.GL_CLAMP);
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T,
GL11.GL_CLAMP);
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R,
GL11.GL_CLAMP);
for (int i = 0; i < 6; i++)
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
GL14.GL_DEPTH_COMPONENT32, width, height, 0,
GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer) null);
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
}
This is the function I use to bind a side of the cube map to my FBO:
public void bindForWriting(int target) {
// target is GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X etc.
GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, fboId);
GL30.glFramebufferTexture2D(GL30.GL_DRAW_FRAMEBUFFER,
GL30.GL_DEPTH_ATTACHMENT, target, cubeMap, 0);
// Disable writes to the color buffer.
GL11.glDrawBuffer(GL11.GL_NONE);
int fboStat = GL30.glCheckFramebufferStatus(GL30.GL_DRAW_FRAMEBUFFER);
if (fboStat != GL30.GL_FRAMEBUFFER_COMPLETE) {
// fboStat is always == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
}
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
Unfortunately, the FBO is incomplete and I can't figure out why. The Khronos site says: "Not all framebuffer attachment points are framebuffer attachment complete. This means that at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached. Color-renderable formats include GL_RGBA4, GL_RGB5_A1, and GL_RGB565. GL_DEPTH_COMPONENT16 is the only depth-renderable format. GL_STENCIL_INDEX8 is the only stencil-renderable format."
I did not destroy the cube map and width/height are > 0. I can't see why GL_DEPTH_COMPONENT16 is the only depth-renderable format, because the FBO I am using for spot light shadow mapping works fine with GL_DEPTH_COMPONENT32. If I change it to GL_DEPTH_COMPONENT16, the same error still happens.
Any advice?
bindForWriting
get called with? – Nicol BolasGL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL14.GL_DEPTH_COMPONENT32, width, height, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer) null);
producesGL_INVALID_VALUE
– Uli Holtmann