DX11 creating a texture with mips

Started by
7 comments, last by ekba89 10 years ago

I'm trying to create a texture with mips, but it keeps failing. I've been searching the internet for an answer, but I'm not having any luck. Here is what I have:


	D3D11_TEXTURE2D_DESC desc;
	ZeroMemory(&desc,sizeof(desc));
	desc.Width = sx;
	desc.Height = sy;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	desc.SampleDesc.Count = 1;
	desc.Usage = D3D11_USAGE_DYNAMIC;
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	desc.MiscFlags = 0;

	ID3D11Texture2D *pTexture = NULL;
	HRESULT result=GE->dev->CreateTexture2D( &desc, NULL, &pTexture );//this works. doesn't fail
	if(FAILED(result)) tp1=12345;
	result=GE->dev->CreateShaderResourceView(pTexture,NULL,&m_texture);
	if(FAILED(result)) tp1=2;

sx and sy are defined already as 256. This works fine as long as I don't try to change the "desc.MipLevels" to anything but 1. I can't find an example of creating the texture with anything but 1 mip level......

Does anyone know how to do it?

Advertisement

Have you enabled to D3D debug output? It might give you more detail on the problem.

Cheers!

I don't have Win8. MSDN says I need to have D3D11_1SDKLayers.dll which is in the Win8 SDK.

Surely someone has actually done this......

You need to call ID3D11Context::GenerateMips.

Sean Middleditch – Game Systems Engineer – Join my team!


I don't have Win8. MSDN says I need to have D3D11_1SDKLayers.dll which is in the Win8 SDK.

Surely someone has actually done this......

Humm? I'm able to enable to the debug libraries through direct3d control panel under Win7. Also, creating the device with the debug flags will give you already pretty good knowledge of what's the problem.

Cheers!

GenerateMips only fills in the mips already present with the highest detailed level's info.....

For the dynamic textures you can't do more than 1 mip levels. If you enable the debug mode it says this.

D3D11 ERROR: ID3D11Device::CreateTexture2D: A D3D11_USAGE_DYNAMIC Resource must have MipLevels equal to 1. [ STATE_CREATION ERROR #102: CREATETEXTURE2D_INVALIDMIPLEVELS]

Thanks for checking that for me. I can't seem to get the debugger to work right-- I must have a wrong setting somewhere.....

Why are dynamic textures unable to have more than 1 mip? DX9 was flexible enough to have that option. It seems the only types have to be render targets.....

What I wanted to do is create some textures with patterns or noise and generate the mips. And there was one in particular that I wanted to have the higher mip levels "fade" to completely transparent. I can do this with a shader, but I already knew how to get the "fade" with mips..... sad.png

I think you can do it using USAGE_DEFAULT and using UpdateSubresource function and you should remove CPU_ACCESS_WRITE to use USAGE_DEFAULT.

This topic is closed to new replies.

Advertisement