Advertisement Jump to content
Sign in to follow this  
Servant of the Lord

OpenGL Using glTexImage3D() for Texture Arrays

This topic is 477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
    glBindTexture(GL_TEXTURE_2D_ARRAY, textureID);

    //Configure the details of this texture object.
    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);



Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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)



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!