Does glMapBuffer data copy?

I am new to OpenGL. My question is: what does glMapBuffer do backstage? does it allocate new host memory, copy GL object data to it, and return a pointer?

Is it possible to get the same pointer for subsequent calls to this method? Of course, with the release between them.

+7
source share
2 answers

How often, the answer is "It depends." In some situations, glMapBuffer really allocates memory through malloc, copies the data there for your use, and glUnmapBuffer releases it.

However, a common way to implement glMapBuffer is to map memory. If you do not know what it is, take a look at the documentation for mmap system calls (* nix systems such as Linux, MacOS X) or CreateFileMap. What happens is interesting: modern operating systems manage the address space of running processes in virtual memory. Each time there is access to some kind of "memory", OS memory management uses the available address as an index in the translation table, redirecting operations to system RAM, swap space, etc. (Of course, the details are largely involved, memory management is one of the most difficult things in the kernel to understand). The driver can install its own access handler. Thus, the process can mmap something controlled by the driver into its address space, and each time it accesses it, the mmap driver handler is called. This allows the driver to map some GPU memory (via DMA) to the process address space and perform the necessary bookkeeping. In this situation, glMapBuffer will create such a memory mapping, and the pointer you receive will point to some address space of your process that was mapped into the DMA memory reserved for the GPU.

+9
source

He could do any of them. The specific behavior of glMapBuffer memory glMapBuffer determined by the implementation.

If you map a buffer to read, it can give you a pointer to that buffer object memory. Or he can select the pointer and copy it. If you type a buffer for writing, it can give you a pointer to that memory of the buffer object. Or he can give you a pointer and pass it.

There is no way to find out; you cannot rely on this by doing one thing. This should give you better performance than glBufferSubData , assuming that you can generate your data (from a file or from another location) directly to the memory that you return from glMapPointer . The worst case scenario would be equal to glBufferSubData performance.

Is it possible to get the same pointer for subsequent calls to this method?

Absolutely not.

+9
source

All Articles