What is the purpose of glVertexAttribLPointer?

Hi dear all,
I found both glVertexAttribPointer and glVertexAttribLPointer all accept GL_DOUBLE , why bother to use glVertexAttribLPointer ? many thanks!

The choice of function depends upon the type of the attribute within the shader. You need to use glVertexAttribPointer for float, vec2, vec3, vec4, glVertexAttribIPointer for int, ivec2, ivec3, ivec4, uint, uvec2, uvec3, uvec4, and glVertexAttribLPointer for double, dvec2, dvec3, dvec4. If you use the wrong function you’ll get garbage, as the data won’t be converted to the format the shader program is expecting.

It would have been cleaner to have one function with another parameter for the internal type, but the first generation of programmable GPUs only supported floating-point attributes; integer attributes were added in OpenGL 3.0 and double-precision attributes in 4.1.

1 Like

thanks! I finally know that GL_DOUBLE is the type of the input type , for glVertexAttribPointer the input data will be converted to float , for glVertexAttribLPointer the original precision will keep (no conversion performed) , sounds reasonable .

But then you wouldn’t be able to distinguish between passing an integer to an integer attribute and passing an integer to a float attribute via casting. This allows you to keep using float attributes for a shader even if sometimes, that data are just integer bytes/shorts.

Of course, frequent changes of vertex formats on modern hardware isn’t a good idea from a performance perspective.

How so? Consider:

glVertexAttribXPointer(GLuint index, GLenum internalType, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void * pointer)
{
    switch (internalType) {
    case GL_FLOAT:
        glVertexAttribPointer(index, size, type, normalized, stride, pointer);
        break;
    case GL_INTEGER:
        glVertexAttribIPointer(index, size, type, stride, pointer);
        break;
    case GL_DOUBLE:
        glVertexAttribLPointer(index, size, type, stride, pointer);
        break;
    }
}