PocketMatrix forums

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

3D performance - from SetPixel to Blit

Currently I'm taking an array of shorts which is 240 x 320 and one by one putting them onto the back buffer using the code borrowed from the Plasma demo however this seems a really slow way to do this. The frame rate gives an ok 3D display but could be faster.

How can I take this array of shorts where each short is already containing the correct RGB values & simply Blit this to the backbuffer. It's already the correct size with the correct content but it's not a surface. I have tried to make it a surface which builds & then crashes so I obviously don;t know what to do. I guess it's only a few lines of code but I can't figure it out.

Thanks in advance
BurningSheep · 15 Jul 2002, 11:22 UTC
The plasma code is copying shorts, it would be faster if you copied 4 bytes at a time. You should see a nice performance boost when you change this.
Then again there might be a completely different (and better) way of doing it, but you can try this while waiting for Thierry's solution ;)
Conan · 15 Jul 2002, 12:22 UTC — copying longs instead of shorts
I will give this a go & see how the frame rate changes.

The nice thing is that the 3D rendering can be pretty complex without affecting speed as it's optimised for PocketPC so as long as I can get the data on screen as efficiently as possible I should get a good result.

All this adverse XScale news is making me wonder if there will have to be a different screen drawing routine for the XScale devices but I will wait until there's feedback on the Compaq machines before getting really depressed.

UPDATE: Strange, seems that the 3D rendering & Blitting is not the issue. Even if I take out everything 3D I still get too slow a result compared to earlier PocketFrog demos so I have introduced something which is slowing things down I guess. I need to look very closely. At present the 3D is going at one sixth of the speed of it's native PocketGL original animation???
Conan · 15 Jul 2002, 16:35 UTC — Speed improvement by using Lock optional parameter
I changed the x,y based loop to a simple loop just moving pixels & that did not improve things so I turned to Lock & Unlock. The major speed improvement came when I changed over to using:-
Lock(buffer,true);
instead of just Lock(buffer);
The routine is 30% faster now

I don't know if a simple copy loop works on all hardware but for the moment I'm using

for(int y = 0; y < 76800; y++)
{
buffer.pixels[offset] = VScreen[offset];
VScreen[offset] = 0;
ZBuffer[offset] = FAR_CLIP;
offset++;
}
BurningSheep · 15 Jul 2002, 16:53 UTC
you are still copying 2 bytes per cycle into buffer.pixels[]. What I meant was to push 4 bytes per cycle into it. But looking at the code, why not use memcpy to copy VScreen into the buffer?

And also instead of
VScreen[offset] = 0;
ZBuffer[offset] = FAR_CLIP;
use memset() to set them to 0 and FAR_CLIP respectively.
Main reason for not moving 4 bytes instead of 2 was not figuring out how to do it as buffer.pixels seemed to want an int & not a long. I did have a go but got nowhere. ( assembler is so much easier but I am making progress with C++ so I must keep at it )

I will look up memcpy & see how to use it.

As I mentioned is seems to be the lock & unlock side of things which causes most of the cycles to be used up but any speed improvement is welcome.

( In Space Treker the use of 3D will be fairly simple with ship selection & planet & base views and already the speed is fine. I won't actually use a full screen, just 240 x about 200 ).

UPDATE: memcpy & memset worked fine for the data and the init of vscreen but as FAR_CLIP is an int I can set it with memset so I'm looking for a function to set ints. Anyway this shaved about 10% off execution time so another good optimisation.

PS: It's vacation time so I'm off to Norway until the 28th July :)
See my other reply about your questions on Swizzle()/Unswizzle(), this will help you understand the performance issues you have.

Basically, you want PocketGL to draw directly to PocketFrog's backbuffer. You also want to make sure Swizzle()/Unswizzle() is not called by the Lock()/Unlock() methods. For Lock(), simply specify "bDiscard = true". For the Unlock(), the only way is to configure PocketGL to render to the screen's format (240x320 or 320x240) depending on the hardware orientation. You can obtain this information from Display::GetOrientation().