zoukankan      html  css  js  c++  java
  • glVertexAttribPointer

    glVertexAttribPointer的详细用法,参考 http://docs.gl/gl4/glVertexAttribPointer

    这篇文章做一下简单的记录:

    先按照我自己的理解,做一下说明:

    attribute:  position, UV坐标,Color等属性。
    vertex:     一组 attribute

    函数声明:

    void glVertexAttribPointer(GLuint index,          // typedef unsigned int GLuint;
                    GLint size,      // typedef int GLint;
                    GLenum type,       // typedef unsigned int GLenum;
                    GLboolean normalized, // typedef unsigned char GLboolean;
                    GLsizei stride,      // typedef int GLsizei;
                    const GLvoid * pointer); // typedef void GLvoid;

    index: 对应顶点着色器的 layout(localtion = 0)

    size:  attribute 的大小, 例如,GL_BGRA是4。 position(x, y) 是2。

    type: 初始值是 GL_FLOAT

    normalized: GL_TRUE时保存的数据 int会映射到[-1,1],unsigned int会映射到[0, 1]。(byte好像会映射到[0, 255]) 。 GL_FLOAT时会直接使用float的数据。

    stride: 一组vertex的大小(连续的attribute组之间的间隔)

    pointer: 这个参数的类型是void*, 要获取数据的偏移(attribute的偏移)。例如 vertex的内容为: position, color,UV. 这个时候如果想获取color, 则需要跳过 position的大小。

    相关的程序代码:

    // position,          color,       uv坐标
    float
    data[] = { -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }; unsigned int buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), positions, GL_STATIC_DRAW);
    //position glEnableVertexAttribArray(
    0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, 0);

    //color
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (GLvoid*) 2 * sizeof(float));

    //uv
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (GLvoid*) 5 * sizeof(float));
  • 相关阅读:
    工具进阶:如何利用 MAT 找到问题发生的根本原因
    性能优化步骤
    搞定内存泄漏
    jvm配置示例
    vue的transition相同元素通过v-if,以及绑定key的区别
    安装nvm之node版本管理器
    在ts中定义变量类型的dva使用方法
    dva的全部用法
    react父子组件传值之二,ref传值(父组件调用子组件的值和方法) useRef+useImperativeHandle(hook)
    react父子组件传值方式一之props方法
  • 原文地址:https://www.cnblogs.com/weishuan/p/12927198.html
Copyright © 2011-2022 走看看