Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


DX11 creating a texture with mips


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 14 April 2014 - 03:16 PM

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?



Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2864

Like
0Likes
Like

Posted 14 April 2014 - 03:57 PM

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

 

Cheers!


Edited by kauna, 14 April 2014 - 03:57 PM.


#3 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 14 April 2014 - 04:40 PM

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......



#4 SeanMiddleditch   Members   -  Reputation: 7269

Like
0Likes
Like

Posted 14 April 2014 - 07:40 PM

You need to call ID3D11Context::GenerateMips.

Edited by SeanMiddleditch, 14 April 2014 - 07:41 PM.


#5 kauna   Crossbones+   -  Reputation: 2864

Like
0Likes
Like

Posted 14 April 2014 - 09:45 PM


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!



#6 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 15 April 2014 - 09:35 AM

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



#7 ekba89   Members   -  Reputation: 480

Like
0Likes
Like

Posted 15 April 2014 - 02:58 PM

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]



#8 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 15 April 2014 - 03:18 PM

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



#9 ekba89   Members   -  Reputation: 480

Like
0Likes
Like

Posted 15 April 2014 - 03:33 PM

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


Edited by ekba89, 15 April 2014 - 03:34 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS