IDirect3DTexture9 assumes column major?

shuipi

Newcomer
IDirect3DTexture9 *texture;

D3DXCreateTexture(d3dDevice, width, height, 1,
0, D3DFMT_R32F,
pool, &texture));

float Table[width * height];

for(unsigned int row = 0; row < height; row++)
{
for(unsigned int col = 0; col < width; col++)
{
Table[row * width + col] = (float)row / col;
}
}

D3DLOCKED_RECT lockedRect;
texture->LockRect(0, &lockedRect, NULL, 0);

for(int j = 0; j < height; j++)
{
MemCopy((byte*)(lockedRect.pBits) + j * lockedRect.Pitch, &Table[j * width], width * sizeof(float));
}

And then I look at the texels in PIX for Win, it appeard to be uv inverted.
 
They are "row"-major if you want to use that terminology. To be more general, texels are stored linearly along their X, Y then Z dimensions. (Arrays are similar, see docs.)

In your code, you should be computing it as:
data[col * width + row]
 
And then I look at the texels in PIX for Win, it appeard to be uv inverted.

Not sure what you expected to see in PIX, but the code you posted should generate values greater than 1.0 in the bottom-left and below 1.0 in upper right. What are you observing?

In your code, you should be computing it as:
data[col * width + row]

But "col" is x and "row" is y, so his code looks correct to me and yours look wrong.
 
Not sure what you expected to see in PIX, but the code you posted should generate values greater than 1.0 in the bottom-left and below 1.0 in upper right. What are you observing?



But "col" is x and "row" is y, so his code looks correct to me and yours look wrong.

You're right. I got confused for a bit. Thanks.
 
Back
Top