1

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?

3
  • So what does bindForWriting get called with? Commented Aug 8, 2013 at 13:14
  • bindForWriting gets called with the side of the cube to write on: GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z Commented Aug 8, 2013 at 21:40
  • I used glGetError to see which line generates errors. It seems like 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); produces GL_INVALID_VALUE Commented Aug 8, 2013 at 22:41

1 Answer 1

4

I found the problem:

GL_INVALID_ENUM is generated if target is one of the six cube map 2D image targets and the width and height parameters are not equal. Source.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.