PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketFrog vs GapiDraw

Pejo Software - Per · 29 Jan 2004, 06:32 UTC
How does PocketFrog compare to GapiDraw in features and performance?
I am thinking of maybe converting my game from GD to PF. Is there Anyone with experience of both PF and GD that can answer this and also give me some advises on how to do this smoothly.
The best person to answer the PF / GD question is Frank Z. as he wrote one game in PF & then beagin the next in GD.

I have only used PF having evaluated both 'way back' but had another look when Frank started using it. Personally the license thing is not an issue I'm just interested in an easy to use, technically neat / fast, game engine with all the basics & I can guarantee that PF has everything I need to write a top class game. (Not that I'm saying my game will be top class, just that PF is capable of producing it). As the source is there to examine extensions are easy and of course with PocketHAL coming out Thierry has gained the performance high ground.

In favour of GD is the cross platform functionality. Obviously PF can be used on any MS PocketPC / Smartphone but several days work would be needed to get it going on Symbian & no one has approached this yet. I guess that GD also benefits from a syntax similar to direct draw but never having used dd I can't say.

PF has more functionality built-in or available as commonly used add-ons.

I'm happy to answer any specific questions so post away.
I'm quite familiar with the performance differences.

PocketHAL is faster on the final blit to the display when running on some PocketPC hardware. You will find the performance differences on the PocketHAL web page. If you are mostly doing low-level surface access (i.e. doing your own blitting or effects, movie playback, or creating a 3D engine) you will get the best performance with PocketHAL on Pocket PCs. It is also easier to access the back buffer using PocketHAL since it is always aligned in portrait mode.

PocketFrog is slower than GapiDraw due to the below listed reasons. When PocketFrog and PocketHAL is finally integrated, the performance increase of using PocketHAL somewhat compensates for these differences. I would say that in many (most?) cases PocketFrog+PocketHAL will be equal in performance to GapiDraw when running on a Pocket PC.
1. In GapiDraw, BltFast is written in ARM Assembler and operates on two pixels simultaneously. PocketFrog always operates on one pixel at a time.
2. All opacity operations in GapiDraw use only one multiplication for each pixel (when blitting to even coordinates) due to the multiple pixel optimizations. PocketFrog uses two multiplications per pixel.
3. On Stationary PCs GapiDraw uses a bridge to DirectDraw for the final blit to display. This is much faster than the GDI BltStretch used in PocketFrog. You can also write full screen applications using video hardware acceleration on Stationary PCs with GapiDraw. Of course, if you only plan to release a PocketPC game then this is not an issue.

I didn't list AlphaBltFast to the list above, since the PocketFrog 0.6 does not have such a function (i.e. blit an image with variable alpha). GapiDraw provides two versions of AlphaBlt/AlphaBltFast and both operates on 32-bits simultaneously.

I guess I could also add that the optimizations in PocketHAL are not valid on any Microsoft Smartphone, but that might change in a future release. So on Microsoft Smartphones GapiDraw is currently a bit faster (and also much less memory-hungry in the image loaders until libpng gets merged into PocketFrog).

I believe we have quite a good bridge for hardware-acceleration already built into GapiDraw, and once the Palm release is out we will give the DirectX8 / OpenGL ES devices a go for hardware acceleration... While we may not be able to compete with PocketHAL for performance on the older IPAQ series, we will try to do so for all the cool new hardware-accelerated devices.
"Thierry has gained the performance high ground."

Only in the final blit which doesn't mean much.
Anyway, the main advantage of HAL ( imho) is the fact that it doesn't use prerotated surfaces.
It makes all kinds of custom blits much easier to write, virtually without any loss of performance.
Johan wrote:1. In GapiDraw, BltFast is written in ARM Assembler and operates on two pixels simultaneously. PocketFrog always operates on one pixel at a time.


Do you have any numbers to support this or is it based on intuition? I would think that the memory bandwidth is the limiting factor when blitting, and not the fact then one or two pixels are written at a time.

