Jump to content

  • Log In with Google      Sign In   
  • Create Account

FAST alpha-blitter: possible?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Matthew Allen   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 01:56 PM

I read the MMX Enhanced Alpha Blitting tutorial and got the function that he created working, but it goes hideously slow. My game dropped from 75 fps to around 5 fps (no exageration) when I had it do a full screen (800x600) alpha blit. This is at 16 bpp, by the way. Even with smaller blits it's horrible: a 250x80 pixel sprite cut the frame rate in half (75 to 37.5).
Is there any way to make this go any faster? I did this testing on a 450 PIII with a 16 mb TNT video card, so I doubt the method I used will go much faster on any other computer.
What I am trying to accomplish in the end is a console-like screen though which the 2D map behind it can be somewhat seen. If there is a way to just, say, make the 2D map a dark tint of blue, that would be great, but I really don't even know how to do that.
Thanks for any help.

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/


Sponsor:

#2 mason   Members   -  Reputation: 128

Like
Likes
Like

Posted 01 November 1999 - 04:53 PM

Yes.

Use your 3D card's alpha blitting hardware. I'm doing this and have no problems doing 75 FPS on a PII 400 w/RIVA TNT and about 1/2 the screen full of alpha blits.

I believe there's an article by Tobias that explains the process; search for "Enhanced2D."

Mason McCuskey
Spin Studios
www.spin-studios.com


#3 Starfall   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 November 1999 - 07:52 PM

Expecting fast full screen non accelerated alpha is a bit unrealistic, but I think you can do better than 5fps. However, if you just want to make the map a dark tint of blue as you say, I'd suggest you make a routine to shift down the red and green values of the pixels in question. If you have 128k memory to blow, you can even make a lookup of pixels (ie. unsigned short blue_tint[65536]) then precalculate the new pixel value for each of the 65536 possible pixels. This would likely be a little faster still. It's not going to run at 75fps, but implemented properly it will be a big improvement over 5fps. If you only want to run this on your computer you could, as Mason suggested, use your 3D card's acceleration, but I highly recommend you include a software mode if you're planning on other people using your program.

The other suggestion I have (if you're not already using it) is to draw your map to a memory buffer instead of directly to the back buffer. This removes the need for your alpha function to look up video memory, which will save time. Once you've applied your alpha (or lookup table, this should speed up either) to the memory buffer, use BltFast to draw it to the back buffer for best results (this way system -> video hardware acceleration will be used also, if available). If you're drawing your map with a lot of overlap, this might even speed up your initial framerate. Then again, it may also drop it if you aren't drawing a lot of overlap, but in the case of the alpha blending it's worth a try to see if it helps things. It does depend on other factors of your program and hardware, so play around with it and see what you come up with.

Good luck, and post back to the thread if you need any further help.

Starfall

[This message has been edited by Starfall (edited November 02, 1999).]


#4 Matthew Allen   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 04:20 AM

mason: thanks for the enhanced2d link, i'm going to try to use that.

starfall: how would I make a function that shifts down the red and green pixels fast? I editied my alpha blitting function to make is so it does what you said, but it still goes pretty slow. What it does is go through a two loops (one for x, one for y) and changes each pixel on the back buffer (which is in video memory) to only the blue value of that pixel. It does this by ANDing the pixel with a blue mask. This isn't exactly what I want, but I'm not going to fix it if it won't go any faster. What should I do to make it faster?

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/

[This message has been edited by Matthew Allen (edited November 02, 1999).]


#5 Sphet   Members   -  Reputation: 631

Like
Likes
Like

Posted 02 November 1999 - 07:45 AM

You've just identified your problem.

If the surface you are locking and reading from is in VRAM, your frame rate is going to drop significantly. Unless all your sprites fit into VRAM, and since you are doing alpha blends, you need to do your image blting first to a system surface, do your blending there, then blast the whole image (or the dirty rect of it) up to the video surface, then call flip. Reads from VRAM are REALLY REALLY slow..


#6 mason   Members   -  Reputation: 128

Like
Likes
Like

Posted 02 November 1999 - 07:58 AM

---------
If you only want to run this on your computer you could, as Mason suggested, use your 3D card's acceleration, but I highly recommend you include a software mode if you're planning on other people using your program.
---------

Actually Starfall, market research shows that the majority of gamers (in the US, anyway) have a card with some form of 3D acceleration. DirectX takes care of the differences between 3D cards, so if you write the code correctly, it will work on many more systems than just your own.

Mason McCuskey
Spin Studios
www.spin-studios.com


#7 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 02 November 1999 - 08:04 AM

I would have to agree with that last statement. To change the value of a pixel in vram you have to go through the the video bus, change the value and then pass the new pixel again through the video bus (really slow). The fastest would be to keep your rendering surfaces buffer in system memory, do all your plotting and then transfer the surface to the back buffer.

or I could be just rambling.


#8 Starfall   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 01:56 PM

As I said in response to the original post, and as everyone has repeated, using a memory surface will help. To further increase speed you should be moving 4 bytes at a time (2 pixels instead of 1) - though this speed may be lost by the use of the lookup table, since you then need to shift the high word down to look it up, and shift the result back up to put it back in the pixel. As for shifting down the blue and green, as I stated before I suggest you use a lookup table for this. The equation to do the shifting then does not need to be so speed critical, as it is performed at load-time. Apart from assembler optimisation, which can be tricky if you're not familiar with assembler, there aren't any other simple things I can think of to speed things up.

In reply to Mason, if "many more systems than just your own" is good enough for you, so be it. Personally I'd want my software to run on as many systems as possible, and without providing a software alternative you're cutting off a large portion of prospective users. The answer is of course simple, if you want the best of both worlds - offer both.

Regards

Starfall





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS