1

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

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • "*the OpenGL wiki has no explicit docuemtnation on it*" It has explicit documentation. It tells you what the sampler type is. It tells you how cube map arrays change the texture accessing functions' interfaces. What it doesn't have is copy-and-pasteable code. Cubemap arrays work just like 2D and 1D array textures: their texture coordinates take an additional component, which is the array layer. If you have a specific question about how to use a cubemap array, you can ask that. – Nicol Bolas Feb 19 '18 at 01:16

1 Answers1

3

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Arrays in C++ can definetely work like that if you use pointers. Instead of having to copy the data you simply know where in RAM the data is stored. This is less efficient in terms of lookup since now you are jumping around in memory, but it's still faster than copying the data. – Makogan Feb 19 '18 at 09:16
  • @Makogan: An array of *pointers to* integers is not the same thing as an array of integers. I knew you'd say something like that, which is why I posted [this OpenGL question](https://stackoverflow.com/q/48858768/734069) immediately after writing this answer. – Nicol Bolas Feb 19 '18 at 14:41
  • I know they are different, but the point was not wether they are the same or not. The point is that they can be used for the same purposes, one being less efficient for lookup but more efficient for data copying than the other. And for me coppying a pointer in an array of pointers can be seen as "attaching" the associated memory section to the array. However that is not important. I do want to comment that I appreciate all of your answers and help btw, just putting it out there because I think I ahve sounded like an ass in some of my replies. – Makogan Feb 19 '18 at 20:21