Jump to content
  • Advertisement


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


How to optimize a software blitter?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

For reasons that I won''t go into, I''m writing a 256 color software blitter. Here is what I have so far: I have a blitter structure that I use to hold blitter stuff:

struct Blitter
    UCHAR* dest_bfr;  // pointer to destination buffer

    int dest_pitch;    // byte width of destination buffer

    int dest_x;
    int dest_y;

    UCHAR* source_bfr;  // pointer to source buffer

    int source_pitch;    // byte width of source buffer

    int source_x;
    int source_y;

    int width;
    int height;
} blitter;

I figured I could do that, to avoid sending 10 parameters to my blitting function. Is this a good idea? Here is the blitter function (it is a straight blitter, no clipping, no transparency):

void BlitNoClip(void)
    int d_off = dest_pitch * dest_y + dest_x; // initial destination buffer offset

    int s_off = source_pitch * source_y + source_x; // initial source buffer offset

    for(int y=0; y<height; y++)
        for(x=0; x<width; x++)
            dest_bfr[d_off+x] = source_bfr[s_off+x];
        d_off += d_pitch;
        s_off += s_pitch;

One optimization I see is to replace the inner loop assignment with a memcpy. What other optimizations can I make? Currently it runs OK, but not nearly as fast as I''d like. Thanks.

Share this post

Link to post
Share on other sites
Hello Vanukoff!

I can give you some tips on optimization. So, let''s go:

- Your memcpy idea is a good start. Memcpy on most compilers is quite fast because it uses CPU fast memory instructions like MOVSD ;

- Avoid mul''s. If memory is not an issue, you should use lookup tables;

- There are too fields in your struct. I took it off dest_x, dest_y and dest_pitch. They could change a lot, and you''ll have to access the struct all the time. This is a waste of time. This information can be passed using parameters. Here you need 3 parameters : dest_x, dest_y and dest_surf. I don''t know if you are using DirectDraw or Allegro. However if you got DirectDraw you can pass as paramaters : dest_x,dest_y and dest_surfd (The destination surface''s DDSURFACEDESC2);

- There are two ways to improve blitting, but things will start getting difficult : Assembly language and Direct3D (or OpenGL). The latter is not recommended for dynamic surfaces, like fire;

Good luck!


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!