Johan wrote:2. All opacity operations in GapiDraw use only one multiplication for each pixel (when blitting to even coordinates) due to the multiple pixel optimizations. PocketFrog uses two multiplications per pixel.


Again do you have any numbers? I am willing to believe it is slower... But by how much?

Johan wrote:3. On Stationary PCs GapiDraw uses a bridge to DirectDraw for the final blit to display. This is much faster than the GDI BltStretch used in PocketFrog. You can also write full screen applications using video hardware acceleration on Stationary PCs with GapiDraw. Of course, if you only plan to release a PocketPC game then this is not an issue.


PocketHAL will soon support full screen apps using DX8/DX9.

Johan wrote:I guess I could also add that the optimizations in PocketHAL are not valid on any Microsoft Smartphone, but that might change in a future release.


Yep, next release.

Johan wrote:I believe we have quite a good bridge for hardware-acceleration already built into GapiDraw, and once the Palm release is out we will give the DirectX8 / OpenGL ES devices a go for hardware acceleration... While we may not be able to compete with PocketHAL for performance on the older IPAQ series, we will try to do so for all the cool new hardware-accelerated devices.


PocketHAL will also use all available acceleration. That's the whole point of PocketHAL.
warmi wrote:Only in the final blit which doesn't mean much.


You'd be surprised at comments I receive. People who says the same thing and then try it and report a performance increase of 10%.
Hi Thierry!

I would think that the memory bandwidth is the limiting factor when blitting, and not the fact then one or two pixels are written at a time


Actually, reading and writing two pixels simultaneously effectively halves the amount of traffic to and from the data cache. While not providing a 100% performance increase as in PocketHAL for the final blit, the performance increase is quite significant.

Do you have any numbers to support this or is it based on intuition? I would think that the memory bandwidth is the limiting factor when blitting, and not the fact then one or two pixels are written at a time.


Actually I do. The MFC demo in GapiDraw running on an IPAQ 3630. With an optimized blitloop only copying one pixel at a time it was capable of around 230 sprites simultaneously running at 30FPS. With multiple pixel operations it now supports more than 270 sprites simultaneously. Add ASM optimizations to that and you get up to 290 sprites simultaneously. The performance gain in this case was more than 17% (using C++ code for 270 sprites and simply rewriting the Blit routines). Please also consider that the MFC demo does two full screen blits (from plant surface to backbuffer to display), which by themselves takes around 9 msec (which would be around 7 msec if PocketHAL was used), which means that the performance increase of 17% only was gained from 72% of the available frame time (1-(9/33msec)). Give me a few minutes tomorrow and I'll get some real stats (including opacity)... I'm actually quite interested in the actual increase in performance myself...

Also.. FillRect with opacity also uses 32-bit operations in GapiDraw. The performance here is even larger, up to 40%. I'll arrange some real figures tomorrow including a sample application (I'll compare GapiDraw 1.04b which uses template loop expansion similar to PocketFrog with 3.0 which operates on multiple pixels simultaneously). And I'll just compare memory surface -> memory surface operations.

PocketHAL will soon support full screen apps using DX8/DX9.


Cool, I didn't know that. With the added smartphone support you'll soon have quite the Win32 package.. :)
Thierry: I was planning on benchmarking the following list. Please add if you have any other suggestions for me to test. I only have access to an IPAQ 4150 at the moment so I'll run the tests on that machine. I will repeat every test 1000 times to get a mean value.

Description
SU - Source Unaligned (starts on an odd address)
DU - Destination Unaligned (starts on an odd address)
SUDU - Both Source and Destination aligned or unaligned

