PDA

View Full Version : Framebuffer object problem



Devdept2
11-29-2010, 04:50 AM
Hi,

I use framebuffer object to build a blurred shadow texture, using 2 fragment shaders(one for horizontal blur and one for vertical blur).

The first time I build the blurred texture, it is good.
But when I re-build the texture a second time, I get a crack in the texture (see top right corner of the attached file).

If I don't use the framebuffer objects, but instead read the texture from the color buffer with a glTexImage2D the texture is always fine, so the problem should be the framebuffer object.

Any ideas on where could be the problem?
Maybe I'm doing something wrong with the framebuffers?

This is my (simplified) code:

***************************************
fbo = gl.GenFramebuffersEXT();
gl.BindFramebufferEXT(gl.FRAMEBUFFER_EXT, fbo);

gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER_EXT, gl.COLOR_ATTACHMENT0_EXT, gl.TEXTURE_2D, sharpTextureName, 0);

DrawShadow(...); // draw the geometry on the sharp texture

gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER_EXT, gl.COLOR_ATTACHMENT0_EXT, gl.TEXTURE_2D, blurredTextureName, 0);

// activates texture ID zero
gl.ActiveTexture(gl.TEXTURE0);

// source texture for the shader (1st pass)
gl.BindTexture(gl.TEXTURE_2D, sharpTextureName);
gl.UseProgram(horizontalShaderProgram);

DrawQuad(...); // draw a quad with the sharp texture, to do the horizontal blur

//source texture for the shader (2nd pass)
gl.BindTexture(gl.TEXTURE_2D, blurredTextureName);
gl.UseProgram(verticalShaderProgram);

DrawQuad(...); // draw a quad with the previous texture to do the vertical blur

gl.UseProgram(0);


// rendering is directed back to original buffer
gl.BindFramebufferEXT(gl.FRAMEBUFFER_EXT, 0);

gl.DeleteFramebuffersEXT(fbo); // destroys FBO
***************************************

BionicBytes
11-29-2010, 08:42 AM
the devil may be in the detail; perhaps you will have to post the texture creation for FBO and copysubtex textures.
What's the filtering on both textures, and what tex format?

Devdept2
12-01-2010, 01:57 AM
Hi,

here is the creation of the textures:

Viewport.GenTextureName(ref sharpTextureName);
gl.BindTexture(gl.TEXTURE_2D, sharpTextureName);
// gl.RGBA8: important for ATI compatibility
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, Viewport.shadowTextureSize, Viewport.shadowTextureSize, 0, gl.BGRA, gl.UNSIGNED_BYTE, scan);
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP);
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP);




Viewport.GenTextureName(ref blurredTextureName);
gl.BindTexture(gl.TEXTURE_2D, blurredTextureName);
// gl.RGBA8: important for ATI compatibility
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, Viewport.shadowTextureSize, Viewport.shadowTextureSize, 0, gl.BGRA, gl.UNSIGNED_BYTE, scan);
// we don't have mipmaps so gl.LINEAR is mandatory, otherwise: empty texture
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP);
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP);