Damian
Damian

Reputation: 5561

glGenFramebuffersOES fails in Android

I'm porting a game from iPhone to Android. I'm using NDK and OpenGLES 2.0.
I'm having a problem with the following code to create a framebuffer with a texture attached that I'll later use to render to it:

glGenFramebuffersOES(1, &glTextureFrameBuffer);
glBindFramebufferOES(GL_FRAMEBUFFER, glTextureFrameBuffer);

// attach renderbuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glName, 0);

GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status == GL_FRAMEBUFFER_COMPLETE) {
    cout << "Framebuffer completed" << endl;
} else {
    cout << "Framebuffer error: " << status << endl;
}

// unbind frame buffer
glBindFramebufferOES(GL_FRAMEBUFFER, 0);

cout << "CREATED FRAMEBUFFER ID: " << glTextureFrameBuffer << endl;

This prints the following:

Framebuffer error: 0
CREATED FRAMEBUFFER ID: 4294967295

And rendering to that texture does nothing, so something is failing and the id returned by glGenFramebuffersOES (4294967295) makes me think that the framebuffer is never generated.

The code is working perfectly on iOS.
Any idea what could be the problem?

EDIT:

I added error ckecking: I'm getting GL_INVALID_OPERATION after glFramebufferTexture2D.
But I'm also getting GL_INVALID_VALUE error after glGenFramebuffersOES. The strange thing is that on iphone I get that error too but everything works anyway.

I've read the OpenGLES docs and glGenFramebuffersOES sets GL_INVALID_VALUE error if the first parameter is negative, wich is not the case.

EDIT 2:

My bad, glGenFramebuffersOES is not setting any error, GL_INVALID_VALUE was being set somewhere before.
But still, glFramebufferTexture2D is setting GL_INVALID_OPERATION, and it also seems weird to me that the id returned by glGenFramebuffersOES is 4294967295.

Any idea?

Upvotes: 0

Views: 2190

Answers (2)

cbw
cbw

Reputation: 266

If anyone else is wondering why glGenFramebuffersOES() isn't working, I don't think it's supported in OpenGL 2.0 for Android.

If you remove the explicit version setting in Android, setEGLContextClientVersion(2);, it should allow you to call GLES11Ext.glGenFramebuffersOES(). However, you then lose all ability to use the GLES20 library.

This is based on my guess because when you call checkIfContextSupportsExtension(gl, "GL_OES_framebuffer_object"); using the code below:

private boolean checkIfContextSupportsExtension(GL10 gl, String extension) {
    String extensions = " " + gl.glGetString(GL10.GL_EXTENSIONS) + " ";
    return extensions.indexOf(" " + extension + " ") >= 0;
}

It will return false if client verison was set to 2

Upvotes: 1

Mārtiņš Možeiko
Mārtiņš Možeiko

Reputation: 12927

Why are you using glBindFramebufferOES instead of glBindFramebuffer? OpenGL ES 2.0 has framebuffers in its core spec, not in OES extension (like OpenGL ES 1.0 have).

You are already using glFramebufferTexture2D function not glFramebufferTexture2DOES, right? So use the glGenFramebuffers function and also glGenFramebuffers.

Upvotes: 2

Related Questions