0
votes

I've been trying to add shadow mapping to my OpenGL ES project and I've just found out that my framebuffer status returns GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT.

Here's my code to create the framebuffer :

//  create fbo
int[] fboPtr = new int[1];
GLES30.glGenFramebuffers(1, fboPtr, 0);
fbo = fboPtr[0];


//  use fbo
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, fbo);


//  create depthMap
int[] depthMapPtr = new int[1];
GLES30.glGenTextures(1, depthMapPtr, 0);
depthMap = depthMapPtr[0];


//  use depthMap
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, depthMap);

GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT, size, size,
        0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_FLOAT, null);

GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_REPEAT);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_REPEAT);

GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_TEXTURE_2D, depthMap, 0);


//  draw buffer
int[] buffer = {GLES30.GL_NONE};
GLES30.glDrawBuffers(1, buffer, 0);
GLES30.glReadBuffer(GLES30.GL_NONE);

int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);

I've bound the texture, so I don't know what can be causing the error.

1
Can you check glGetError() status after the glTexImage2D call? It's possible the texture wasn't created correctly, so the attachment process failed. - solidpixel

1 Answers

1
votes

Your internalFormat parameter for glTexImage2D isn't legal.

https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml

You need to use a sized internal format for depth. So I think this should work:

GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_DEPTH_COMPONENT32F,
                   size, size, 0, GLES30.GL_DEPTH_COMPONENT, GLES30.GL_FLOAT, null);

Off topic: Learn to use the KHR_debug extension if you can - it gives you readable error messages, often with a precise reason why something failed.