Hi,
I have written an app that uses the persistent mapping technique.
I use 2 different threads on the app - upload thread and drawing thread.
The upload thread uploads the data to the mapped buffer using the std:copy command, while the drawing thread displays the data using the openGL commands.
when I try to upload a big amount of data that is changing fast (e.g. ~5000 triangle every 5 milliseconds), the display shows sometime garbage.
I tried to perform the same code synchronously, e.g upload and draw on the same thread, and everything looks good.
I used debug printings and it seems that the same offsets and data I upload on one thread is what I read and display on the other thread.
The mapping is like this:
glBindBuffer(m_bufferDataType, m_glBufferId);
const GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
glBufferStorage(m_bufferDataType, m_bufferSize, NULL, flags);
m_glBufferDataPtr = (char*)glMapBufferRange(m_bufferDataType, 0, m_bufferSize, flags);
glBindBuffer(m_bufferDataType, 0);
The upload looks like that:
std::copy(_data.begin(), _data.end(), (T*)(m_glBufferDataPtr + m_uploadOffset));
I use fences to sync the buffer for not uploading data the a section while it is in use of the GPU.
Does anyone have an idea why it is happening?
Thanks.