PDA

View Full Version : Mipmaps for GL_TEXTURE_2D_ARRAY do not generate



Vorril
09-01-2015, 02:53 AM
I have a 2D texture array holding a few textures, I have been able to successfully generate this array and it does render however glGenerateMipmap(GL_TEXTURE_2D_ARRAY) isn't behaving like I expect it to. Manual upload of mipmaps I made does work but I really dislike going to that trouble.

What I've been doing:
I allocate with glTexStorage3D and upload level 0 with glTexSubImage3D. Using glTexImage3D with a nullptr instead of glTexStorage3D yields the same result. I debug with CodeXL and at this point everything is OK, I have my texture base perfectly stored and the same number of mipmaps I requested storage for and they're just empty. After calling glGenerateMipmap though it gets weird: I seem to only have the base plus mipmap level 1. The texture has become only become 2 leveled, vs the previous 9 or 10. Here's the relevant code, I use three 512x512 textures to test:




glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevel, GL_RGBA8, wid, hi, files.size());

for (int i = 0; i < files.size(); i++){
unsigned char* buffer;

int w, h, c;

string fileLoc = files[i];

buffer = (SOIL_load_image(fileLoc.c_str(), &w, &h, &c, SOIL_LOAD_RGBA));
if (buffer == nullptr){// || wid != w || hi != h
cout << "MISSING TEXTURE: " << fileLoc << endl;//TEMP
return;
}

glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, wid, hi, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer);


free(buffer);
}
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);

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);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);



My context is 4.5, my card is an AMD 7850, my shaders are running #330.

I have also tried using exactly analogous code for a simple GL_TEXTURE_2D with glTexStorage2D and it worked fine, all mipmaps generated. So if anyone has any advice or insight thanks for taking a look and I'd be happy to hear it.