0

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?

Benoît Dubreuil
  • 650
  • 1
  • 11
  • 27

1 Answers1

1

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.

Community
  • 1
  • 1
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Hmmm okay but it doesn't get rid of the drmemory's warning. I didn't try to replace the function declaration because it's kinda too complicated for me... (messing with OpenGL and GLEW's functions). I just want a cast that doesn't throw warning or another OpenGL function: you said there were gl...Offset functions. What are they? – Benoît Dubreuil Mar 22 '15 at 15:17
  • @user2924010: gl…Offset are not officially specified. Essentially they're just function pointers with a slightly different signature (taking a `uintptr_t` instead of a `void*`) and assigning the gl…Pointer function addresses to these …Offset pointers. See the very last 3 paragraphs in my other answer to see how it's done. Of course if you want to limit yourself to OpenGL-4 you can use the glVertexAttribFormat family of functions. – datenwolf Mar 22 '15 at 18:07
  • typedef void (*TFPTR_VertexOffset)(GLuint, GLint, GLenum, GLboolean, GLsizei, uintptr_t); TFPTR_VertexOffset myglVertexAttribOffset = (TFPTR_VertexOffset)glVertexAttribPointer; This gives an error. It doesn't any information even in debug. – Benoît Dubreuil Mar 22 '15 at 19:57
  • @user2924010: Which error does it give you exactly? – datenwolf Mar 22 '15 at 20:42