#### Archived

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

# Need Faster Blt Routine

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

## Recommended Posts

I am using the generic Blt() function in DirectDraw to draw my sprites. However, I have some surfaces that are quite large, such as 800x600 background surfaces and other large bitmaps that are the width/height of the screen. I have noticed when drawing those larger surfaces to the screen (I draw to the backbuffer first, then flip(pageflipping)), the program gets very slow. What is causing this, and how else could I load these larger bitmaps, in order for them to blit faster. Help is appreciated. Thanks.

##### Share on other sites
i may very well be way off, but the slow down probably isnt in the blitting part of the loop, but in the part where you are adding data into the back surface.

here in castle camelot we eat ham and jam and spam alot!

##### Share on other sites
I had this exact problem in my program. I found that that if you use color keys, your blit will slow down immensly. If you are blitting a background, then use BltFast() (I think that''s what the function is called) and don''t use colorkeys. It will speed that blit much faster. If you are blitting sprites that will move around above the background and you want to have a color key, one thing, I think at least, that you can do to speed up the blit is break up the bitmap so that the center parts of it don''t have to have color keys, and then put the edges around the center box creating a full sprite, but only the edges will have the color keys instead of the entire bitmap. I hope this helps. If I confused ya, email me at VChelaru@hotmail.com

-- Vic --

##### Share on other sites
The location of the surface you''re blitting to and from makes all the difference:

System -> System:
CPU does all the work, limited by CPU speed, usually very quick on modern CPUs, but selective operations like colour keying might be quite slow.

Video (Local) -> Video (Local):
Super fast, what you should always be aiming for. The only limit is the speed of the video card. The other advantage is the blit happens in parallel to what you''re doing with the CPU (true multiprocessing).

System -> Video (Local):
Slow!. You''re limited by the speed of the PCI or AGP bus (depending on where the graphics card is) as well as by the DMA controller. On true DMA you can stil get parallelism though since the DMAC is doing the work not the CPU

AGP (Non Local) -> Video (Local):
Similar to System->Video, but slightly better since the memory is set aside specially for video card transfers.

AGP (Non Local) -> AGP (Non Local):
Slightly slower than System->System, usually done with the CPU (although some video card drivers intervene with hardware help) - the slowness comes from the different cache characteristics of AGP memory versus system memory (ie. AGP doesn''t use CPU cache because graphics card can''t snoop on that).

Video (Local) -> System:
Super Super slow, avoid at all costs! - transfer has to go over the bus, theres no read caching etc

There are other less common permutations which I won''t go into here.

Generally try to set stuff up so that it prefers video to video for everything, then chooses AGP to video as a second choice with system to video as a worst case.

You may be able to do some intelligent uploads if you really have to go from system to video where you cache commonly and recently used stuff etc...

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

##### Share on other sites
For some reason I can''t get BltFast to work! I am not sure what I am doing wrong. The first function that draws the bitmap, uses Blt(which works fine, only seems to be slow), while the second part of the code uses the BltFast function, which is what I am having problems with. The BltFast function doesn''t draw anything to the screen for some reason. It just doesn''t draw.

Here is the Blt() code:
int DDDrawSprite( DDSPRITE sprite , int blt){ // blt = 1 or 2, Blt or BltFastRECT DestRect,SourceRect;DestRect.left=sprite.x;DestRect.top=sprite.y;DestRect.right=sprite.x + sprite.width;DestRect.bottom=sprite.y + sprite.height;SourceRect.left=1;SourceRect.top=1;SourceRect.right=sprite.width;SourceRect.bottom=sprite.height;if(lpddsback->Blt(&DestRect, sprite.images[ sprite.curr_frame ], NULL,DDBLT_WAIT | DDBLT_KEYSRC,NULL!=DD_OK)) return 0;return 1;} // End DDDrawSprite();

And now the BltFast() code:
int DDDrawSprite( DDSPRITE sprite , int blt){ // blt = 1 or 2, Blt or BltFastRECT DestRect,SourceRect;DestRect.left=sprite.x;DestRect.top=sprite.y;DestRect.right=sprite.x + sprite.width;DestRect.bottom=sprite.y + sprite.height;SourceRect.left=1;SourceRect.top=1;SourceRect.right=sprite.width;SourceRect.bottom=sprite.height;if(lpddsback->BltFast(sprite.x,sprite.y,sprite.images[sprite.curr_frame],&DestRect,DDBLTFAST_WAIT )!=DD_OK)return 0;return 1;} // End DDDrawSprite();

So, with this code, what am I doing wrong here? Thanks.

##### Share on other sites
BltFast is only faster if your videocard has no hardware acceleration...So most systems these days won´t benefit from bltfast....

This is taken from the docs (DirectX 6.0):

"The software implementation of IDirectDrawSurface4::BltFast is 10 percent faster than the IDirectDrawSurface4::Blt method. However, there is no speed difference between the two if display hardware is being used."

-- Look at you hacker. A Pathetic creature of meat and bone, panting and sweating as you run through my corridors. How can you challenge a perfect, immortal machine?--

"Yeah, I''ve seen people w/ ''so-called'' lives. They are petty and thoughtless." - Nazrix

##### Share on other sites
The reason FastBlt may not be working is you have a clipper attached (?). FastBlt has a problem with clippers.

As for Blt being "as fast" as FastBlt or "only 10% slower" depending on hardware acceleration - believe that at your own peril.

El Duderino

##### Share on other sites
I made sure that the sprite was small, and not bounding any of the screen edges. I also took out the clipper. BltFast still doesn''t work. What else could it be?

• ### Forum Statistics

• Total Topics
628698
• Total Posts
2984275

• 20
• 10
• 13
• 13
• 11