Jump to content
  • Advertisement
Sign in to follow this  

How can I load a single mip level from dds?

This topic is 3974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello guys, I`m working on my texture management, but I can`t figure out how can I get for example only 5th mip level from a texture. loading function in directX has parameter how many mip levels I want to load, but if I put there for example 1, it loads the highest mip level. it would be fine if it loaded the lowest one, but unfortunately it doesn`t. how can I do it? or do I have to load whole texture and then use tex2Dlod? not exactly the fastest way, especially when I plan to load textures dynamicaly.

Share this post

Link to post
Share on other sites
Admittedly I've not tried it, but there is the lesser known D3DX_SKIP_DDS_MIP_LEVELS(levels,filter) macro (at the very bottom of the remarks in the docs).

From what I gather, pass in the number of levels you want (e.g. 1) as usual, then use the aforementioned macro for the MipFilter parameter - the second argument of the macro handles your normal usage, but the first encodes the number of levels to skip. Presumably using 1 level and skip 4 will only load the 5th for you.

However, I have no idea how smart the implementation is - whether it actually reduces the I/O usage or whether it just loads everything and returns an IDirect3DTexture9 with everything else discarded...


Share this post

Link to post
Share on other sites
yep, thanx, its working. I`ve tried adding it to my texture browser, but I have no idea either how smart the implementation is. I have there some mysterious bug so when I load 2 megs of textures it takes 50mbs in memory. weird, huh? but nvm, i`m going to profile it.

for all fellow MDX programmmer: we don`t have this macro, or at least I haven`t found it, so we have to make it. here is my version:

int mipsInFile = TextureLoader.ImageInformationFromFile(path).MipLevels;
int mipsNeeded = 7;

int mipMask = 0x1F;
int shift = 26;
int filter = (int)Filter.Linear;
int mipsToThrowAway = mipsInFile - mipsNeeded;
int f = ((mipsToThrowAway & mipMask) << shift) | filter;

Texture t = TextureLoader.FromFile(device, path, 0, 0, 1, Usage.None, Format.Unknown, Pool.Managed, Filter.None, (Filter)f, 0);

this is from SDK:
use bits 27-31 to specify the number of mip levels to be skipped (from the top of the mipmap chain) when a .dds texture is loaded into memory; this allows you to skip up to 32 levels.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!