Wednesday, September 21, 2016

Define: glBufferData .. glNamedBufferData ... creates and initializes a buffer object's data store

Name

glBufferData, glNamedBufferData — creates and initializes a buffer object's data store

C Specification

void glBufferData(GLenum target,
 GLsizeiptr size,
 const GLvoid * data,
 GLenum usage);
 
void glNamedBufferData(GLuint buffer,
 GLsizei size,
 const void *data,
 GLenum usage);
 

Parameters

target
Specifies the target to which the buffer object is bound for glBufferData, which must be one of the buffer binding targets in the following table
buffer
Specifies the name of the buffer object for glNamedBufferData function.
size
Specifies the size in bytes of the buffer object's new data store.
data
Specifies a pointer to data that will be copied into the data store for initialization, or NULL if no data is to be copied.
usage
Specifies the expected usage pattern of the data store. The symbolic constant must be GL_STREAM_DRAWGL_STREAM_READGL_STREAM_COPYGL_STATIC_DRAW,GL_STATIC_READGL_STATIC_COPYGL_DYNAMIC_DRAWGL_DYNAMIC_READ, or GL_DYNAMIC_COPY.

Description

glBufferData and glNamedBufferData create a new data store for a buffer object. In case of glBufferData, the buffer object currently bound to target is used. ForglNamedBufferData, a buffer object associated with ID specified by the caller in buffer will be used instead.
While creating the new storage, any pre-existing data store is deleted. The new data store is created with the specified size in bytes and usage. If data is not NULL, the data store is initialized with data from this pointer. In its initial state, the new data store is not mapped, it has a NULL mapped pointer, and its mapped access isGL_READ_WRITE.
usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store. usage can be broken down into two parts: first, the frequency of access (modification and usage), and second, the nature of that access. The frequency of access may be one of these:
STREAM
The data store contents will be modified once and used at most a few times.
STATIC
The data store contents will be modified once and used many times.
DYNAMIC
The data store contents will be modified repeatedly and used many times.
The nature of access may be one of these:
DRAW
The data store contents are modified by the application, and used as the source for GL drawing and image specification commands.
READ
The data store contents are modified by reading data from the GL, and used to return that data when queried by the application.
COPY
The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.

Notes

If data is NULL, a data store of the specified size is still created, but its contents remain uninitialized and thus undefined.
Clients must align data elements consistently with the requirements of the client platform, with an additional base-level requirement that an offset within a buffer to a datum comprising N bytes be a multiple of N.
The GL_ATOMIC_COUNTER_BUFFER target is available only if the GL version is 4.2 or greater.
The GL_DISPATCH_INDIRECT_BUFFER and GL_SHADER_STORAGE_BUFFER targets are available only if the GL version is 4.3 or greater.
The GL_QUERY_BUFFER target is available only if the GL version is 4.4 or greater.


______________________________________________________________________
[00][LNK]

Is glBufferData actually allocating the memory based on the size on spot?

How much memory on the GPU will this take:
glBufferData(GL_ARRAY_BUFFER, 1000, NULL, GL_DYNAMIC_DRAW);
  • There's no guarantee that this will allocate any memory "on the GPU". The driver may well decide to put the buffer object in CPU memory instead of GPU.
  • I will instead assume your question is, "How much memory will be allocated for the buffer object?"
  • 1000 bytes. That's what you asked for, and that's what the driver will allocate.

And then, how will the occupied memory change when you do this on the same buffer:
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(poly), &poly);  
  • If the buffer object currently bound to GL_ARRAY_BUFFER has had storage allocated for it, and that storage contains at least sizeof(poly) bytes, then it will modify the buffer's storage by copying the first sizeof(poly) bytes from &poly into the storage.
  • If it does not have storage allocated, or if the storage is smaller than sizeof(poly) bytes, you'll get a GL_INVALID_VALUE error.
  • The size of the allocation is not changed. Just as the size of the allocation returned by malloc is not changed when you call memcpy on the returned pointer. glBufferData is like malloc; it allocates storage (with an option to memcpy into that storage). glBufferSubData is like memcpy; it copies data into existing storage.
  • Just as you can't memcpy without allocating first, you can't call glBufferSubData without calling glBufferData first.


[01][LNK]

..

No comments:

Post a Comment