-1

I write glsl wrapper for education purposes, but I stopped because I have some misunderstanding. When I want insert variable to specific location, I have mismatch warning. Because location is GLint, but glVertexAttrib location must be GLuint.

Here's my code sample

bool Material::AddAttrib(GLchar *variable, std::vector<GLdouble> values) {
GLint location = glGetAttribLocation(program,variable);
GLenum error = glGetError();
bool isNor = PrintError(error);
if(!isNor) return isNor;
switch (values.size()) {
    case 1:
        glVertexAttrib1d(location, values.at(0));
        break;
    case 2:
        glVertexAttrib2d(location, values.at(0), values.at(1));
        break;
    case 3:
        glVertexAttrib3d(location, values.at(0), values.at(1), values.at(2));
        break;
    case 4:
        glVertexAttrib4d(location, values.at(0), values.at(1), values.at(2), values.at(3));
        break;
    default:
        PrintErrorSize();
        return false;
}
error = glGetError();
isNor = PrintError(error);
return isNor;
}
Airat
  • 80
  • 1
  • 8

1 Answers1

1

glGetAttribLocation() may return negative indices in case of an error. Of course, a negative index is not valid if used for glVertexAttrib...(). That's why there is a type mismatch. You can resolve this with a simple cast:

GLint retrievedLocation = glGetAttribLocation(program,variable);
if(retrievedLocation < 0)
    return ...; //there is no variable with this name
GLuint location = (GLuint) retrievedLocation;
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70