0

Could you help me figure out why the following code is generating GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT

mBitmap = BitmapFactory.decodeFile(imagePath);
int[] handles = { 0 };
GLES30.glGenTextures(1, handles, 0);
if (checkGlError("glGenTextures")) {
    return 0;
}
outputTextureHandle = handles[0];
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, outputTextureHandle);
if (checkGlError("glBindTexture")) {
    return 0;
}
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR);
    GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
if (checkGlError("glTexParameteri")) {
    return 0;
}
int format = GLES30.GL_RGBA;
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, format, framebufferWidth, framebufferHeight, 0, format,
            GLES30.GL_UNSIGNED_BYTE, null);
if (checkGlError("glTexImage2D")) {
    return 0;
}
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
if (checkGlError("glBindTexture 0")) {
    return 0;
}

framebufferWidth = mBitmap.getWidth();
framebufferHeight = mBitmap.getHeight();

int[] rfhandles = { 0 };
GLES30.glGenRenderbuffers(1, rfhandles, 0);
if (checkGlError("glGenRenderbuffers")) {
    return 0;
}
int renderBufferId = rfhandles[0];
GLES30.glBindRenderbuffer(GLES30.GL_RENDERBUFFER, renderBufferId);
GLES30.glRenderbufferStorage(GLES30.GL_RENDERBUFFER, GLES30.GL_DEPTH_COMPONENT16, framebufferWidth,
                framebufferHeight);
GLES30.glBindRenderbuffer(GLES30.GL_RENDERBUFFER, 0);

int[] fbhandles = { 0 };
GLES30.glGenFramebuffers(1, fbhandles, 0);
if (checkGlError("glGenFramebuffers")) {
    return 0;
}
framebufferHandle = fbhandles[0];
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, framebufferHandle);
if (checkGlError("glBindFramebuffer")) {
    return 0;
}
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D,
                outputTextureHandle, 0);
if (checkGlError("glFramebufferTexture2D")) {
    return 0;
}
GLES30.glFramebufferRenderbuffer(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_RENDERBUFFER,
                renderBufferId);
if (checkGlError("glFramebufferRenderbuffer")) {
    return 0;
}
int framebufferStatus = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER);
        Log.d(TAG, "framebufferStatus: " + framebufferStatus);
if (GLES30.GL_FRAMEBUFFER_COMPLETE != framebufferStatus) {
    Log.d(TAG, "framebuffer incomplete");
    return 0;
}
if (checkGlError("glCheckFramebufferStatus")) {
    return 0;
}
Saeid Farivar
  • 1,667
  • 24
  • 43
  • 1
    I don't see any problem with this, I have this same code and it is working. I suggest checking that "outputTextureHandle" is valid and it does not have a dimension of zero. – andras Jan 14 '17 at 20:40
  • @andras you're right. I added the code for preparing `outputTextureHandle` too. I noticed that the dimensions were set to 0 as you had suggested. – Saeid Farivar Jan 15 '17 at 11:27

1 Answers1

1

yes, indeed @andras's suggestion was right. outputTextureHandle 's dimentions were set to 0.

I needed to move

framebufferWidth = mBitmap.getWidth();
framebufferHeight = mBitmap.getHeight();

before the code for preparing outputTextureHandle.

Saeid Farivar
  • 1,667
  • 24
  • 43