Filling and Copying Data in Buffers

Monday to Friday, a day, 7 am Beijing time on time updates -

After allocating storage space for your buffer object using glBufferStorage(), one possible next step is to fill the buffer with known data. Whether you use the initial data parameter of glBufferStorage(), use glBufferSubData() to put the initial data in the buffer, or use glMapBufferRange() to obtain a pointer to the buffer’s data store and fill it with your application, you will need to get the buffer into a known state before you can use it productively. If the data you want to put into a buffer is a constant value, it is probably much more efficient to call glClearBufferSubData() or glClearNamedBufferSubData(), whose prototypes are

After a good memory allocated buffer objects, the next step might turn to fill data to the memory. You can fill the data buffer can also be used glBufferSubData or glMapBufferRange data buffer is filled in after a good buffer memory allocation to allocate memory at the same time. Before you use buffer, you need to put buffer to a known state. If you want to brush into the buffer constant, then you can use glClearBufferSubData or glClearNamedBufferSubData to efficiently do it.

void glClearBufferSubData(GLenum target,
GLenum internalformat,
GLintptr offset,
GLsizeiptr size,
GLenum format,
GLenum type,
const void data);
void glClearNamedBuffeSubData(GLuint buffer,
GLenum internalformat,
GLintptr offset,
GLsizeiptr size,
GLenum format,
GLenum type,
const void
data);
These functions take a pointer to a variable containing the values that you want to clear the buffer object to and, after converting it to the format specified in internalformat, replicate the data across the range of the buffer’s data store specified by offset and size, both of which are measured in bytes. format and type tell OpenGL about the data pointed to by data. The format can be one of GL_RED, GL_RG, GL_RGB, or GL_RGBA to specify one-, two-, three-, or four-channel data, for example. Meanwhile, type should represent the data type of the components. For instance, it could be GL_UNSIGNED_BYTE or GL_FLOAT to specify unsigned bytes or floating-point data, respectively. The most common types supported by OpenGL and their corresponding C data types are listed in Table 5.3.

These functions use the data pointer to the location data to the refresh memory buffer, the data is converted into internalformat format specified by the number data refresh offset and size, the data size in bytes. and tells the OpenGL format type, the format of the data pointer to the data format may be a value GGL_RED, GL_RG, GL_RGB, or GL_RGBA, 1,2,3,4 used to mark data is data channel. type specified here is what each channel format. For example, it may be GL_UNSIGNED_BYTE or GL_FLOAT. The more common type reported in Table 5.3 in out
Filling and Copying Data in Buffers
Once your data has been sent to the GPU, it's entirely possible you may want to share that data between buffers or copy the results from one buffer into another. OpenGL provides an easy-to- use way of doing that. glCopyBufferSubData ( ) and glCopyNamedBufferSubData () let you specify which buffers are involved as well as the size and offsets to use.

When you send data to the GPU, you might want to share data with other buffer or copy data from one buffer to another buffer. Corresponding API OpenGL and provided that glCopyBufferSubData glCopyNamedBufferSubData, they are defined as follows

void glCopyBufferSubData(GLenum readtarget,
GLenum writetarget,
GLintptr readoffset,
GLintptr writeoffset,
GLsizeiptr size);
void glCopyNamedBufferSubData(GLuint readBuffer,
GLuint writeBuffer,
GLintptr readOffset,
GLintptr writeOffset,
GLsizeiptr size);
For glCopyBufferSubData(), the readtarget and writetarget are the targets where the two buffers you want to copy data between are bound. They can be buffers bound to any of the available buffer binding points. However, since buffer binding points can have only one buffer bound at a time, you couldn’t copy between two buffers that are both bound to the GL_ARRAY_BUFFER target, for example. Thus, when you perform the copy, you need to pick two targets to bind the buffers to, which will disturb the OpenGL state.

glCopyBufferSubData address data read and data write address only one node instead of binding buffer object tag itself. However, each specific binding node can only bind a buffer, so you can not be both binding buffer for data on GL_ARRAY_BUFFER copy. So, when you want to copy, you will need to buffer bound to go up two binding node, and then perform the copy operation, which effectively disrupt the OpenGL state machine

To resolve this, OpenGL provides the GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER targets. These targets were added specifically to allow you to copy data from one buffer to another without any unintended side effects. Because they are not used for anything else in OpenGL, you can bind your read and write buffers to these binding points without affecting any other buffer target.

To achieve this goal, OpenGL bindings provide two dedicated nodes, GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER, maybe a node can perform data copying between buffer, and no side effects. Because maybe it has the goods in addition to the copy function has no other function, so when you perform inter-buffer copies, and maybe change a node's status does not affect the logic of other OpenGL.

Alternatively, you can use the glCopyNamedBufferSubData() form, which takes the names of the two buffers directly. Of course, you can specify the same buffer for both readBuffer and writeBuffer to copy a region of data between two offsets in the same buffer object. Be careful that the regions to be copied don’t overlap, though, as in this case the results of the copy are undefined. You can consider glCopyNamedBufferSubData() as a form of the C function memcpy for buffer objects.

Similarly, you can use the second glCopyNamedBufferSubData, address write data address and read data directly into. You can also specify the reading and writing to the same buffer, and copying the data in the buffer in different regions. You can imagine this to be function memcpy

The readoffset and writeoffset parameters tell OpenGL where in the source and destination buffers to read or write the data, and the size parameter tells it how big the copy should be. Be sure that the ranges you are reading from and writing to remain within the bounds of the buffers; otherwise, your copy will fail. You may notice the types of readoffset, writeoffset, and size, which are GLintptr and GLsizeiptr. These types are special definitions of integer types that are at least wide enough to hold a pointer variable

readoffset and writeoffset tell OpenGL data offset position of the read and write addresses. size tell OpenGL size copy of the data. You do not have to ensure that cross-border, or else your copy will fail. You may have noticed GLintptr and GLsizeiptr, these data are integer data, they are marked for address pointer is already big enough.

Translations of this day to get here, see you tomorrow, bye ~

Get the latest plot first time, please pay attention to the Eastern Han Dynasty academy and the heart of the public graphic No.

Han College, waiting for you to play Oh

Guess you like

Origin blog.51cto.com/battlefire/2429958