Hello there.
I’m sorry for my very bad english, but I will try to do a maximum effort for you can understand what I want to say :).
So, I want to create a little rendering engine with OpenGL 4.4.
Why OpenGL 4.4? Simply because we can improve performance with Bindless Texture, Buffer storage, and other :).
I work on Ubuntu 14.4 LTS.
I have a many problems with buffer storage for update my buffers.
I think it’s a problem of synchronisation, because when I make my render, I have a display issue. Indeed, I have the impression the data used during my render is a “older” data. For example, when I render my object with a matrix, the matrix is a light matrix or inverse. I think it’s a synchronisation issue too, because when I test a “old school” (glBufferData and glMapBuffer and glUnmapBuffer), I don’t have this problem…
So, this is my code.
It’s my way to set and “map” my buffer
void Buffer::allocate(u32 index, u32 size)
{
if(index >= mId.size())
throw "Buffer : Index out of rang";
u32 flags = GL_MAP_COHERENT_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT;
glNamedBufferStorageEXT(mId[index], size, nullptr, flags);
mPtr[index] = glMapNamedBufferRangeEXT(mId[index], 0, size, flags);
mSize[index] = size;
}
void *Buffer::map(u32 index)
{
return mPtr[index];
}
And when I want update my buffer, I use this :
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
MVPandM *matrixPtr = manager->mapMVPandM();
TexHandle *texturePtr = manager->mapTexHandle();
auto it = m.begin();
for(u32 i = 0; i < mNumMeshes; ++i)
texturePtr++->handle = mTexHandle[i];
for(u32 i = 0; i < nMatrix; ++it, ++i)
*matrixPtr++ = *it;
glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000000000);
glDeleteSync(sync);
mapMVPandM and mapTexHandle is a map function in a other object.
Thanks to you, and if you can’t understand one sentence, you can ask to me :).
Thanks !