I agree that exposing some of the params for CreateTexture2D would be nice. As it stands now, I used the library for loading the images, but am creating the DX Texture resources in my own code due to these not being exposed. Not that is is terribly
difficult to create them, but if the goal is provide a general purpose library for creating DX Textures then it isn't quite meeting it in this area.
I do like the library much better than D3DX though. The intermediate step with ScratchImage is great.
For loading an array you can avoid using an UpdateSubresource if you want. I did something similar to what CreateTexture is doing to create my texture array. I used what they did as an example but based it off an array of ScratchImages.
1) Allocate an array of ScratchImage for however many images you want in the texture array.
2) Use LoadFromDDSFile/LoadFromWICFile to load all the images.
3) Do whatever validation you need on your images since they have to all be the same for the array.
4) Now you can allocate an array of D3D11_SUBRESOURCE_DATA for all the images * mips (just like CreateTexture does) and iterate through them all to fill in the structures.
unique_ptr<D3D11_SUBRESOURCE_DATA> initData(new D3D11_SUBRESOURCE_DATA[imageCount * firstMeta.mipLevels]);
const Image* mips;
int index = 0;
for (int i=0;i<imageCount;++i)
mipCount = imageList[i].GetImageCount();
mips = imageList[i].GetImages();
for (size_t mipIndex=0;mipIndex<mipCount;++mipIndex)
initData[index].pSysMem = mips[mipIndex].pixels;
initData[index].SysMemPitch = static_cast<DWORD>(mips[mipIndex].rowPitch);
initData[index].SysMemSlicePitch = static_cast<DWORD>(mips[mipIndex].slicePitch);
5) Now you can call CreateTexture2D just like the library does without having to use UpdateSubresource.
Whether this is actually a better way (your original question) I dunno. Less API calls, but I suppose if you have a lot of large images this might not be the best approach due to having to load them all at the same time. In that case your UpdateSubresource
is probably better since you can do it in smaller chunks. For my case, I have a lot of small images and loading them all up at once before creating the array is not a big deal.
I agree it would be nice to see a way to create a texture arrays directly in the library. To make use of that though, I would need the D3D11_TEXTURE2D_DESC data accessible in some fashion.