Predict the pitch of a texture before creation?

Recommended Posts

I want to create a texture of D3DFMT_A8R8G8B8 format. If I already know the width and height is there any way I can predict the pitch before calling CreateTexture?

Share on other sites

In my experience it always coresponded to the width of the nearest higher power of two (256, 512, 1024, 2048 etc.).

So a texture 800x600 would have pitch 4*1024, the same as it if was 1024x600.

But I have no idea how reliable this is! That's just my experince, not based on any documentation or something.

Share on other sites

if I'm not stupid, you want the dot pitch?

Well if that's the case, then you should look at this:

So that would be:

float d = sqrt(width^2 + height^2);


Then we can calculate the ppi (pixels per inch) using the ratio of pixels/inches:

float ppi = 1639.2 / 20; // = 81.96 ppi


Sometimes the marketing is different, so they use millimeters, soo:

float dPitch = 25.4 / ppi


I found an example with javascript:

function calcDotPitch(hPixels, vPixels, diagonal)
{
var d = Math.sqrt(hPixels * hPixels + vPixels * vPixels);
var ppi = d/diagonal;
var dotPitch = 25.4 / ppi;
return dotPitch;
}


PS. I have never done this, this was something that I just read, so can somebody please confirm that this is not bullshit?

Share on other sites

The driver is free to give you any pitch greater than or equal to (width * bytesperpixel). The documentation specifically says that you can't rely on a particular pitch, even in subsequent locks to the same surface. This is because the driver can reallocate GPU memory internally (usually to defragment it). With Vista and up, the physical GPU memory reallocation is potentially very frequent because of the video memory virtualization.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628333
• Total Posts
2982139

• 9
• 24
• 9
• 9
• 13