Jump to content
  • Advertisement
Sign in to follow this  
RenHoek

OpenGL Correct orphaning of mapped buffer data

This topic is 1840 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

Hi guys

 

So I have a uniform buffer which I use for material constants.

This does not change very often, but it does change from time to time.  Which means I need to update the buffer contents sometimes during the course of a render.

The following shows a snippit from my refreshUniforms() function.

When exectuted first, it creates the uniform buffer.  And for all other executions, it simply updates the uniform buffer  ( with care to avoid Implicit synchronization )

 

There are two ways I have this implemented ATM.

 

1)  orphaning

 

if ( m_uniformBuffer == 0 )

{

  // init the buffer

  glGenBuffers( 1, &m_uniformBuffer );                                            //  create new buffer
  glNamedBufferDataEXT(m_uniformBuffer, bufferSize, buf.get(), GL_STATIC_DRAW);   //  upload new data

}

else

{

  // refresh the buffer

  glNamedBufferDataEXT(m_uniformBuffer, bufferSize, NULL, GL_STATIC_DRAW);        //  orphan prev data
  glNamedBufferDataEXT(m_uniformBuffer, bufferSize, buf.get(), GL_STATIC_DRAW);   //  upload new data

}

 

2)  Via Map/UnMap

 

if ( m_uniformBuffer == 0 )

{

  // init the buffer

  glGenBuffers( 1, &m_uniformBuffer );                                        //  create buffer
  glNamedBufferDataEXT(m_uniformBuffer, bufferSize, NULL, GL_DYNAMIC_DRAW);   //  initialise

}

else

{

  //  orphan prev data

  glNamedBufferDataEXT(m_uniformBuffer, bufferSize, NULL, GL_DYNAMIC_DRAW);    // is this line needed?

}

 

//  upload new data
GLvoid* data = glMapNamedBufferEXT( m_uniformBuffer, GL_WRITE_ONLY );
memcpy( (void*)data, (const void*)buf.get(), bufferSize );
bool mapResult = glUnmapNamedBufferEXT( m_uniformBuffer );

 

 

Question

 

I was previously performing option 1.  But need to move to option 2 due to a driver issue.  dont ask... : (

So my question...

It is necessary to perform orphaning for option 2?

If so, why?  Shouldn't the driver manage the uploading of the memory for me?  At the right time?

 

Cheers!

Ren

Edited by RenHoek

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!