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

OpenGL Using glTexImage3D() for Texture Arrays

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);
    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);

    }

 

Share this post


Link to post
Share on other sites
Advertisement

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!