Optimized bliting and put_pixel routines

Started by
15 comments, last by HIND-D 23 years, 3 months ago

To Stan :

Hardware blit wins pretty much hands down.

I'm currently doing a slightly modified RLE scheme with software drawing, and its decently fast, which is why I haven't bothered with hardware acceleration yet. But remember, the beauty of RLE is that it saves in overhead and blitting of non-visible pixels. But, the raw bandwidth that you can move pixels to the video card with isn't changed.

------------------
- Remnant
- (Steve Schmitt)

- Remnant- (Steve Schmitt)
Advertisement
Well, you can optimize that even more. If you use a good optimizing compiler (DJGPP _MIGHT_ do this, not sure), you can just say buffer[y * 320 + x] = c, and it will optimize the multiplication very nicely. If not, here is some good assembly:

mov edi,[y]
shl edi,6
lea edi,[edi*4+edi]
add edi,[buffer]
add edi,[x]
mov al,[c]
mov [edi],al

As for the blit, hardware acceleration is the way to go. If you can't do that however, compiled sprites. This is where you actually generate like a function that specifically draws a particular sprite, pixel by pixel. This avoids any jumping, colorkey testing, etc...only limitation is memory and the fact that it can be a pain in the ass. If that is a problem too, use RLE.

How would i do a realy fast mode13h bliting routine?
And is this put_pixel optimized? can i be done faster (can be c/c++ or inline asm)

void putpix(int x, int y, int color)
{
if(x < 320 && x > -1 && y < 200 && y > -1)
{
vgamemory[(y<<8)+(y<<6)+x] = color;
}
}

vgamemory is a pointer to VGA-memory (duh)

Jonatan Hedborg
Compiled sprites don't really work well except on 386's. They wreak havoc with the cache. Plus they can't be clipped. I think RLE sprites are much better. Better still would be an MMX sprite blitter though.

Rock

Thers actually one more blitting scheme to consider, it has predictable performance is easy to implmement and well can easily be unrolled.

The drawback is that it makes all your sprites twice as big :/

the idea is this, save every pixel as a "alpha","color" pair and when blitting you and the destination with alpha and or it with color. So basicly a you set alpha to zero for non transparent pixels and you set it to 0xFF for 8bpp 0xFFFF for 16bpp etc. and for a transparent pixel the color should be zero. easy huh?
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
quote:Original post by HIND-D

How would i do a realy fast mode13h bliting routine?



How about doing a table look-up for y-coordinates offsets?






[home page] [e-mail]

---
"Lifting shadows off a dream once broken
She can turn a drop of water into an ocean"
---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]
Many years ago I wrote a mode 13 library that uses a combination of C and assembler. It''s hardly something I''m proud of, but it may have some useful tidbits. It''s fully commented and totally free to use (no strings attached). It includes assembly language blitting routines, plus a few things like a GIF loader, brezenham line routine, FLI player, etc. Nothing special, but somebody did write an article about it for C Users Journal at one point.

ftp://ftp.islandnet.com/Mark_Morley/vgl20.zip

and

ftp://ftp.islandnet.com/Mark_Morley/vgl20fli.zip for the sample FLI animation.

Toom

This topic is closed to new replies.

Advertisement