OpenGL Buffer Object
OpenGL Little Red Book P57 2.7-Section buffer object
The OpenGL 1.5 version adds buffer objects (Bufferobject) that allow applications to explicitly specify which data to store in the graphics server. OpenGL is designed in the client-server mode, assuming the application is on the client, and the graphics server is on another computer, so each time the image is rendered, the data is fetched from the client. In general, you can assume that OpenGL needs to read data from memory to video memory for calculation.
OpenGL 1.5: Vertex data can be stored in a server-side buffer object.
OpenGL 2.1: Support for pixel data (texture maps or pixel blocks).
OpenGL 3.1: Agree to Buffer object (Uniformbuffer object) for shaders.
Creating a Buffer Object
Returns the name that is not currently in use, buffers is an array of stored names, and you do not have to specify exactly what the name is.
void Glgenbuffers (Glsizei n,gluint *buffers);
Activate Buffer object
You first want to bind it. A bound buffer object represents which buffer object is affected by the selection of future operations (initialization of data or rendering with a buffer object).
void Glbindbuffer (Glenum target,gluintbuffer);
Target specifies the buffer type, which refers to the previously generated buffers ID.
Role:
1. Buffer is a Non-zero integer that is used for the first time, it creates a new buffer object and assigns the buffer to use as the name.
2, bind to a previously created buffer object, this buffer object becomes the active object.
3, when binding to a zero-value buffer, OPENGGL stop using the buffer object.
Data allocation and initialization of buffer objects after binding
void Glbufferdata (glenum target,glsizeiptrsize,const glvoid *data,glenum usage);
The OpenGL server memory (video memory) assigned to size storage unit, data is a pointer to the memory database, usage indicates how to read and write data blocks. Whether these blocks are often updated, suitable for drawing or for calculation, can be optimized by setting.
Update Buffer Object
1. Replaces part of the currently bound buffer with another buffer.
void Glbuffersubdata (Glenum target,glintptroffset,glsizeiptr size,const glvoid *data);
2. Glmapbuffer () returns a pointer to a buffer object that can write new values in the Buffer object, just as the array is assigned. Glmapbuffer () provides access to the entire collection of data in a buffer object. This method is useful if you need to modify most of the data in the buffer. However, this approach is inefficient if a large buffer only needs to update a small subset of the values.
Glvoid *glmapbuffer (glenum target,glenum access);
Glboolean Glunmapbuffer (glenum target);//complete access to the data store.
glvoid *glmapbufferrange (glenum target,glintptroffset,glsizeiptr length,glbitfield access);//offset and length The mapping range
glvoid *glflushmappedbufferrange (glenum target,glintptroffset,glsizeiptr length) is specified;//indicates that the value in a buffer range has been modified
Replication data between buffer objects
void Glcopybuffersubdata (Glenum readbuffer,glenum writebuffer, Glintptrreadoffset, Glintptr writeoffset
,
Glsizeiptrsize);
Clear Buffer Object
void Gldeletebuffers (Glsizei n,const gluint*buffers);//delete N buffer objects.
--------------------------------------------------------------------------------------------------------------- -------
Qglbuffer provides the ability to create and manipulate OpenGL buffer objects.
Qglbuffer Buffer1 (qglbuffer::indexbuffer);
Buffer1.create ();
Qglbuffer buffer2 = Buffer1;
The replication between buffers is a shallow copy, and when the copy is modified, the original data is modified together.
enum Qglbuffer::access
L Qglbuffer::readonly
L Qglbuffer::writeonly
L Qglbuffer::readwrite
enum Qglbuffer::type
L Qglbuffer::vertexbuffer
L Qglbuffer::indexbuffer
L Qglbuffer::P Ixelpackbuffer
L Qglbuffer::P Ixelunpackbuffer
enum Qglbuffer::usagepattern
Qglbuffer::streamdraw
Qglbuffer::streamread
Qglbuffer::streamcopy
Qglbuffer::staticdraw
Qglbuffer::staticread
Qglbuffer::staticcopy
Qglbuffer::D Ynamicdraw
Qglbuffer::D ynamicread
Qglbuffer::D ynamiccopy
Creates a new buffer object directly with the Qglbuffer () constructor.
Use the Create () function to wear a buffer in the GL server.
Allocates the cache size with allocate ().
Destroys the buffer with destroy (), including the storage block in the buffer.
Bind the buffer with bind () and release () binding.