Archived

This topic is now archived and is closed to further replies.

dj9781

can some explain to me what pitch is?

Recommended Posts

Im just learning directx and Im having a little trouble understanding what the author is talking about when he says pitch. Can someone tell me what it is exactly?

Share this post


Link to post
Share on other sites
lpitch is the number of pixels per line. You use it instead of the number of pixels u count because some videocards require extra room for cache or something.


I think that is right, I remember it from lamothe''s book, I''m still learning all this stuff too. I also didn''t really pay attention to that stuff because I just don''t use drawing primitives at all I just use bitmaps

Share this post


Link to post
Share on other sites
Yup it bytes per scan line. For example if you had a picture 256 pixels wide in 8bpp mode, theoretically the pitch of that bitmap is 256, in 16bpp it would be 512 because there are 2 bytes for every pixel. In 36bpp mode it would be 1024 for a 256 pixel wide surface. However some video cards will make a surface with a greater phycical width than it''s theoretical width. So that 256 pixel wide surface could have any number over 256 pixels for it although it will never double the surface size or anything like that... I don''t remember the reasons for this. But to be safe always use the returned lPitch from locking a surface just in case.

See ya,
Ben

Share this post


Link to post
Share on other sites
We use pitch because sometimes when you create a DD surface, there will be some unusable tacked onto the sides (hardware dependant).

Even though you create a surface of 10 pixels wide for example, DX might have to create one 16 pixels wide.
you can write anywhere on the first 10 pixels, but the remaining six are reserved for DX and you''re not to touch them.

When accessing surface memory via a pointer, and you increase the pointer value so it moves over a pixel, you may write to the no-touch area and crash-boom! So we have to check how many pixels the pointer is over and increase it by the pitch to wrap around to the next line just to be safe.

representation:
width-extra (no write here)
SSSSSSEEEE
SSSSSSEEEE
|-----|
width

|---------|
pitch

if you increase a pointer by the width of this surface you will end up in the E''s which you can''t write to, so you instead increase by the pitch (the extra + width). However in most cases the extra will be zero, see if it works on your computer by adding width instead of pitch.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Even though you create a surface of 10 pixels wide for example, DX might have to create one 16 pixels wide.
you can write anywhere on the first 10 pixels, but the remaining six are reserved for DX and you''re not to touch them.



Looks like someone didn''t read the previous two posts. *sigh*

DX doesn''t change the pixel width of your surface. It changes the pitch
instead. If you request a 10 *pixel* wide suface, that is exactly what
you will get.

Share this post


Link to post
Share on other sites