1. BltFast without colorkey, 32x32, 256x256, SU, DU, SUDU
2. BltFast with colorkey, 32x32, 256x256, SU, DU, SUDU
3. BltFast without colorkey with opacity, 32x32, 256x256, SU, DU, SUDU
4. BltFast without colorkey with 50% opacity, 32x32, 256x256, SU, DU, SUDU
5. BltFast with colorkey with opacity, 32x32, 256x256, SU, DU, SUDU
6. BltFast with colorkey with 50% opacity, 32x32, 256x256, SU, DU, SUDU
7. AlphaBltFast, 32x32, 256x256, SU, DU, SUDU
8. FillRect, 32x32, 256x256, SU, DU, SUDU
9. FillRect with opacity, 32x32, 256x256, SU, DU, SUDU
10. FillRect with 50% opacity, 32x32, 256x256, SU, DU, SUDU

Of course, if anyone else has something they would want to see benchmarked then please post it here.. :)
Johan wrote:
Of course, if anyone else has something they would want to see benchmarked then please post it here.. :)


I think it will be better to not bench SU DU SUDU (SADA) case but repeat the test 1000 times with random coordinate value, the user do not want to know if the adresses are aligned or not.... The mean value is the most interesting.

Also, could you provide the source of the benchmark itself, so other people could use it to bench their own 2D layer.

Too bad I do not have a 4155 for now...

If I send you an exe that perform the test and report the results in a nice .txt, could you run it on your device ?
Of course, the benchmark have to be performed with exactly the same data.
I think it will be better to not bench SU DU SUDU (SADA) case but repeat the test 1000 times with random coordinate value, the user do not want to know if the adresses are aligned or not.... The mean value is the most interesting.


Agreed. I'll call srand(0) at application startup

Also, could you provide the source of the benchmark itself, so other people could use it to bench their own 2D layer.


Sure!

If I send you an exe that perform the test and report the results in a nice .txt, could you run it on your device ?


No problem! Email to johan.sanneblad@home.se (<- my spam-address that gets around 200-300 viruses and spams every day) :)
Thierry wrote:

Do you have any numbers to support this or is it based on intuition? I would think that the memory bandwidth is the limiting factor when blitting, and not the fact then one or two pixels are written at a time.



When the data are already in the cache then performing operation on multiple pixel really speed up many operations.

With RLE encoding it's possible to blit as much as 16 pixels at a time, and the performance increase is really significant.
Johan wrote:
Agreed. I'll call srand(0) at application startup


And fill an array with all those rand value before the bench.

I use my own optimised rand number generator, and we don't want to bench it.
How about having a 3rd party (neutral) write the benchmark code? StephC already wrote one as far as I know, and it looked quite nice.

If the code can easily be modified to use different libraries (GapiDraw, PocketFrog, ..) then we could have some useful numbers to work with?

I mention all this because it is way too easy to write benchmark code that will make either library look bad.
Thierry: Agreed..
It's the Rumble in the Jungle! Johan is pulverizing a heavy bag! Thierry is doing the rope-a-dope!
mlepage wrote:It's the Rumble in the Jungle! Johan is pulverizing a heavy bag! Thierry is doing the rope-a-dope!


That's exactly what I want to prevent =) Let's have a 3rd party bench the libs and then Johan and I can get back to some more optimizations =)
Thierry":3tog4hny]

It's quite easy to write a common bench loop, use identical sprites and surfaces, etc, and post the executables in this forum.

Johan, please provide the first bench source code and data (sprites), we'll eventually refine it and then all compile an executable and post it here.

Everyone could then be able to run the bench on his device and report the results, this may be very interesting to see the difference between strongarm, xscale (pxa250 & pxa255) and samsung based devices.
Here is the protocol I've used with gxmark to eliminate glitches due to OS interrupts (I guess).

for N samples

if (N/2)+1 samples are identical then -> result = this sample

else

result = (sum samples / N)
Pejo Software - Per · 29 Jan 2004, 20:09 UTC
This tread is turning out exactly how I wanted it! It would still be nice with some more feature comparisons and also maybe some more comments of the look and feel. Someone that identifies himself with Kosh could perhaps write a few words!?
Gee, someone said I was the one to ask (must not cry... must not cry...), so let me put in my $.0000000000000002 here...

First, the disclaimer: I have NOT played with PocketHAL at all yet, so I am completely unqualified to talk about it.

