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