Problems with FrameBuffer and glDrawBuffers

So first time poster.

I’m working with OpenGL ES 3.0 on Android in C++.

Recently I’ve been trying to add a G-Buffer to my rendering engine and I keep getting unusual behavior and not a straight answer on how to set this up properly.

I’ve created an FBO with 4 textures attached using glFramebufferTexture2D(…).

Everything seems fine until I try to rebind the Frame Buffer Object in my Draw step where the call to glBindFramebuffer(GL_FRAMEBUFFER, mFrameNameId) gives me an Invalid return code for its parameters. mFrameNameId is value 1 which was assigned when I used glGenFrameBuffer. It also doesn’t give this error when I initialize the buffer with my textures.

In addition glDrawBuffers(4,…) with the 4 GL_COLOR_ATTACHMENT0…GL_COLOR_ATTACHMENTN tends to crash my code.

As far as I can tell I’ve done everything write. I’ve even tried it on other Android devices to make sure it wasn’t some sort of chipset compatibility problem. Any help would be appreciated. Thanks in advance.

How are you getting this return code? glBindFramebuffers doesn’t return a value.

Are you checking for GL errors in your code? Are you getting any? If so, what is the first GL call that triggers one:

There is also an eglGetError you can use to check for errors from EGL functions.

[QUOTE=Dark Photon;1281051]How are you getting this return code? glBindFramebuffers doesn’t return a value.

Are you checking for GL errors in your code? Are you getting any? If so, what is the first GL call that triggers one:

There is also an eglGetError you can use to check for errors from EGL functions.[/QUOTE]

Yes I’m using glError() to get my GLenum which is giving me GL_INVALID_OPERATION after the second attempt to bind my frame buffer object. The name is good and even my check of the buffer with glCheckFramebufferStatus(GL_FRAMEBUFFER); says that it completes. I peppered in some more glError calls with a macro in the stages after initialization, but these areas are relatively untouched from when I had them rendering straight to the back buffer. They still work now. I get one error during my shader compilation phase, but this maybe due to something trivial or a false positive as it doesn’t impact the shader binary that is produced.

At present I do not get any errors from eglGetError().

Did you call glGetError() before calling glBindFramebuffer()? According to the specification, the only error which can be generated by glBindFramebuffer() is GL_INVALID_ENUM if the target is incorrect.

(GL_OUT_OF_MEMORY and GL_CONTEXT_LOST, can be generated by any command even if all parameters and state are correct).

There’s no requirement for the framebuffer passed to glBindFramebuffer() to be complete or otherwise valid. Indeed, you can’t attach renderbuffers or textures to a framebuffer without binding it first. The first time you bind a framebuffer, the “name” doesn’t even refer to a framebuffer object (glGenFramebuffers() only allocates names; the framebuffer object itself is only created the first time it is bound).

A framebuffer only needs to be complete in order to render to it or read from it; otherwise, the rendering or reading command will fail with a GL_INVALID_FRAMEBUFFER_OPERATION.

[QUOTE=GClements;1281057]Did you call glGetError() before calling glBindFramebuffer()? According to the specification, the only error which can be generated by glBindFramebuffer() is GL_INVALID_ENUM if the target is incorrect.

(GL_OUT_OF_MEMORY and GL_CONTEXT_LOST, can be generated by any command even if all parameters and state are correct).

There’s no requirement for the framebuffer passed to glBindFramebuffer() to be complete or otherwise valid. Indeed, you can’t attach renderbuffers or textures to a framebuffer without binding it first. The first time you bind a framebuffer, the “name” doesn’t even refer to a framebuffer object (glGenFramebuffers() only allocates names; the framebuffer object itself is only created the first time it is bound).

A framebuffer only needs to be complete in order to render to it or read from it; otherwise, the rendering or reading command will fail with a GL_INVALID_FRAMEBUFFER_OPERATION.[/QUOTE]

I guess I need to pepper in some more error checks, but you’re right I’m getting this error right before glBindFrameBuffer(). Shouldn’t the buffer still get set and my textures rendered too if everything else is working?

If you’re getting an error, “everything else” isn’t working. Whichever command is generating the error, presumably that command was issued for a reason, and the fact that it failed is going to affect something.

Alright, I’ve run down all the glErrors and fixed them. Mostly results of some minor refactoring bugs.

Tested my scene rendering on the back buffer so I know all that code is working fine and we are now back to the framebuffer problem with my textures not getting drawn to. At least to the best of knowledge anyway.

So far this code crashes my engine:

 
GLenum targets[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3};
glDrawBuffers(4,targets);

not all the examples I’ve seen so far have used glDrawBuffers either.

OGL Tracer that comes with Android Studio (or part of the Android dev kit) shows my scene being draw for at least location=0 in my fragment shader. I can’t see the other 4 textures either due to lack of experience with a tool or a deficiency with the tool itself (couldn’t find an option to help with that).

I’ve tried switching my buffer back to the Back Buffer, then back to the Frame Buffer Object I have created. What happens is that I’m presented with a black render for each draw call made for the same scene instead of a step by step rendering of the scene. As far as I can tell the Depth Buffer is intact and preventing these draws from occurring and that something is clearing my textures every time I call glBindFrameBuffers or I’m having a different problem all together and they are never getting set in the first place.

Thank you for the help thus far.

I think I have tracked down the issue and it does appear that a combination of issues were getting in the way of me solving this problem.

Tablet in question doesn’t seem to fully support OpenGL ES 3.0 and I hadn’t properly rewrote my Shaders in proper ESSL so my phone which I knew for certain supported OGLES 3.0 for some reason didn’t throw any errors till I fixed the other issues.

Guess I’ll have to see about supporting this under OGL ES2.0

So resolved and thanks again.