glTexImage2D returns GL_INVALID_VALUE for some computers. I am not sure what is the problem.
The parameters I am sending is
GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, data_fmt, GL_UNSIGNED_BYTE, surf->pixels
data_fmt is GL_RGBA
width and height is 872 639
Here are the reasons that it can be invalid value.
GL_INVALID_VALUE is generated if width is less than 0 or greater than GL_MAX_TEXTURE_SIZE.
GL_INVALID_VALUE is generated if target is not GL_TEXTURE_1D_ARRAY or GL_PROXY_TEXTURE_1D_ARRAY and height is less than 0 or greater than GL_MAX_TEXTURE_SIZE.
GL_INVALID_VALUE is generated if target is GL_TEXTURE_1D_ARRAY or GL_PROXY_TEXTURE_1D_ARRAY and height is less than 0 or greater than GL_MAX_ARRAY_TEXTURE_LAYERS.
GL_INVALID_VALUE is generated if level is less than 0.
GL_INVALID_VALUE may be generated if level is greater than log2(max), where max is the returned value of GL_MAX_TEXTURE_SIZE.
GL_INVALID_VALUE is generated if internalFormat is not one of the accepted resolution and format symbolic constants.
GL_INVALID_VALUE is generated if width or height is less than 0 or greater than GL_MAX_TEXTURE_SIZE.
GL_INVALID_VALUE is generated if border is not 0.
GL_INVALID_VALUE is generated if target is GL_TEXTURE_RECTANGLE or GL_PROXY_TEXTURE_RECTANGLE and level is not 0.
It is not a big texture so size should be under GL_MAX_TEXTURE_SIZE? I don’t know the value of it though. Red one is also a possibility but I doubt that RGBA is not supported.
Any idea? Or help me to further debug?
Here is the full code
out << "loading " << fileName << "
";
dimensions.setZero();
name = fileName;
this->repeat = repeat;
SDL_Surface* surf = IMG_Load(fileName.c_str());
if (surf == NULL)
{
out << "surface_error: " << fileName << " " << SDL_GetError() << "
";
hasError = true;
return;
}
GLenum data_fmt;
if (surf->format->BytesPerPixel == 4)
{
data_fmt = GL_RGBA;
}
else if (surf->format->BytesPerPixel == 3)
{
data_fmt = GL_RGB;
}
else if (surf->format->BytesPerPixel == 1)
{
data_fmt = GL_RED;
}
else
{
assert(false);
}
GL_CALL(glGenTextures(1, &gTexture));
GL_CALL(glBindTexture(GL_TEXTURE_2D, gTexture));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, data_fmt, GL_UNSIGNED_BYTE, surf->pixels));
if (hadGLError)
{
out << data_fmt << " " << surf->w << " " << surf->h << "
";
}
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
dimensions = IntVec2(surf->w, surf->h);
glGenerateMipmap(GL_TEXTURE_2D);
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
SDL_FreeSurface(surf);
glGetError is set to 0x501 after glTexImage2D and it crashes on glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S
It gives me
gl error glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, data_fmt, GL_UNSIGNED_BYTE, surf->pixels) (source\cTexture.cpp:49) 0x501
and after that it prints
6408 872 639 (which is GL_RGBA and width/height of the textures)
surf->format->BytesPerPixel is 4 so it picks rgba
I cant really debug things further because this is a crash report