Hey all,
I've been trying to implement mipmapping with the images in my texture array, but I think I may be going about this wrong and I'm having difficulty tracking down an answer. I'm not receiving an error, but everything in game still looks very pixelated and jagged in the distance.
my image loading looks thusly:
void LoadAssets()
{
//create texture array////
glGenTextures(1, &TextureArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureArray);
glTexStorage3D(GL_TEXTURE_2D_ARRAY,1, GL_RGBA8, 1024, 1024, 9);
//bind vertex array. Once.////
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
//load images////
//don't change the number on the end, used for texture array placement. don't rearrange. add to end of list.
//stone image////
LoadImage("GAMEASSETS/StoneDiffuse.png", 0);
LoadImage("GAMEASSETS/StoneNormal.png", 1);
LoadImage("GAMEASSETS/StoneSpecular.png", 2);
imageIndices.emplace_back(glm::vec3(0,1,2));
//mountain image////
LoadImage("GAMEASSETS/mountainDiffuse.png", 3);
LoadImage("GAMEASSETS/mountainNormal.png", 4);
LoadImage("GAMEASSETS/mountainSpecular.png", 5);
imageIndices.emplace_back(glm::vec3(3,4,5));
//tree image////
LoadImage("GAMEASSETS/TreeDiffuse.png", 6);
LoadImage("GAMEASSETS/TreeNormal.png", 7);
LoadImage("GAMEASSETS/TreeSpecular.png", 8);
imageIndices.emplace_back(glm::vec3(6,7,8));
//set texture parameters////
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}
void LoadImage(const char* imageName, int layerNumber)
{
if(!image.loadFromFile(imageName))
{
std::cout<<imageName<<" failed to load..."<<std::endl;
}
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerNumber, image.getSize().x, image.getSize().y,1, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
}
So, if I'm doing things incorrectly, what is the proper way in OpenGL 3.3+ to mipmap the images in a texture array? Should I be setting the glTexParameters for every image rather than once at the end? Do I need to be changing the second parameter of glTexSubImage3D? Is the jaggedness in the textures at a distance not a mipmap problem? I do find cranking up the antialiasing helps, but it's not really feasible to keep that at 32 samples :P
To clarify though, I'm not receiving any error, but the images definitely don't look mipmapped, and become pixelated in the distance. Hopefully I'm just doing something silly here.
Anyhow, I appreciate any input, and cheers!