Question

Assume I have GL_TEXTURE_2D_ARRAY including 6 textures I'm loading it with:

  vector<string>::iterator vsit;
  for(vsit=filenameTable.begin();vsit!=filenameTable.end();++vsit)
  {
    string filename = *vsit;
    BMPData* bmpData = LoadTextureBMPData_custom(filename);
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY,0,0,0,i++,bmpData->width,bmpData->height,1,GL_BGR,GL_UNSIGNED_BYTE,(GLvoid*)&(bmpData->data[0]));
  }

Before this code I have to allocate storage for every texture, if I have good understand I can do this with glTexImage3D() or glTexStorage3D(), for example:

glTexImage3D(GL_TEXTURE_2D_ARRAY,0,GL_RGB,1024,1024,filenameTable.size(),0,GL_BGR,GL_UNSIGNED_BYTE,NULL);

or

glTexStorage3D(GL_TEXTURE_2D_ARRAY,0,GL_RGB,1024,1024,filenameTable.size());

================================================================================ But when I allocate size for every texture in table I have only one pair of parameters for [width,height] of texture. What if I want every texture image to have another dimmensions? Is there any solution for this problem without scaling every texture to one size in graphic editor?

Another problem is fact that glTexStorage3D() I'm presenting on third code snipper causing crash of my program. Information about glTexStorage3D() I found there:
http://www.opengl.org/wiki/Array_Texture

Was it helpful?

Solution 2

Well, if you do not care about wasting memory, you can use the biggest image (separate for each dimesnion) to define the size of the TA. You can load each image separately into a layer using glTexSubImage3D. You will have to modify the texcoords when accesin the textures, though, so your shader needs to know the size of each image in the array it needs to access. You should also be aware that the builtin wrap functionality cannot be used and has to be emulated in the shader (if needed).

OTHER TIPS

All images in an array texture have the same size. Just like if you make a C array of some struct, each struct must be of the same type (and therefore the same size).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top