Predict the pitch of a texture before creation?

Started by
2 comments, last by Nik02 10 years, 8 months ago
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?
Advertisement

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.

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

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

triangle_thumb.png?imgmax=800

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?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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.

Niko Suni

This topic is closed to new replies.

Advertisement