#### Archived

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

# Ideas to make this faster? (in SDL)

This topic is 5937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is the pixel draw function I use:
inline void pset(int x, int y, Uint8 R, Uint8 G, Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);

Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}

and filling a 1024*768 screen this way goes much too slow. This is the vertical line drawing function I use:
inline void vLine(int x, int y1, int y2, Uint8 R, Uint8 G, Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);

Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y1*screen->pitch/4 + x;

y2 *= w; //w = the screen width!

for(int y = 0; y < y2; y+=w)
{
*(bufp+y) = color;
}
}

And drawing 1024 of these lines with full height on a 1024*768 screen is STILL too slow! I update the screen only once, after I drew all the lines. They said me that for software rendering engines, drawing multiple pixels at once in a loop like in the vLine function, is the way they do it, but then why is my function still much slower? Are there ways to optimize this? P.S. I'm not even using different colors for the vertical lines like should be in a software renderer! The whole line has only one color :/ P.S.2: Horizontal lines may go faster, but my engine is a Wolf3D raycaster so it have to be vertical lines. [edited by - Lode on September 8, 2002 6:37:17 AM]

##### Share on other sites
in 1024x768 all 3d engines will be slow Memory transfer thru cpu is slow.
If you want such hi-res mode use 3d acceleration to draw your bitmaps.
If you want it software, use mode like 640x480 and it will work fine.

PS.don''t draw directly to vidmem. First draw stuff in sysmem and then copy the whole buffer to vidmem backbuffer and flip buffers. This is the best method to do it, esp. if you want stuff like alpha-blending etc. which requires reading pixels from screen.(vidmem read is terribly slow, like 50x slower then write)

##### Share on other sites
you can perhaps replace the divided by four by a rightshift of 2
x/4 ~ x>>2 .

maybe you can replace the for loop by a piece of asm code. Probably use a ''repmov'' or something. that should speedup things dramatically.

The problem could also have to do because you try to adress the graphic card directly this process can be slow.

##### Share on other sites
if you just want to filled rectangles use SDL_FillRect(Look it up in the docs). If you want to draw vlines then use a memset to set all the pixels at the same time. It might make it faster.

##### Share on other sites
I recommend drawing horizontal lines, not vertical lines, as you won''t have any cache misses. Try to get your multiplications out of there, by the way. Most of them can be replaced with simple additions or bit shifts.

- JQ
Full Speed Games. Coming soon.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633669
• Total Posts
3013259
×