Warning for glVertexAttribPointer

Started by
4 comments, last by BitMaster 8 years, 7 months ago
I'm reworking the rendering part of my game engine and I have run into a warning that I'm not too sure about. This warning is coming out of my call to glVertexAttribPointer and the last param (the const GLvoid* pointer one).

The warning is: cast to pointer from integer of different size. This happens when I compile for x86_64, arm64-v8a, and mips64 device types

In short I have a class called DefaultShaderProgram that has a method that looks like this:
void DefaultShaderProgram::EnableAttributes()
{
	attributes["vertexPosition"].Enable(TOTAL_ATTRIBUTES_BYTE_SIZE, 0);

        //Compiler says byteSize is where the warning is coming from: cast to pointer from integer of different size
	attributes["color"].Enable(TOTAL_ATTRIBUTES_BYTE_SIZE, (const GLvoid*)attributes["vertexPosition"].byteSize);
}
This call (the Enable method) is just a wrapper for glVertexAttribPointer. Where the Enable function is apart of the base class ShaderProgram and looks like:
void ShaderProgram::ShaderAttribute::Enable(const GLsizei byteStride, const GLvoid *byteOffset)
{
	glEnableVertexAttribArray(location);
	glVertexAttribPointer(location, typeSize, baseType, normalized, byteStride, byteOffset);
}

Whats the proper way to fix this? I don't think its one of those warnings that I can ignore
Advertisement

I do something like:

(const GLvoid*)(uintptr_t)attributes["vertexPosition"].byteSize

So I'm casting to a uint with a size that matches a pointer before casting to a pointer.

Someone who doesn't like c style casts will probably chime in and tell us that code is horrible (they may well have a point) :)

First things first. Since you are using C++, why are you using horrible C casts? There is static_cast and reinterpret_cast. They show intent much clearer, are easier to locate when searching a document and actually avoid some of the potential pitfalls of C casts.

Then, a way to solve the warning is to use
static_cast<const char*>(0) + size
Or, if the editor decides to mangle my template again turn a null pointer into a const char* pointer and add your offset. Good old pointer arithmetic will then deal with the rest.

Someone who doesn't like c style casts will probably chime in and tell us that code is horrible (they may well have a point)


First things first. Since you are using C++, why are you using horrible C casts? There is static_cast and reinterpret_cast.


C0lumbo can see the future. tongue.png

Sean Middleditch – Game Systems Engineer – Join my team!

First things first. Since you are using C++, why are you using horrible C casts? There is static_cast and reinterpret_cast. They show intent much clearer, are easier to locate when searching a document and actually avoid some of the potential pitfalls of C casts.

Then, a way to solve the warning is to use


static_cast<const char*>(0) + size
Or, if the editor decides to mangle my template again turn a null pointer into a const char* pointer and add your offset. Good old pointer arithmetic will then deal with the rest.

In this particular case, I don't see the point of making a stink about it. OpenGL's the one doing an abusive integer-pointer cast and there's no particular ambiguity about what's happening, or particular potential for unexpected behavior. So C or C++ style cast, do whatever. Hilariously enough, your idea of adding to a zero pointer? Undefined behavior. Whoops. It's just a messy thing to do in the first place.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
In my defense, that idea hasn't grown on my compost. And while I did get my doubts about it when reflecting on it later that evening the forum has been responding so sluggishly and badly on the browsers I have at home I decided against making an attempt at an edit.

This topic is closed to new replies.

Advertisement