Name
glBufferData — creates and initializes a buffer object's data store
创建并初始化一个缓冲区对象的存储
Specification
void glBufferData( | GLenum | target, |
GLsizeiptr | size, | |
const GLvoid * | data, | |
GLenum | usage) ; |
Parameters
-
Specifies the target buffer object. The symbolic constant must be
GL_ARRAY_BUFFER
,GL_ATOMIC_COUNTER_BUFFER
,GL_COPY_READ_BUFFER
,GL_COPY_WRITE_BUFFER
,GL_DRAW_INDIRECT_BUFFER
,GL_DISPATCH_INDIRECT_BUFFER
,GL_ELEMENT_ARRAY_BUFFER
,GL_PIXEL_PACK_BUFFER
,GL_PIXEL_UNPACK_BUFFER
,GL_SHADER_STORAGE_BUFFER
,GL_TEXTURE_BUFFER
,GL_TRANSFORM_FEEDBACK_BUFFER
, orGL_UNIFORM_BUFFER
. -
Specifies the size in bytes of the buffer object's new data store.
指明缓冲区对象的存储的大小
-
Specifies a pointer to data that will be copied into the data store for initialization, or
NULL
if no data is to be copied.指向数据的指针,该指针所指向的数据将被复制到缓冲区内,如果为NULL则不复制数据
-
Specifies the expected usage pattern of the data store. The symbolic constant must be
GL_STREAM_DRAW
,GL_STREAM_READ
,GL_STREAM_COPY
,GL_STATIC_DRAW
,GL_STATIC_READ
,GL_STATIC_COPY
,GL_DYNAMIC_DRAW
,GL_DYNAMIC_READ
, orGL_DYNAMIC_COPY
.指明数据存储的使用方式,值为以上的符号常量之一
target
size
data
usage
Description
glBufferData
creates a new data store for the buffer object currently bound to target
. 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 is GL_READ_WRITE
.
glBufferData为现在绑定到target上面的缓冲区对象,创建一个新的存储,将会删除之前存在的所有数据存储。新的存储大小为size个byte。如果data不是NULL,那么用data所指向的数据来初始化这个缓冲区对象的存储。在初始状态,新的数据存储没有被映射的,它有一个NULL的映射指针,映射的访问权限为GL_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:
usage是告诉GL实现,这个缓冲区对象的数据存储的访问权限与方式。这样GL实现可以提高性能。这也不会限制数据存储的使用。usage可以分为两个部分:第一个是访问的频率(修改和使用),第二是访问的目的。访问频率可以是一下之一:
-
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.
存储的内容被应用程序修改,而作为GL绘制和图像指令的数据源被使用
READ
-
The data store contents are modified by reading data from the GL, and used to return that data when queried by the application.
存储的内容通过读取GL数据而被修改,用做返回值,返回应用程序的查询
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.
存储的内容通过读取GL而被修改,而用来作为GL绘制和图像指令的数据源被使用
Notes
If data
is NULL
, a data store of the specified size is still created, but its contents remain uninitialized and thus undefined.
如果data为NULL,函数会缓冲区的存储,但是里面的内容是为初始化的,未定义的。
Clients must align data elements consistent 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.
客户端程序必须按照客户平台的要求,对齐数据元素。对齐还必须满足附加的基础层次的要求:到一个大小为N字节的数据项的偏移量,必须是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.
Errors
GL_INVALID_ENUM
is generated if target
is not one of the accepted buffer targets.
GL_INVALID_ENUM
is generated if usage
is not GL_STREAM_DRAW
, GL_STREAM_READ
, GL_STREAM_COPY
, GL_STATIC_DRAW
, GL_STATIC_READ
, GL_STATIC_COPY
, GL_DYNAMIC_DRAW
,GL_DYNAMIC_READ
, or GL_DYNAMIC_COPY
.
GL_INVALID_VALUE
is generated if size
is negative.
GL_INVALID_OPERATION
is generated if the reserved buffer object name 0 is bound to target
.
GL_OUT_OF_MEMORY
is generated if the GL is unable to create a data store with the specified size
.
GL_OUT_OF_MEMORY表示创建失败