开发者

copying between interleaved openGL Vertex Buffer Objects

using opengl 3.3, radeon 3870HD, c++..

I got qu开发者_Go百科estion about interleaved arrays of data. I got in my application structure in vector, which is send as data to buffer object. Something like this:

struct data{
  int a;
  int b;
  int c;
};

std::vector<data> datVec;
...
glBufferData(GL_ARRAY_BUFFER, sizeof(data)*datVec.size(), &datVec[0], GL_DYNAMIC_DRAW);

this is ok I use this thing very often. But what I create is interleaved array so data are like:

a1,b1,c1,a2,b2,c2,a3,b3,c3

Now I send this thing down for processing in GPU and with transform feedback I read back into buffer for example b variables. So it looks like:

bU1, bU2, bU3

I'd like to copy updated values into interleaved buffer, can this be done with some single command like glCopyBufferSubData? This one isn't suitable as it only takes offset and size not stride (probably it's something like memcpy in c++)... The result should look like:

a1, bU1, c1, a2, bU2, c2, a3, bU3, c3

If not is there better approach than these 2 mine?

  1. map updated buffer, copy values into temp storage in app, unmap updated, map data buffer and itterating through it set new values

  2. separate buffers on constant buffer and variable buffer. constant will stay same over time but using glCopyBufferSubData the variable one can be updated in single call..

Thanks


glMapBuffer seems like a better solution for what you are doing.

The basic idea, from what I can tell, is to map the buffer into your address space, and then update the buffer manually using your own update method (iterative loop likely).

glBindBuffer(GL_ARRAY_BUFFER, buffer_id);
void *buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);

if (buffer == NULL)
  //Handle Error, usually means lack of virtual memory

for (int i = 1; i < bufferLen; i += stride /* 3, in this case */)
  buffer[i] = newValue;

glUnmapBuffer(GL_ARRAY_BUFFER);


I would separate the dynamic part with a static one (your point 2).

If you still want to keep them interleaved into a single buffer, and you have some spare video memory, you can do the following:

  1. Copy the original interleaved array into a backup one. This requires memory for all components rather than only dynamic ones, how it was originally.
  2. Transform Feedback into the original interleaved, carrying the static values unchanged.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