DRECTX11 study notes Texture2d about

Source: Internet
Author: User

/////////////////////////////////////////////////////////////////////////////////////

有时候....有时候....我们不是输在大局上而是败在细节上......Fight>>Fight>>Fight

/////////////////////////////////////////////////////////////////////////////////////



HRESULT Ctex_dx11::loadtex (const tp_box *pdstbox, const void *psrcdata,
UINT Srcrowpitch, uint srcdepthpitch) in which the parameters of the uint srcrowpitch true meaning is not clear. The results were delayed for a long time. Below to explain it:

In the SDK, the parameter uint Srcrowpitch is interpreted as:

The pitch, or width, or physical size (in bytes), the of one row of a uncompressed texture.


When a map operation is performed on a id3d11texture2d, the D3D11_MAPPED_TEXTURE2D structure is encountered. The structure has a property of uint rowpitch. Assuming that there is no very good understanding of the meaning of this attribute, the result of the map operation is very likely to be incorrect.

The total number of bytes in an ordinary texture line is its rowpitch. However, it is important to note that Rowpitch is not equal to the width of texture2d multiplied by the number of bytes per grain (Texel). That

rowpitch≠width* sizeof (PixelFormat)

Rowpitch is always greater than or equal to the latter, and is usually equal to a 2 power of N. It can also be seen from above that pitch is measured in bytes. and width is measured in pixels.

To illustrate:

A id3d11texture2d. The FORMAT property of the D3D10_TEXTURE2D_DESC structure that was used when it was created is dxgi_format_r32g32b32a32_float, which is an element that occupies up to (4x4) bytes. The Width property is 400, which means that each row has 400 stripes, then each line can be computed with a total of x = 6400bytes. However, assuming the map operation of the texture2d, it can be found that the D3D10_MAPPED_TEXTURE2D structure obtained after the map Rowpitch value is 8192 (is greater than 6400 of the smallest 2 of the n-th power).

Therefore, in the map operation, you need to target rowpitch. Instead of relying on the width when defining texture.

However, when you sample textures in the FX file. The width is the target. See for example the following FX code. Where offset is the offset from the starting point. G_texwidth is a two-dimensional width of the texture, visible in order to obtain offset in the texture of the UV coordinates, the calculation is relative to the width, then do not consider pitch.



uint baseU = offset % g_TexWidth;

uint baseV = offset / g_TexWidth;




DRECTX11 study notes Texture2d about

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.