Sign in to follow this  
Followers 0
NiteLordz

DX11
Mipmaps without D3DX11FilterTexture

4 posts in this topic

I am using DX10/11 and i am trying to create mipmaps, without using d3dx as i am cross platform and would like to keep it clean of the D3DX library.

 

As a test, i used D3DX11FilterTexture to create the mipmaps, and verify everything works as expected.  And it does.  Now i want to replace this method with, what suggestions or alternatives are there.

 

Currently i load in my textures into an image file, so i have the raw image data. 

 

Thanks much

0

Share this post


Link to post
Share on other sites

Note that with GenerateMips:

 

If the base resource was not created with D3D11_BIND_RENDER_TARGET and D3D11_RESOURCE_MISC_GENERATE_MIPS, the call to GenerateMips has no effect.

 

(From the MSDN doc link).

 

If you want to create mipmaps without FilterTexture, you should create an array of D3D11_SUBRESOURCE_DATA, one array element for each miplevel, set pSysMem to the data for each miplevel, set SysMemPitch to the pitch for each miplevel, and (assuming Texture2D) SysMemSlicePitch to 0.  Then pass that array as the second param to your CreateTexture2D call.  There's nothing special you need to do to indicate the end of the array; CreateTexture2D is clever enough to realize when it hits the 1x1 sized level (or the MipLevels member of your D3D11_TEXTURE2D_DESC) that there are no more.

 

Since you have the raw image data, that becomes the pSysMem for your miplevel 0.  For other miplevels you filter it down to the correct size for the level, then use the filtered down data as the pSysMem for those levels.

 

That means having to allocate and subsequently free a chunk of data for each level, so having a memory manager that lets you release it all in one fell swoop is a useful, but by no means essential, thing to have.

 

This method has the bonus that it will work just fine even with immutable textures (it is in fact the only method that will work with immutable textures).

0

Share this post


Link to post
Share on other sites

Oh man, that's embarrassing, I'm sorry about that. I just remembered a function that did that, and didn't bother to read it. Sorry again.

0

Share this post


Link to post
Share on other sites

My recommendation would be to work with DDS files. The file format is documented so it's not limited to one platform, and it lets you store all the mip maps in the file. Loading them is almost certainly quicker than creating them at runtime, especially if you use a decent quality filter to generate them. It will also handle formats like DXT1 that can cut down video memory usage by a factor of 8.

 

NVidia have a free plugin for Photoshop and some other tools which handle dds files.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0