I CAN however make fair comparisons between GD 2.05 and the last non-PocketHAL version of PF.

It's also fair to point out that my PF project was not the type of game that required a great deal of speed, while my current GD project is.

That all being said, here's some honest opinions comparing both...

(1) The overall functionality provided by PF and GD is, in my mind, essentially a wash. It comes down to what your going to do with them which one is superior in terms of functions.

GD offers more in the way of blits, things like effects. There's many more options in that department than PF. But, PF offers pixel shaders, which can be an incredibly powerful tool (I know, you can more or less do the same things with GD because you have direct surface access... it's not the same thing though, if for no other reason than a pixel shader is a more intuitive way of doing certain things).

PF has more in the way of primitive drawing tools (well, the version I put out does anyway :) ), GD could I think do with having some more line, polygon, circle, etc.-type functions added.

GD has far superior image loaders. This is perhaps my single biggest complaint with PF, and the one thing more than anything else I hope Thierry addresses in the first PF/PH release (I beileve I read that he is, so I am happy!).

Both provide intrinsic clipping and intersect functionality, so there's no need to re-invent the wheel there.

I'd dare say there's very little you couldn't do in one vs. the other, so let's move on...

(2) Ease of use... both are pretty simple to get going with and to work with in general. I don't think anyone will have problems jumping between them, and getting started probably isn't easier in one vs. the other. Having the source for PF is a plus when you are trying to understanding what's going on at first though.

(3) Performance... ok, we could argue all day here, so I will make what I think is a perfectly fair statement... for 90% of what 90% of all develoeprs will do, the performance of each is not the limiting factor, hardware is. And I'm not talking about WindowsXP needing a 1GHz PC to run effectively vs. a 266MHz PC... what I mean is that your performance will be limited by bottlenecks inherit in the current crop of PocketPC's, namely these lousy graphics co-processors that, how shall I say it... BITE MY ASS!... NOT by either library's code.

Might GD get a few extra FPS in some demos? Sure. Might PF win out in a couple? Yes. Might PH make PF even a bit better? Of course.

But, in the end, I think you'll find either library more than sufficient for the vast majority of projects out there. I think performance is the one area you should look at the LEAST when considering these libraries actually. They are both excellent, and 60FPS vs 56FPS isn't the biggest deal in my mind.

In conclusion, from a purely technical standpoint, I don't see either library towering over the other. There are pluses and minuses both ways, but both are completely useable for most tasks equally well, all things considered.

It's actually nice to have a choice like this where you can be assured that either path will lead to success. You can base your decisions on factors other than the technical merits, to a large extent. For instance, I choose GD for my current project for two reasons, and none else: (1) at the time Thierry wasn't going to be supporting PF, and I didn't want to do it AND try and write a game, and (2) GD offered me the ability to release for the desktop as well (I didn't consider PF's GDI-based approach a viable alternative). The image loader thing mattered too, but I've frankly discovered that my complaint in that department had more to do with the way I architected Invasion: Trivia than the image loader itself, so it wasn't a big factor at all.

