Cognition of A getleveldesc Function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.