Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Correct orphaning of mapped buffer data


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
No replies to this topic

#1 RenHoek   Members   -  Reputation: 119

Like
0Likes
Like

Posted 07 August 2013 - 06:44 PM

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, 07 August 2013 - 06:57 PM.


Sponsor:



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