ADDENDUM: I should point out that I actually relate to the Shadows far more than Kosh, but I couldn't find a good enough picture of a Shadow. Besides, one First One is just about as good as any other I figure...
Here, I fixed an easy-to-use template class for your enjoyment.. First some figures running on a stationary PC (I didn't have time to try it out on my Pocket PC):

GapiDraw 1.04:
BltFast 32x32, 22, ms
BltFast 32x32 with 50% opacity, 86, ms
BltFast 32x32 with 10% opacity, 101, ms
BltFast 128x128, 307, ms
BltFast 128x128 with 50% opacity, 1338, ms
BltFast 128x128 with 10% opacity, 1540, ms
BltFastColorkey 32x32, 70, ms
BltFastColorkey 32x32 with 50% opacity, 76, ms
BltFastColorkey 32x32 with 10% opacity, 85, ms
BltFastColorkey 128x128, 1045, ms
BltFastColorkey 128x128 with 50% opacity, 1165, ms
BltFastColorkey 128x128 with 10% opacity, 1301, ms
AlphaBltFast 32x32, 233, ms
AlphaBltFast 128x128, 2035, ms
FillRect 32x32, 94, ms
FillRect 32x32 with 50% opacity, 72, ms
FillRect 32x32 with 10% opacity, 109, ms
FillRect 128x128, 184, ms
FillRect 128x128 with 50% opacity, 1110, ms
FillRect 128x128 with 10% opacity, 1679, ms

GapiDraw 3.0 (32-bit):
BltFast 32x32, 23, ms
BltFast 32x32 with 50% opacity, 57, ms
BltFast 32x32 with 10% opacity, 100, ms
BltFast 128x128, 272, ms
BltFast 128x128 with 50% opacity, 851, ms
BltFast 128x128 with 10% opacity, 1512, ms
BltFastColorkey 32x32, 36, ms
BltFastColorkey 32x32 with 50% opacity, 59, ms
BltFastColorkey 32x32 with 10% opacity, 116, ms
BltFastColorkey 128x128, 503, ms
BltFastColorkey 128x128 with 50% opacity, 850, ms
BltFastColorkey 128x128 with 10% opacity, 1482, ms
AlphaBltFast 32x32, 101, ms
AlphaBltFast 128x128, 1467, ms
FillRect 32x32, 12, ms
FillRect 32x32 with 50% opacity, 21, ms
FillRect 32x32 with 10% opacity, 101, ms
FillRect 128x128, 125, ms
FillRect 128x128 with 50% opacity, 227, ms
FillRect 128x128 with 10% opacity, 1507, ms

Here's how to use the class:

1. Initialization. Add the following to your initialization:
Code:

m_gfxbench.Initialize(TEXT("\\gfxbench.txt"), &m_sprite32x32, &m_sprite128x128, &m_sprite32x32alpha, &m_sprite128x128alpha, pDisplay->GetBackBuffer());


2. In your main loop, add something like:
Code:

// PASTE THE FOLLOWING CODE IN YOUR BLIT LOOP -------------------------------
static DWORD bTestDone = FALSE;
static DWORD dwTestStatus = 0;
if (!bTestDone)
{
str1 = TEXT("<Processing benchmarks>");
str2 = TEXT("Please wait...");
if (0 == dwTestStatus)
{
m_gfxbench.WriteFile(TEXT("Starting with default display mode"), 0);
m_gfxbench.WriteFile(TEXT("-----"), 0);
}
m_gfxbench.RunTests();
dwTestStatus++;
}
else
{
str1 = TEXT("All done!");
str2 = TEXT("<Press any key to exit>");
}
switch (dwTestStatus)
{
case 1:
SetDisplayMode(GDDISPMODE_ROTATE90CCW);
m_gfxbench.WriteFile(TEXT("-----"), 0);
m_gfxbench.WriteFile(TEXT("Changing display mode to 90 degrees counter clockwise rotation"), 0);
m_gfxbench.WriteFile(TEXT("-----"), 0);
break;
case 2:
SetDisplayMode(GDDISPMODE_ROTATE90CW);
m_gfxbench.WriteFile(TEXT("-----"), 0);
m_gfxbench.WriteFile(TEXT("Changing display mode to 90 degrees clockwise rotation"), 0);
m_gfxbench.WriteFile(TEXT("-----"), 0);
break;
case 3:
SetDisplayMode(GDDISPMODE_ROTATE180);
m_gfxbench.WriteFile(TEXT("-----"), 0);
m_gfxbench.WriteFile(TEXT("Changing display mode to 180 degrees rotation"), 0);
m_gfxbench.WriteFile(TEXT("-----"), 0);
break;
case 4:
bTestDone = TRUE;
break;
default:
break;
}
// --------------------------------------------------------------------------


3. Finally, subclass the GfxBench template class and add calls to your own blit routines:
Code:

// PASTE THE FOLLOWING CODE TO YOUR PROJECT ---------------------------------
template<class _Surface>
class CGapiDrawBench : public GfxBench<_Surface>
{
// Attributes
private:
GDALPHABLTFASTFX m_alphabltfastfx;
GDBLTFASTFX m_bltfastfx;
GDFILLRECTFX m_fillrectfx;
COLORREF m_clrFillColor;

// Construction
public:
CGapiDrawBench()
{
m_clrFillColor = RGB(0, 0, 255);
};

// Implementation
public:
// A simple 1:1 blit with variable dwOpacity from the entire source to destination at [x,y]
virtual void BltFast(_Surface* pSourceSurface, _Surface* pAlphaSurface, _Surface* pDestinationSurface, DWORD dwOpacity, DWORD x, DWORD y)
{
m_bltfastfx.dwOpacity = dwOpacity;
pDestinationSurface->BltFast(x, y, pSourceSurface, NULL, GDBLTFAST_OPACITY, &m_bltfastfx);
}

// A simple 1:1 color keyed blit with variable dwOpacity from the entire source to destination at [x,y]
virtual void BltFastColorkey(_Surface* pSourceSurface, _Surface* pAlphaSurface, _Surface* pDestinationSurface, DWORD dwOpacity, DWORD x, DWORD y)
{
m_bltfastfx.dwOpacity = dwOpacity;
pDestinationSurface->BltFast(x, y, pSourceSurface, NULL, GDBLTFAST_KEYSRC | GDBLTFAST_OPACITY, &m_bltfastfx);
}

// Alpha blend source surface with destination based on the opacity in the alpha surface and dwOpacity
virtual void AlphaBltFast(_Surface* pSourceSurface, _Surface* pAlphaSurface, _Surface* pDestinationSurface, DWORD dwOpacity, DWORD x, DWORD y)
{
m_alphabltfastfx.dwOpacity = dwOpacity;
pDestinationSurface->AlphaBltFast(x, y, pSourceSurface, NULL, pAlphaSurface, NULL, GDALPHABLTFAST_OPACITY, &m_alphabltfastfx);
}

// Fill a blue rectangle on the destination surface the size of the source surface using dwOpacity
virtual void FillRect(_Surface* pSourceSurface, _Surface* pAlphaSurface, _Surface* pDestinationSurface, DWORD dwOpacity, DWORD x, DWORD y)
{
m_fillrectfx.dwOpacity = dwOpacity;
pDestinationSurface->FillRect(CRect(x, y, x+pSourceSurface->GetWidth(), y+pSourceSurface->GetHeight()), m_clrFillColor, GDFILLRECT_OPACITY, &m_fillrectfx);
}

virtual ~CGapiDrawBench()
{
};
};
// --------------------------------------------------------------------------


It should take less than 10 minutes to benchmark PocketFrog or other libraries with it... I have posted the benchclass and the source for two sample programs here:

http://www.sanneblad.se/johan/temp/gfxbench.h
http://www.sanneblad.se/johan/temp/minimal104.zip
http://www.sanneblad.se/johan/temp/minimal300.zip

I'm in quite a rush so please if anyone has the time feel free to bench ahead (I spent less than two hours on the code)... :)
aw..

As I do not use the OO paradigm at all, I think that I'll rework your code and adapt it to my good old C style.

My engine does not support dynamic switching of the display mode (portrait, landscape, etc), it's hard wired at compile time, but that do not affect the benchmark anyway (same numbers for all orientations).

I'll also try to provide a better sprite for the 128*128 case, which is not very representative of the real gaming world (I think).

I do not have much time in my hands for now, so I'll probably do not post my results today.
The Stationary PC Debug and Release builds crash just after the GD splash screen on my computer (OS : win2000 SP4)
Is BltFast without colorkey just a rectangular copy of a memory block ?

If yes do you think there is a real need to benchmark it ? (trivial code in my opinion)
StephC: Um. Strange. Try opening the VC project if you have Visual C installed and recompile. As I said, i wrapped this baby up quite quickly.

Looking forward to the C version and a better sprite, I can help you out early next week when you have something to work on...
Pejo Software - Per · 30 Jan 2004, 23:56 UTC
I have had a quick look at PocketFrog now and I like the fact that source code is available. The documentation is a little sparse compared to GapiDraw and I do like the GD API more but that is perhaps because I have used that for a while now and before that I have also used DirectDraw.
A question: Is it possible to draw to a temporary memory surface and not only the display object?
Yes, you can do that in both libraries. It's been a while since I used PF, so I'm trying to remember things that are growing fuzzier by the day, but as I recall it's not quite as intuitive as in GD... I think you have to set the render target of the display device to the surface you wish to draw on... something to that effect, someone can of course state it properly, but the bottom line is yes, you can do it with both PF and GD, it's just a question of syntax.
That's exactly right, Frank.

Generally, I'll create a global variable:
DisplayDevice *pDisplay;
And set it in the Splash() function:
pDisplay = GetDisplay();

Then throughout the program I can just reference pDisplay. (Note that that is totally optional though.)
To change the target for blits, you would do something like:
pDisplay->SetRenderTarget(pSurfaceName);

All blits from that point on are drawn on pSurfaceName rather than the pDisplay->GetBackBuffer() surface, until you do:
pDisplay->SetRenderTarget(0);

Of course, a VERY cool thing about PF is that you can create a surface, and give it its own rasterizer. For example:

Surface *pSurface = pDisplay->CreateSurface(240, 320);
Rasterizer *pRasterizer = pDisplay->CreateRasterizer(pSurface);
pRasterizer->Blit(0, 0, pImage1);
pRasterizer->Blit(120, 0, pImage2);
pRasterizer->Blit(0, 160, pImage3);
pRasterizer->Blit(120, 160, pImage4);

This has the effect of blitting the four images onto the pSurface object. A later call to:
pDisplay->Blit(0,0,pSurface);
would put the composite image onto the BackBuffer, ready for the next:
pDisplay->Update();

Simply put, I think the functionality rocks.

Enjoy,
-John
Pejo Software - Per · 31 Jan 2004, 11:39 UTC
I just realized that my current game is only using a small subsets of the rendering routines available from GD and PF (standard blits and some opacity). So maybe I'll write my own blitting code, this could be a great learning experience. Perhaps the RLE approach could be something to look at.
Presto,
In your rasterizer thing... what is the advantage of blitting to the intermediate surface and then blitting that to the screen... vs. setting the rasterizer and all?
There are probably hundreds of reasons why you'd want an intermediate surface, but I'll name a couple:

I've used it heavily for keeping track of fog-of-war. Each side has its own surface created the same size as the real battlefield. A black pixel on that surface means they haven't seen that pixel on the real battlefield, grey means they have, but can't anymore, and white means they can see that pixel right now. Using PF's shader, I can just blit that image on top of the composite image of the battlefield with all of the units on it, and the fog-of-war is complete. It's quite fast, but not fast enough that it could be run each frame.

I use intermediate images in Dr. Pocket as well. First, I load up the possible backgrounds, which are also used randomly as backgrounds for the menu screens. But for the play screen, I take the background selected by the user, darken parts of it, add the bottle, score/high-score box, time box, etc. and have the new play screen background all stored on a temporary surface. It saves A LOT of time to just blit that one full-screen image each frame, rather than blitting a full-screen background, darkening about 75% of it, and then applying an almost-full-screen overlay on top of that each frame. (That doesn't count the actual data, like viruses, pills, scores and time.)

You may want one image file/resource/etc, and pre-render other images based off of it for speed/memory efficiency. For example, pixel shaders... Do you want to modify the original image with them? Probably not, and you probably don't want to run the pixel shader every frame in realtime... Solution, blit the original image to an intermediate surface, use the pixel shaders on that surface, and then use that new surface when you blit to the backbuffer. These are games. Speed is important.

In any case where you want to have a flexible image on hand, and it doesn't come from a resource or file (hence it being flexible), most likely you'll need to have it stored on an intermediate surface... unless you want to bloat the installation package with all of the possible image combinations... which of course none of us want to do.

Hope this helps,

-John
Presto wrote:There are probably hundreds of reasons why you'd want an intermediate surface, but I'll name a couple:

I use intermediate images in Dr. Pocket as well. First, I load up the possible backgrounds, which are also used randomly as backgrounds for the menu screens. But for the play screen, I take the background selected by the user, darken parts of it, add the bottle, score/high-score box, time box, etc. and have the new play screen background all stored on a temporary surface. It saves A LOT of time to just blit that one full-screen image each frame, rather than blitting a full-screen background, darkening about 75% of it, and then applying an almost-full-screen overlay on top of that each frame. (That doesn't count the actual data, like viruses, pills, scores and time.)

-John


I do not use the "surface" concept in my games, all drawing function are directly writing in the backbuffer. (simple & fast)

When I want to prerender a background I simply render it in the backbuffer and then save it in an other buffer, I use macros for this kind of things...

- renderbackground
- SCREEN2BACKGROUND // save the whole back buffer in the "background"

and I start the main game loop by :

BACKGROUND2SCREEN; // restore the saved background

off course, you may need to save and restore only a part of the backbuffer, this is not very complicated to solve..

The only drawback is that I can't create images bigger than the backbuffer...
Presto, I'll have to dig deeper into the rasterizer stuff I guess...

As for temp surfaces, I've got those down. I made a class called autoscaleimg - where you initialize it with an image, then request it at different sizes. The resul it kept in a temp surface so it can be returned quickly without a recalculation if the size didn't change.

Thierry, the surface->lock in pocketFrog will not need any rotation done once pHal is incorporated, right? And would this be as fast(or at least close) as using pHal directly for direct pixel operations?
But you can blit to other surfaces using GapiDraw. I sometimes compose images into another surface before I blit that surface (and more) to the backbuffer.

Maybe I lost the conversation somewhere but isn't this something you can do in both PF and GD? What were we saying was better in which?
Pejo Software - Per · 01 Feb 2004, 20:39 UTC
Started with my own routines today and implemented loading of png images with libpng and simple blitting. All on top of PocketHal. It wasn't as hard as I first expected it to be. I guess PocketHal does most of the job.
So has anyone done some benchmarking yet?
I'll post source + new sprite gfx + results for sample programs running PF 0.6, GD 1.04 and GD 3.0 later today.
fast_rx wrote:Thierry, the surface->lock in pocketFrog will not need any rotation done once pHal is incorporated, right? And would this be as fast(or at least close) as using pHal directly for direct pixel operations?


That's exactly right. Lock() will probably not be needed anymore, but I'll leave them there (with empty bodies) so that the lib stays "backward" compatible.
Pejo Software - Per · 03 Feb 2004, 10:23 UTC
Yesterday I implemented a blit function with keysource that works with two pixels at the same time, this gave a speedup of 100% compared to working with one pixel as done in PocketFrog. For now the routine only works when source and destination is DWORD aligned so I have some more paths to implement. I don't think this will slow things down that much(though I have not given it much thought yet).
Implementing blitters is really fun and not as hard as I thought it would be! The good thing is that PocketHal takes care of screen rotations and all that stuff(This something that I wouldn't think was fun handling bu myself).
Alignment is a pain.

Once upon a time I ported older commercial DOS code to 64-bit alpha. If things weren't aligned, the program did Bad Things.

The library I was porting had its own little array allocator, so I just tweaked it to always add a bit extra on the front to align if necessary. Then during access, I added the same amount if necessary.

This was the quickest solution to port the codebase over. It worked so well that the original author used it on 64-bit PowerPC as well.

They also offered me a job in California which I for some reason didn't follow up on. Oh yeah I remember now that reason was stupidity. :-)

So yeah alignment is a hassle.