Create and fill texture array

Started by
1 comment, last by Adaline 11 years, 1 month ago

Hello

I'm trying to load several textures into a texture array :


		D3D10_TEXTURE2D_DESC desc;
		ZeroMemory(&desc,sizeof(desc));
		desc.Width=width;
		desc.Height=height;
		desc.ArraySize=nbFrames;
		desc.MipLevels=1;
		desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
		desc.SampleDesc.Count=1;
		desc.Usage=D3D10_USAGE_DYNAMIC;
		desc.BindFlags=D3D10_BIND_SHADER_RESOURCE;
		desc.CPUAccessFlags=D3D10_CPU_ACCESS_WRITE;

		if FAILED(device->CreateTexture2D(&desc,NULL,&texture)) return false;

But I get an exception : ID3D10Device::CreateTexture2D: A D3D10_USAGE_DYNAMIC Resource must have ArraySize equal to 1.

How can I create a texture array with a CPU-write access (as a shader resource and with dynamic usage) please ? Or equivalent ?

Thanks

Nico

Advertisement

You only want to use DYNAMIC usage if the resource will actually be dynamic. In other words, that usage is designed for cases where the CPU will need to update the contents of the resource many times during the lifetime of that resource. If you just want a static read-only texture, then you should use IMMUTABLE usage and initialize the contents of the texture using the pInitialData parameter. For the case of a texture array, you'll want to pass a pointer to an array of N D3D10_SUBRESOURCE_DATA, where N is the number of array slices in your texture. Then for each D3D10_SUBRESOURCE_DATA, you need to set pSysMem to a pointer to the texture data for a single array slice.

Thank you MJP smile.png, it solved my problem

This topic is closed to new replies.

Advertisement