Pitch / offscreen pixels / modulo

In the structure that is returned when you open a fullscreen videomode there
is av value called “pitch”. Pitch is as far as I can see the amount of bytes
on each scanline. Divide this by the amount of bytes in your pixel and you
have the amount of pixels in each scanline.

Under Linux this value is set to match the default resolution and if you
open a smaller resolution you will get an amount of offscreen bytes. Thats
just fine and som nice things added to the API would make it possible to use
hardwarescrolling.

But my questions are?

How is this handled by default under Windoze??
I run XFree86 in 1024x768 and when I open a fullscreen of 320x240 its realy
1024x240 with a lot of offscreen pixels.

Wouldn?t it be nice to be able to controll that pictch (on the Amiga we call
it modulo) when you open the videomode???

/ Christian

In the structure that is returned when you open a fullscreen videomode there
is av value called “pitch”. Pitch is as far as I can see the amount of bytes
on each scanline. Divide this by the amount of bytes in your pixel and you
have the amount of pixels in each scanline.

This is not exactly correct. It is possible to have a pitch that extends
past the edge of the visible screen area:

<–pixels---->
/-------------------
| |
| Visible | Not |
| |
-------------/------/

The invisible area could contain offscreen video surfaces, or may be visible
in the overscan area, so you should write up to the logical pixel width,
rather than the pitch of the surface:

memset(surface->pixels, 0, surface->w*surface->format->BytesPerPixel);

Under Linux this value is set to match the default resolution and if you
open a smaller resolution you will get an amount of offscreen bytes. Thats
just fine and som nice things added to the API would make it possible to use
hardwarescrolling.

Unfortunately, hardware scrolling is not portable. You could under Linux
using XFree86 DGA set the display base address and use that to do hardware
scrolling, but there’s no way to do that in a window or as far as I know
under DirectX (I could be wrong about that, though I looked pretty hard
for a way to do it.)

How is this handled by default under Windoze??

How is what handled under Windows?

I run XFree86 in 1024x768 and when I open a fullscreen of 320x240 its realy
1024x240 with a lot of offscreen pixels.

Yup.

Wouldn?t it be nice to be able to controll that pictch (on the Amiga we call
it modulo) when you open the videomode???

I know of no way on any platform to do that.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Sam Lantinga skrev:

This is not exactly correct. It is possible to have a pitch that extends
past the edge of the visible screen area:

Ok, that?s what I was trying to say…

The invisible area could contain offscreen video surfaces, or may be visible
in the overscan area, so you should write up to the logical pixel width,
rather than the pitch of the surface:

    memset(surface->pixels, 0, surface->w*surface->format->BytesPerPixel);

Yes, anything else would be a real waste of time. :wink:

Unfortunately, hardware scrolling is not portable. You could under Linux
using XFree86 DGA set the display base address and use that to do hardware
scrolling, but there’s no way to do that in a window or as far as I know
under DirectX (I could be wrong about that, though I looked pretty hard
for a way to do it.)

I don?t know anything about DirectX. I puked all over the API when i
read through some of it. but I have a friend who is working with D3D. I
will ask him if he knows a way to do this. But then there?s the
window-problem anyway…

How is this handled by default under Windoze??

How is what handled under Windows?

The fact that pitch is autoset to the value I am running as deafult.
Windows doesn?t use virtual resolution so perhaps it?s diffrent??
Well it doesn?t matter that much.

Wouldn?t it be nice to be able to controll that pictch (on the Amiga we call
it modulo) when you open the videomode???

I know of no way on any platform to do that.

Well, I did this when I created a class for handling VBE under Dos. So I
know how to do it with low-level-stuff but I can?t say if it can be done
through DGA since I don?t know anything about that. I do not like the
idea of not being able change the pitch. It?s allways a nice thing to
have a scanline of 4096 or 2048. Then you can use shifts instead of muls
when addressing the LFB and win a lot of time. But if the pitch is set
by default to a value you can?t be sure of, it can?t be done.

/ Christian

Christian Granstr?m, Bryggerigatan 4A, 733 34 Sala, Sweden
home:0224-77312, cellular:070-4961587, work:018-184470
@christian.granstrom, christian.granstrom at home.se
uin: 206475

How is what handled under Windows?

The fact that pitch is autoset to the value I am running as deafult.
Windows doesn?t use virtual resolution so perhaps it?s diffrent??
Well it doesn?t matter that much.

Oh, windows sets the pitch to a random value. On most video cards the
pitch is equal to the width, but on some it’s equal to … whatever.
CAUTION: The pitch on fullscreen DirectX surfaces can actually change
outside of calls to SDL_LockSurface() and SDL_UnlockSurface() – always
use the new screen format instead of assuming it stays constant.

If the user changes the screen depth while your program is running,
the screen format will change. This isn’t gracefully handled at the
moment by SDL, but with 0.9.x, the support is there to have blits
automatically remap when the display format changes. This will be
fixed by 1.0. Your code will still have to watch to see if the format
has changed, but at least you’ll have a way of knowing when it does.

Wouldn?t it be nice to be able to controll that pictch (on the Amiga we call
it modulo) when you open the videomode???

I know of no way on any platform to do that.

Well, I did this when I created a class for handling VBE under Dos. So I
know how to do it with low-level-stuff but I can?t say if it can be done
through DGA since I don?t know anything about that. I do not like the
idea of not being able change the pitch. It?s allways a nice thing to
have a scanline of 4096 or 2048. Then you can use shifts instead of muls
when addressing the LFB and win a lot of time. But if the pitch is set
by default to a value you can?t be sure of, it can?t be done.

The pitch is set by default to a value you can’t be sure of.
DGA provides no way of setting the pitch. I don’t think DirectX does
either. If you know the surface code really well, you can trick SDL
into creating a buffer with no memory, and then stick in your own memory
area with its own pitch value, so your offscreen surface can have whatever
pitch you want. If there’s any demand for it I can add a flag for this.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/