Jump to content

  • Log In with Google      Sign In   
  • Create Account


FBO rendering behavior


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Seabolt   Members   -  Reputation: 610

Like
0Likes
Like

Posted 25 October 2013 - 03:58 PM

Hey guys, I have some questions about how an FBO may work.

I'm trying to incorporate FBOs into an existing rendering pipeline. To maintain current architecture I'm trying to use only one FBO for the program. I know it may not be ideal, but it should still work, (unless someone knows a better way to do MRT in OpenGL). I really can't know about any other targets I may be bound with when I create the render target, so I'm creating them and attaching them to the FBO later on.

So my current path is like such:

If it's a color target: Create a texture.

If it's a depth target: Create a renderbuffer.

Then when I bind the targets for a draw:
Bind a framebuffer
For each color target
     If it's a color target.
         Attach my texture to the frame buffer
    If it's a depth target
        Attach my renderbuffer to the frame buffer
Enable the draw buffer for any color target attachments

This runs with no problems, but in gDebugger I don't see anything being drawn to my color target's texture. Any ideas?

 

//
// Create our gl texture handle
//

glGenTextures( 1, &texture->m_Texture );																	
GL_ERROR( "Failed to generate render target texture" );
glBindTexture( GL_TEXTURE_2D, texture->m_Texture );															
GL_ERROR( "Failed to bind the render target texture when initializing" );

//
// Set the texture data parameters and some filtering data.
// TODO: We need to pass in platform agnostic filtering information here.
//
	
GLenum platformFormat = GetPlatformTextureFormat( format ); 
GLenum imageFormat = GetOpenGLImageFormat( platformFormat );
GLenum componentType = GetOpenGLComponentType( platformFormat );
glTexImage2D( GL_TEXTURE_2D, 0, platformFormat, width, height, 0, imageFormat, componentType, 0 );			
GL_ERROR( "Failed to set the texture image parameters for a render target texture" );

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);										
GL_ERROR( "Failed to set the filtering parameters for a render target texture" );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);											
GL_ERROR( "Failed to set the filtering parameters for a render target texture" );

and for depth stencil render targets I use this code:

 

pglGenRenderbuffers( 1, &m_PlatformData.m_TargetHandle );				
GL_ERROR( "Failed to generate render buffer handle" );

pglBindRenderbuffer( GL_RENDERBUFFER, m_PlatformData.m_TargetHandle );		
GL_ERROR( "Failed to bind the render buffer" );

pglRenderbufferStorage( GL_RENDERBUFFER, platformFormat, width, height );	
GL_ERROR( "Failed to set render buffer storage" );
		
pglBindRenderbuffer( GL_RENDERBUFFER, 0 );		
pglBindFramebuffer( GL_FRAMEBUFFER, m_FrameBufferObject ); 
GL_ERROR( "Failed to bind context frame buffer" );

int numDrawBuffers = 0;
GLenum drawBuffers[ VTG_MAX_RENDER_TARGETS ] = {GL_COLOR_ATTACHMENT0};
for( int currentTarget = 0; currentTarget < VTG_MAX_RENDER_TARGETS; ++currentTarget )
{
	if( m_BoundRenderTargets[ currentTarget ] )
	{
	        m_BoundRenderTargets[ currentTarget ]->Bind( currentTarget );
		drawBuffers[ currentTarget ] = GL_COLOR_ATTACHMENT0 + currentTarget;
		numDrawBuffers++;
	}
}

pglDrawBuffers( numDrawBuffers, drawBuffers );	
GL_ERROR( "Failed to specify draw buffers" );

if( m_BoundDepthTarget )
{
	m_BoundDepthTarget->Bind( -1 );
}

//
// Now we need to make sure we are complete.
//

CheckForCompleteness();

The bind function for a render target looks like this: 

 

	if( m_Texture )
	{
		//glBindTexture( GL_TEXTURE_2D, m_Texture->m_Texture );	
                GL_ERROR( "Failed to bind the texture" );
		pglFramebufferTexture2D( GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, m_Texture->m_Texture, 0 );
		GL_ERROR( "Failed to set the render target as a texture" );
	}
	else
	{
		//
		// Attach to the currently bound frame buffer object.
		// TODO: Need some way to ensure there is an FBO bound...
		//

		pglFramebufferRenderbuffer( GL_FRAMEBUFFER,
			attachment,
			GL_RENDERBUFFER,
			m_PlatformData.m_TargetHandle );
		GL_ERROR( "Failed to attach the render buffer to the frame buffer" );
	}
			
GL_ERROR( "Failed to bind the default back buffer" );

This code executes with no problem. Then when I update all render targets I do this code:

 


 


Perception is when one imagination clashes with another

Sponsor:

#2 3TATUK2   Members   -  Reputation: 706

Like
0Likes
Like

Posted 25 October 2013 - 04:14 PM

First, i'd check whether your framebuffer is proper ...

printf("%i\n",glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE);

Also, I'd avoid using a renderbuffer for the depth.. just use a regular GL_DEPTH_COMPONENT texture....

 

Lastly, probably can try to avoid re-attaching the textures to the framebuffer each time. Just attach them once when you create it and they're still attached next time you bind the framebuffer.



#3 Seabolt   Members   -  Reputation: 610

Like
0Likes
Like

Posted 25 October 2013 - 04:21 PM

I am check the framebuffer completeness, it's all good. 
I'm using a renderbuffer for the depth because it's faster and I want to test renderbuffer functionality as well.

My problem is that I don't know what render targets are going to be bound to a framebuffer each frame, so I have to rebind the texture/renderbuffers each frame.


Perception is when one imagination clashes with another

#4 Seabolt   Members   -  Reputation: 610

Like
0Likes
Like

Posted 25 October 2013 - 04:42 PM

So it seems that it will write to the render target texture as long as the texture is bound. If I bind another texture it seems to overwrite it. Should that happen? What if I want to bind a texture for something I want to draw into the render target, how would I do that?


Perception is when one imagination clashes with another

#5 Seabolt   Members   -  Reputation: 610

Like
0Likes
Like

Posted 25 October 2013 - 04:57 PM

Jesus christ, I apologize guys, I'm all over the place right now.

I can get the model to draw if I don't use a depth stencil buffer.

Is it possible the texture and renderbuffer are conflicting somehow? The renderbuffer is being bound to the GL_DEPTH_STENCIL_ATTACHMENT point of the FBO so it shouldn't be overwriting anything...


Perception is when one imagination clashes with another




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS