GlGenerateMipmap does not work with 3D textures in OpenGL

I have several 3D textures and I would like to automatically generate a mip map for each one. The textures are all 64x64x64 and I want the mipmap to be generated only up to 16x16x16.

After that, I want to use textureLOD to do interpolation between different mip levels.

This is what I tried:

I do this for every main 3d texture

        glGenTextures(1, &volumeTexture[i]);
        glBindTexture(GL_TEXTURE_3D, volumeTexture[i]);
        glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, volumeDimensions, volumeDimensions, volumeDimensions, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
        glGenerateMipmap(GL_TEXTURE_3D);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
        glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_LOD_BIAS, 0.f);

        glBindTexture(GL_TEXTURE_3D, 0);
        glGenFramebuffers(1, &volumeFbo[i]);
        glBindFramebuffer(GL_FRAMEBUFFER, volumeFbo[i]);
        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, volumeTexture[i], 0);
        glBindFramebuffer(GL_FRAMEBUFFER, 0);

      

Then, for each frame, I call glClear to remove them, and then I call the shader that fills the 3D texture (it only fills the highest level at 64 ^ 3).

 layout (binding = 0, rgba8) coherent uniform image3D volumeTexture[N];
 ...
 imageStore(volumeTexture[n_tex], ivec3(coords1), vec4(fragmentColor.xyz, 1.0));

      

After that, before using textures, I call:

for (int i = 0; i < N; ++i){
    glActiveTexture(GL_TEXTURE0 + i);
    glBindTexture(GL_TEXTURE_3D, volumeTexture[i]);
    glGenerateMipmap(GL_TEXTURE_3D);
}

      

And finally, inside my shader I have

layout (binding = 0) uniform sampler3D VolumeTexture[N];
...
vec4 color = textureLod(VolumeTexture[current_tex], texCoords, 1+distance/10);

      

since it didn't seem like a sample from any lower level, instead of 1 + distance / 10 I entered a manual number, but I get the same results that I get when reading from the main texture. I put a lod of 100, which I only expected to see, but the result did not change

+3


source to share





All Articles