OpenGL API 之 glVertexAttribPointer

6 篇文章 0 订阅
2 篇文章 0 订阅

glVertexAttribPointer

  定义通用顶点属性数据的数组

 C Specification

  format

void glVertexAttribPointer(GLuint index,
 	                       GLint size,
 	                       GLenum type,
 	                       GLboolean normalized,
 	                       GLsizei stride,
 	                       const void * pointer);

 Parameters

nametypedescription
indexGLuint Specifies the index of the generic vertex attribute to be modified.
sizeGLintSpecifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. Additionally, the symbolic constant GL_BGRA is accepted by glVertexAttribPointer. The initial value is 4.
typeGLenumSpecifies the data type of each component in the array. The symbolic constants GL_BYTEGL_UNSIGNED_BYTEGL_SHORTGL_UNSIGNED_SHORTGL_INT, and GL_UNSIGNED_INT are accepted by glVertexAttribPointer and glVertexAttribIPointer. Additionally GL_HALF_FLOATGL_FLOATGL_DOUBLEGL_FIXEDGL_INT_2_10_10_10_REVGL_UNSIGNED_INT_2_10_10_10_REV and GL_UNSIGNED_INT_10F_11F_11F_REV are accepted by glVertexAttribPointerGL_DOUBLE is also accepted by glVertexAttribLPointer and is the only token accepted by the type parameter for that function. The initial value is GL_FLOAT.
normalizedGLbooleanFor glVertexAttribPointer, specifies whether fixed-point data values should be normalized (GL_TRUE) or converted directly as fixed-point values (GL_FALSE) when they are accessed.
strideGLsizeiSpecifies the byte offset between consecutive generic vertex attributes. If stride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0.
pointerconst void *Specifies a offset of the first component of the first generic vertex attribute in the array in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target. The initial value is 0.

描述

        glVertexAttribPointer、glVertexAttribIPointer 和 glVertexAttribLPointer 指定在索引索引处的通用顶点属性数组的位置和数据格式,以便在渲染时使用。size 指定每个属性的组件数,并且必须为 1、2、3、4 或 GL_BGRA。Type 指定每个组件的数据类型,Stride 指定从一个属性到下一个属性的字节步幅,允许将顶点和属性打包到单个数组中或存储在单独的数组中。

        对于 glVertexAttribPointer,如果规范化设置为 GL_TRUE,则表示以整数格式存储的值在访问并转换为浮点时将映射到范围 [-1,1](对于有符号值)或 [0,1](对于无符号值)。否则,值将直接转换为浮点数,而无需规范化。

         对于 glVertexAttribIPointer,仅接受整数类型GL_BYTE、GL_UNSIGNED_BYTE、GL_SHORT、GL_UNSIGNED_SHORT、GL_INT GL_UNSIGNED_INT。值始终保留为整数值。

        glVertexAttribLPointer 指定与使用 64 位双精度组件声明的着色器属性变量关联的通用顶点属性数组的状态。类型必须GL_DOUBLE。索引、大小和步幅的行为与 glVertexAttribPointer 和 glVertexAttribIPointer 所述。

        如果指针不为 NULL,则必须将非零命名的缓冲区对象绑定到GL_ARRAY_BUFFER目标(请参阅 glBindBuffer),否则将生成错误。指针被视为缓冲区对象数据存储中的字节偏移量。缓冲区对象绑定 (GL_ARRAY_BUFFER_BINDING) 保存为索引索引的通用顶点属性数组状态 (GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)。

        指定通用顶点属性数组时,除了当前顶点数组缓冲区对象绑定外,大小、类型、规范化、步幅和指针将另存为顶点数组状态。

        要启用和禁用通用顶点属性数组,请调用 glEnableVertexAttribArray 和 glDisableVertexAttribArray with index。如果启用,则在调用 glDrawArrays、glMultiDrawArrays、glDrawElements、glMultiDrawElements 或 glDrawRangeElements 时使用通用顶点属性数组。

注意

        每个通用顶点属性数组最初都是禁用的,并且在调用 glDrawElements、glDrawRangeElements、glDrawArrays、glMultiDrawArray 或 glMultiDrawElements 时无法访问该数组。

        仅当 GL 版本为 4.4 或更高版本时,类型才接受 GL_UNSIGNED_INT_10F_11F_11F_REV。

参考

OpenGL 4 Reference Pages (khronos.org)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值