Advertisement

Using glTexImage3D() for Texture Arrays

Started by September 28, 2017 05:33 AM
2 comments, last by Servant of the Lord 7 years, 4 months ago

When I create a Texture Array using glTexImage3D() (instead of glTexStorage3D()), am I supposed to call it for every texture in the array, or call it just once?


    glGenTextures(1, textureID);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D_ARRAY, textureID);

    //Configure the details of this texture object.
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, (mipmapLevels - 1));

    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, /* blah */);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, /* blah */);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, /* blah */);

    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, /* blah */);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, /* blah */);

    //Allocate every texture in the array.
    for(GLint arrayIndex = 0; arrayIndex < this->details.textureLayers; ++arrayIndex)
    {
            //Allocate the texture on the GPU, with uninitialized data.
            glTexImage3D(GL_TEXTURE_2D_ARRAY, 0 /* mipmapLevel */, format,
                         width, height, arrayIndex,
                         0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

    }

 

Just once. You're (optionally) uploading 3D image data to be used as an array of 2D textures (same difference, really). Depth should match the array size.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Advertisement

Ah, that makes sense. I wasn't thinking of it as a 3D image, but that function has it's interface designed for 3D images.

 

But when I'm generating mipmap levels for 2D textures that aren't arrays, I do need to call glTexImage2D() once per mipmap level, right?And so when generating mipmap levels for "3D textures" / 2D texture arrays, I need to call glTexImage3D() once per mipmap level?

 

(I was mistakenly thinking that since I have to call glTexImage2D() once per mipmap, I needed to call glTexImage3D() once per array layer and per mipmap)

 

 

This topic is closed to new replies.

Advertisement