When does glBufferSubData return? [duplicate]

廉价感情. 提交于 2019-12-11 07:25:01

问题


I want to transfer contents of a very large memory chunk to a sufficiently large GPU buffer and then immediately alter the contents of memory on CPU. Something like this in pseudo-code:

glBindBuffer(/*very_large_buffer*/);
glBufferSubData(/*very_large_memory_chunk*/);
memset(/*zeros*/, /*very_large_memory_chunk*/);

In this code, what does glBufferSubData actually do? Does it transfer very_large_memory_chunk somewhere before return or just schedules the transfer operation for possibly later execution? So if I start altering the CPU buffer immediately, is it possible that partially altered memory will be transfered, yielding garbage in GPU's very_large_buffer?

Note that I'm not asking about rendering calls. I know that if the buffer is used for rendering, transfer operations will wait until rendering is complete and vice versa. I want to know if OpenGL behaves the alike way in CPU-to-GPU transfer operations.


回答1:


OpenGL doesn't define how glBufferSubData has to be implemented: It can either copy the data immediately to GPU memory or it may defer the copy operation to a later point.

What OpenGL guarantees (OpenGL 4.5 Specification, Section 5.3) is that one can assume a call to glBufferSubData to be completed when the method returns. This means that every implementation that defers the CPU->GPU copy operation has to make sure that the CPU memory is copied before returning.

In conclusion: You can change the content of the pointer immediately after the glBufferSubData returns without modifying/destroying the buffers content.



来源:https://stackoverflow.com/questions/44667194/when-does-glbuffersubdata-return

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!