Benoît Dubreuil
Benoît Dubreuil

Reputation: 680

glVertexAttribPointer last attribute value or pointer

The last attribute of glVertexAttribPointer is of type const GLvoid*. But is it really a pointer? It is actually an offset. If I put 0, it means an offset of 0 and not a null pointer to an offset. In my engine, I use this function:

void AbstractVertexData::vertexAttribPtr(int layout) const
{
    glVertexAttribPointer(layout,
                          getShaderAttribs()[layout]->nbComponents,
                          static_cast<GLenum>(getShaderAttribs()[layout]->attribDataType),
                          getShaderAttribs()[layout]->shouldNormalize,
                          getVertexStride(layout),
                          reinterpret_cast<const void*>(getVertexAttribStart(layout)));
}

getVertexAttribStart returns an intptr_t. When I run drmemory, it says "uninitialized read" and I want to remove that warning. This warning comes from the reinterpret_cast. I can't static_cast to a const void* since my value isn't a pointer. What should I do to fix this warning?

Upvotes: 0

Views: 1142

Answers (1)

datenwolf
datenwolf

Reputation: 162164

Originally, back in OpenGL-1.1 when vertex arrays got introduces, functions like glVertexPointer, glTexCoordPointer and so on were accepting pointers into client address space. When shaders got introduced they came with arbitrary vertex attributes and the function glVertexAttribPointer follows the same semantics (this was in OpenGL-2.1).

The buffer objects API was then reusing existing functions, where you'd pass an integer for a pointer parameter.

OpenGL-3.3 core eventually made the use of buffer objects mandatory and ever since the glVertexAttribPointer functions being defines with a void* in their function signature are a sore spot; I've written in extent about it in https://stackoverflow.com/a/8284829/524368 (but make sure to read the rest of the answers as well).

Eventually new functions got introduced that allow for a more fine grained control over how vertex attributes are accessed, replacing glVertexAttribPointer, and those operate purely on offsets.

Upvotes: 1

Related Questions