0

I am currently moving data from the CPU host to OpenGL memory and I am using pixel buffer object to do that. I can copy the whole image like so:

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
GLubyte * data = (GLubyte *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, 
                  GL_READ_WRITE);

// copying 4 channel 8 unsigned char data
memcpy(data, cpu_data, rows * cols * 4);

This is actually quite fast. However, now I need to copy a rectangular subimage of the data. So, in essence I will need to do multiple memcpy to do this, which could take a performance hit as I will have to copy things line by line. I was wondering if somehow there is a faster way to perform this operation.

Luca
  • 10,458
  • 24
  • 107
  • 234
  • It always depends. A `memcpy` per line might still be the fastest apporach. Another alternative would be to copy the whole image and only use parts of the PBO. You probably need this as source for texture data, so you can use `glTexSubImage2D()` in combination with `glPixelStorei()` to actually cut out the 2d sub-blocks during texture specification. A variation of that would be that you could get the PBO mapping _first_, and write the data directly there, instead of later copying them. – derhass May 15 '15 at 12:38
  • In the end, I ended up copying the data on the CPU itself to another sub-buffer as it was less complicated for hardly any loss of performance. I will leave this as an exercise for less stressy times :-) – Luca May 15 '15 at 14:03

0 Answers0