/////////////////////////////////////////////////////////////////////////////////////
sometimes .... Sometimes.... We are not losing in the big picture but losing in the details ... Fight>>fight>>fight
/////////////////////////////////////////////////////////////////////////////////////
HRESULT Ctex_dx11::loadtex (const tp_box *pdstbox, const void *psrcdata,
UINT Srcrowpitch, uint srcdepthpitch) where the parameter UINT srcrowpitch true meaning is not clear, the result was delayed for a long time, the following explanation:
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, if it is not well understood the meaning of this property, the result of map operation is likely to be wrong.
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):
rowpitch≠width* sizeof (PixelFormat)
Rowpitch is always greater than or equal to the latter, and is generally equal to a 2 power of N. It can also be seen from above that pitch is in bytes, and width is in pixels.
To illustrate:
a id3d11texture2d, the FORMAT property of the D3D10_TEXTURE2D_DESC structure that is used to create it is dxgi_format_r32g32b32a32_float, which is an element that occupies up to three (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, if the map operation of the texture2d, it can be found that the map of the resulting D3D10_MAPPED_TEXTURE2D structure Rowpitch value is 8192 (is greater than 6400 of the smallest 2 n power).
So when you do a map operation, you need to target rowpitch, rather than relying on the width when defining texture.
However, when sampling the texture in the FX file, it is width, as shown in the FX code below. Where offset is the offset from the starting point, G_texwidth is the width of a two-dimensional texture, visible in order to get 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;
|