glVertexAttribpointer 是否仅用于顶点、UV、颜色和法线?没有其他的?

Is glVertexAttribpointer used only for vertex, UVs, colors, and normals ? Nothing else?

我想合并一个随顶点变化的自定义属性。在这种情况下,它被分配给 location=4 ...但没有任何反应,其他四个属性除了那个之外适当地变化。在底部,我添加了一个测试以在遇到值“1”时生成特定颜色(我知道它存在于缓冲区中,因为我之前查询过缓冲区)。属性 4 停留在其数组的第一个值处并且永远不会移动。

我是否缺少设置? (可能要启用某些东西?)还是 openGL 只改变了少数属性而没有其他改变?

#version 330 //for openGL 3.3

//uniform variables stay constant for the whole glDraw call
uniform mat4  ProjViewModelMatrix;
uniform vec4  DefaultColor;  //x=-1 signifies no default color

//non-uniform variables get fed per vertex from the buffers
layout (location=0) in vec3 coords;       //feeding from attribute=0 of the main code
layout (location=1) in vec4 color;        //per vertex color, feeding from attribute=1 of the main code
layout (location=2) in vec3 normals;      //per vertex normals
layout (location=3) in vec2 UVcoord;      //texture coordinates
layout (location=4) in int  vertexTexUnit;//per vertex texture unit index

//Output
out vec4 thisColor;
out vec2 vertexUVcoord;
flat out int  TexUnitIdx;

void main ()
{
    vertexUVcoord = UVcoord;
    TexUnitIdx=vertexTexUnit;

    if (DefaultColor.x==-1) {thisColor = color;} //If no default color is set, use per vertex colors
    else {thisColor = DefaultColor;}

    gl_Position = ProjViewModelMatrix * vec4(coords,1.0); //This outputs the position to the graphics card.

    //TESTING
    if (vertexTexUnit==1) thisColor=vec4(1,1,0,1); //Never receives value of 1, but the buffer does contain such values
}

因为vertexTexUnit属性是一个整数,所以必须使用glVertexAttribIPointer()而不是glVertexAttribPointer()

您可以随心所欲地使用顶点属性。 OpenGL 不知道也不关心你用它们做什么。