Makogan
Makogan

Reputation: 9540

How to create a cube map array texture from individual cube map textures in OpenGL 4.5?

Say I have a number of cube map textures and I wish to pass all of them to the GPU as a cube map array texture.

First I would need to create the array texture, which should look something like:

glTextureStorage3D(textureId, 0, internalFormat, width, height, howManyCubeMaps);

Assuming there is only one mipmap level.

How can I then attach each indidivual texture to this texture array?

Say if each cube map id is in an array, I wonder if you can do somehting like this:

for(uint level=0; level<num_levels; level++)
    glAttach(textureID, cubeID[level], level);

And then I am not sure how I should receive the data on the shader side and the OpenGL wiki has no explicit docuemtnation on it

https://www.khronos.org/opengl/wiki/Cubemap_Texture#Cubemap_array_textures

Upvotes: 1

Views: 612

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473174

How can I then attach each indidivual texture to this texture array?

That's not how array textures work in OpenGL. That's not even how arrays work in C++. Think about it: if you have 5 int variables, there's no way to "attach" those int variables to an int array[5] array. The only solution is to copy the value of those variables into the appropriate locations in the array. After this process, you still have 5 int variables, with no connection between them and the array.

So too with OpenGL: you can only copy the data within those cube map textures into the appropriate location in the cube map array texture. glCopyImageSubData is your best bet for this process.

Upvotes: 3

Related Questions