The getleveldesc function is in msdn:
Retrieves a level description of a texture resource.
Hresult getleveldesc (
Uint level,
D3dsurface_desc * pdesc
);
Parameters
Level
[In] identifies a level of the texture resource. This method returns
Surface description for the level specified by this parameter.
Pdesc
[Out] pointer to a d3dsurface_desc structure, describing the returned level.
This function is used to obtain the width and height of the loaded image and some information. Usage:
d3dsurface_desc DESC;
ptex-> getleveldesc (0, & DESC);
DESC. width;
DESC. height;
ptex is a pointer to the idirect3dtexture9 interface, and reads a texture from the file to the ptex data member.
in this way, you can obtain the width and height of the loaded image.
the first parameter level of this function uses 0 in many reference books and materials. What if we use 1 or a number greater than 1. In fact, the first parameter is a mipmap layer. If we load a 256*256 texture, by default, d3dx will create a mipmap chain (128 *, 64*64 ,..., 1*1 surface), Level parameter 0 (top layer) indicates the actual size. The width and height of each texture layer are halved. For example, for 256*256 textures, level = 0 is 256*256 textures, and level = 1 is 128*128 textures...
it is quite depressing to obtain the texture width and height like this. If the width of your texture is 192, follow the above method and the level parameter is 0, DESC is used. the width value is indeed 256. the reason is that d3dx creates an mipmap chain, which does not contain 192, but is only 256 larger than the chain. the premise of obtaining the width and height of the texture using this method is that the width and height of the texture must be the M power of 2 N and 2, where n and M can be different, (For example, 126*64 textures can also be used). Otherwise, the obtained texture size will be incorrect.