Page 1 of 1

3D working, need to understand Pitch

PostPosted: Jul 14, 2002 @ 9:05am
by Conan

PostPosted: Jul 16, 2002 @ 7:32pm
by Kzinti
Hi Conan,

I will break down your message in two questions:

Q1: What is the pitch and how to work with it?

A1: The pitch represents the offset in bytes between two row of pixels. A typical error is to use the width of the surface to calculate this offset (where the pitch should be used). You typically won't have to deal with the pitch until you want to use direct access. Basically, you Lock() a surface and the pitch is returned to you. Pixels are then addressed in the following manner:

Pixel(x,y) = (startOfBuffer) + y * pitch + x * 2


Q2: What is Swizzle()/Unswizzle()?

A2: Each device has a different screen orientation (ie: the actual display hardware is mounted sideway on the iPAQ36xx). In fact, the iPAQ36xx has a 320x240 pixels display (not a 240x320!). Doing "rotation" of the backbuffer in real time is slow. Because of this, PocketFrog pre-rotate all surfaces to match the hardware orientation. This is transparent: you draw on a surface using a rasterizer which takes care of this orientation for you.

When doing direct access (or GDI), PocketFrog will rotate the surface to a "normal" orientation by calling Swizzle(). When you have finished updating the surface, PocketFrog rotate the surface back to match the hardware, this is Unswizzle().

Now, there is no need to Swizzle() if you are going to overwrite all the pixels (ex: loading an image, rendering a 3D scene). In the same manner, there is no need to Unswizzle() if you didn't change any of the pixels. This is exposed in the appropriate methods (Lock, Unlock) by the "bDiscard" boolean.

Of course, if the display hardware orientation is already "normal", Swizzle() and Unswizzle() won't do anything (ie: no performance hit).

PostPosted: Aug 3, 2002 @ 3:55pm
by BurningSheep

PostPosted: Aug 3, 2002 @ 5:12pm
by Kzinti

PostPosted: Aug 3, 2002 @ 7:31pm
by BurningSheep
The first method doesn't work on my iPAQ, I'm probably doing something funky. I'm going to try to figure it out later.
It just isn't my day I guess, ActiveSync doesn't even want to install anymore, so debugging on the device is also out of the question at the moment. :\