Jump to content
  • Advertisement
Sign in to follow this  
Eldritch

Problems using FBO for z-culling pass

This topic is 4326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to develop a small application for an assignment in school. We have to use Java and the JOGL library to perform this. Now, I have just implemented FBO's to support me with offscreen rendering, and I want to use this to make a z-cull pass. Here is my code for the generation of the FBO:
public COGLRenderSurface2(GL gl, String name, int height, int width, int type)
	{
		super(name, height, width);
		m_refGL = gl;
		
		if (CExtensionManager.Instance().m_bFrameBuffer)
		{
			int[] tempId = new int[1];
			m_refGL.glGenFramebuffersEXT(1, tempId, 0);
			m_iFrameBuffer = tempId[0];
			m_refGL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, m_iFrameBuffer);
		
			// Color surface.
			if ((type & Type_Color_Surface) == 1)
			{
				m_refColorTexture = COGLTextureLibrary.Instance().LoadTexture(m_name, CTextureLibrary.Instance().Target_2D);
				if (!m_refColorTexture.IsValid())
				{
					((COGLTexture)m_refColorTexture).LoadDynamic(GL.GL_RGB, GL.GL_RGB, width, height, GL.GL_UNSIGNED_BYTE);
				}
				m_refGL.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,
												  GL.GL_TEXTURE_2D, m_refColorTexture.GetId(), 0);
			}
			
			// Depth surface.
			else if ((type & Type_Depth_Surface) == 2)
			{
				int[] tempDepth = new int[1];
				m_refGL.glGenRenderbuffersEXT(1, tempDepth, 0);
				m_iDepthBuffer = tempDepth[0];
				m_refGL.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, m_iDepthBuffer);
				m_refGL.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, width, height);
				m_refGL.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT,
													 GL.GL_RENDERBUFFER_EXT, m_iDepthBuffer);
				
				m_refDepthTexture = COGLTextureLibrary.Instance().LoadTexture(m_name, CTextureLibrary.Instance().Target_2D);
				if (!m_refDepthTexture.IsValid())
				{
					((COGLTexture)m_refDepthTexture).LoadDynamic(GL.GL_DEPTH_COMPONENT, GL.GL_DEPTH_COMPONENT, width, height, GL.GL_UNSIGNED_BYTE);
				}
				m_refGL.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_COMPONENT,
												  GL.GL_TEXTURE_2D, m_refDepthTexture.GetId(), 0);
				
				m_refGL.glDrawBuffer(GL.GL_NONE);
				m_refGL.glReadBuffer(GL.GL_NONE);
			}
			
			// Verify that everything is correct.
			int error = m_refGL.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
			switch (error)
			{
			case GL.GL_FRAMEBUFFER_COMPLETE_EXT:
				break;
			case GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT:
				CLog.Instance().WriteToLog("FBO configuration unsupported!");
				break;
			default:
				CLog.Instance().WriteToLog("FBO programmer error!");
				break;
			}
			
			m_refGL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
		}
		else
		{
			CLog.Instance().WriteToLog("Error: FBO extension not supported on this system!");
		}
	}

You can either create a surface of type "Color" or of type "Depth". The color type is like a regular texture for offscreen rendering while the depth type was meant to be like a depth buffer where I can store data for use in stuff like a z-cull pass. Here is the z-cull shader:
// An empty material, which simply transforms the vertex and sets the color to white.

//------------------------------------
float4x4 matWorldViewProjection:WorldViewProjection;

struct vertexInput
{
    float4 pos : POSITION;
};


struct vertexOutput {
    float4 pos : POSITION;
};

//------------------------------------
vertexOutput VS_Transform(vertexInput IN, uniform float4x4 matWVP) 
{
	vertexOutput OUT;
	OUT.pos = mul( matWVP,IN.pos );
	return OUT;
}

float4 PS_RedColor(vertexOutput IN):COLOR
{
	float4 color = float4(1,1,1,1);
	return color;
}
//-----------------------------------
technique zonly
{
    pass p0
    {		
		VertexProgram = compile arbvp1 VS_Transform(matWorldViewProjection);
		FragmentProgram = compile arbfp1 PS_RedColor();
		ClearDepth = 1.0;
		DepthTestEnable = true;
		DepthFunc = LEqual;
		DepthMask = true;
		
	       	CullFaceEnable = true;
	       	FrontFace = CCW;
	       	ColorMask = bool4(false,false,false,false);
    }
}

It's an FX file, which should be pretty self-explanatory. When I render, I don't see anything particular indicating it to work, and when I want to print the "depth texture" from a Depth type surface, I see nothing except the black screen. I have tried for days to find something on the Internet about this sort of thing, but it seems like people only seem to use FBO's for shadowmaps and stuff. Anybody here who can shed some light on this?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!