fbo once again.

Hello!

I have had many problems with fbo’s in past, later which i found out they were driver bugs of certain brand cards. Once again, i got a similar problem but this time i am not sure if it is a driver bug.
Tested on 3 different cards, 2 of them are NVIDIA and it works perfectly. The last card is an ATI, which is the one i had also troubles in past.
I can’t just send the copy of my code/shaders since it would make things more complicated than it is. I’ll just paste the related parts.

Not Working:


fb->bind();
dd.set(rs_culling, true);
dd.set(rs_depth_test, true);
dd.clear(0, 0, 0, 0);
{
	program_p& p = prg_basic;
	p->use();
	p->bind("mx_w", mx_identity);
	p->bind("mx_vp", mx_view_proj);
	p->bind("color", vec3(1, 1, 0));
	cube->render();
	p->unuse();
}
dd.set(rs_culling, false);
dd.set(rs_depth_test, false);
fb->unbind();
--copy into system fb


Uploaded with ImageShack.us

Working :


dd.set(rs_culling, true);
dd.set(rs_depth_test, true);
dd.clear(0, 0, 0, 0);
{
	program_p& p = prg_basic;
	p->use();
	p->bind("mx_w", mx_identity);
	p->bind("mx_vp", mx_view_proj);
	p->bind("color", vec3(1, 1, 0));
		cube->render();
	p->unuse();
}
dd.set(rs_depth_test, false);
dd.set(rs_culling, false);


Uploaded with ImageShack.us

In the first one i am rendering a cube into a texture then just copy outputs to the main framebuffer, viewports are same.
For the later i am rendering the same cube using the same program in same viewport but using only main framebuffer.

As you see the trouble is, the outputs are different. I am guessing if it is not a bug, it is about some undefined behavior at the vertex clipping stage at the end of vertex program. I am not using any of the fixed program matrices. AFAIK framebuffers use global state for everything. Could try and post more detail but remember it happens only in 1 of 3 cards i could find.

Thanks for reading.

Edit: copy paste error in code

Hmm not clear enough.

Both screenshots are from my ATI card.
For NVIDIA cards the outputs of the both codes are same as second screenshot, which it the expected behavior.

*cheers

I’m not sure what these variables are. p is a shader class program? When you bind your FBO, do you change the viewport to match or is it the same size as your window? If it’s happening on only a few cards, I’d guess that nVidia’s drivers do some guesswork and ATI’s don’t, and you need to add some very specific calls to your code.

I, for one, would start with glViewport() when switching to your FBO just to be sure. Like you said, the FBO should use the global specs, but I can’t find any docs to verify that. I know in the past, I’ve had to explicitly set the viewport every time. Not sure if it was because the FBO had a different size, or it was a requirement.

Yes, program_p is a shared_ptr to a program. Also i set viewport whenever i bind/unbind a framebuffer but in this case it is not even needed since frame and framebuffer (textures attached to this framebuffer) sizes are exact same.
fb->bind()


glBindFramebuffer(GL_DRAW_FRAMEBUFFER, id());
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, GLsizei(w), GLsizei(h));

fb->unbind()


glPopAttrib();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);