I’d like to upload a bunch of vertices of meshes (simple arrays of float values x,y,z) into a single vbo. I’ve created a unique buffer with the total ammount of bytes needed to contains all the vertices
glBufferData(buffer->glTarget, buffer->nTotalBytes, 0, buffer->glUsage);
then reading each mesh vertices array i’d like to copy those bytes into the buffer, each at the right offset inside the VBO. to do that i calculate the offset and size of each array to copy then i call a function that simply do this
// Bind the buffer for use glBindBuffer(buffer->glTarget, buffer->glId); GLvoid* data_pointer = glMapBufferRange( buffer->glTarget, offset, // Offset size, // Size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); // copy the data uploadFunction(data_pointer); // flush the data glFlushMappedBufferRange(buffer->glTarget, offset, size); // release the buffer pointer glUnmapBuffer(buffer->glTarget); // Unbind the buffer glBindBuffer(buffer->glTarget, 0);
offset is 0 at the begin, size is the size of the array in bytes, then the next mesh offset+= size, size = new_mesh_size. The problem is that at the second mesh copy, when i flush the data, OpenGL gives me a GL_INVALID_VALUE error. I checked all the ranges values and everything is ok (the buffer is like 2 Mbytes and the first mesh is like 3000 vertices, the second 1000) and if the ranges are wrong i’d assume glMapBufferRange would give me an error first, isn’t it?
If i remove the flush and let it do the operation automatically with glUnmapBuffer there’s no error. Any ideas why i cannot flush the second slice?