Greetings OpenGL Jedi,
I’m wondering wish one is the fastest for updating a pixel buffer, glMapBuffer or glBufferData?
Init:
UInt *l_pixelBufferId = in_texture->GetPixelBufferId();
if (l_pixelBufferId[0] == 0)
{
glGenBuffers(1, &l_pixelBufferId[0]);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, l_pixelBufferId[0]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, l_image->GetSize(), 0, GL_STREAM_DRAW); /// NULL pointer reserves only memory space.
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
if (l_pixelBufferId[1] == 0)
{
glGenBuffers(1, &l_pixelBufferId[1]);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, l_pixelBufferId[1]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, l_image->GetSize(), 0, GL_STREAM_DRAW); /// NULL pointer reserves only memory space.
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
Update 1:
static Int l_index = 0;
Int l_nextIndex = 0;
l_index = (l_index + 1) % 2;
l_nextIndex = (l_index + 1) % 2;
UInt *l_pixelBufferId = in_texture->GetPixelBufferId();
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, l_pixelBufferId[l_index]);
glTexSubImage2D(l_dimension, in_level, in_x, in_y, l_image->GetWidth(), l_image->GetHeight(), l_image->GetImageFormat(), l_image->GetDataType(), 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, l_pixelBufferId[l_nextIndex]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, l_image->GetSize(), l_image->GetPixels(), GL_STREAM_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
Update 2:
glBufferData(GL_PIXEL_UNPACK_BUFFER, l_image->GetSize(), NULL, GL_STREAM_DRAW);
UChar *l_buffer = (UChar*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
if (l_buffer)
{
l_buffer = l_image->GetPixels(); /// Not working and that is why I started this thread.
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); /// Release pointer to mapping buffer.
}
Would we get any beneficial gain in using glMapBuffer in this case?