GLBasic forum

Main forum => GLBasic - en => Topic started by: Crivens on 2011-Oct-29

Title: Loadbmp fps drop
Post by: Crivens on 2011-Oct-29
Ok so I'm doing a quick side project for my wife on my iPod 4th gen retina device.

Part of it involves having a nice non moving backdrop so I used loadbmp with a full 640x960 jpg. The fps went from 60 to 47. I have a load of other sprites onscreen but this one thing takes up 13fps cos when I take it out it's back to 60 again. Using it as a sprite keeps it about the same so I assume loadbmp is doing the same thing in the background. Using png has no impact so assume they are the same thing in memory.

But really 13fps (at least as its limited to 60 on the device) to just show the background?

My next game keeps 60fps on full retina but it uses 3d. Should I use 3D as the background for a pseudo 2d wallpaper? Or perhaps a smaller sprite zoomed? Will test more tomorrow.

Cheers
Title: Re: Loadbmp fps drop
Post by: MrTAToad on 2011-Oct-29
It does sound as though its repeataly re-loading the file, doesn't it - or the picture has to be continually decompressed in each loop...
Title: Re: Loadbmp fps drop
Post by: msx on 2011-Oct-29
I had this problem and the reason was that loaded the bmp continuously
Title: Re: Loadbmp fps drop
Post by: MrTAToad on 2011-Oct-30
In which like it sounds like a buggette
Title: Re: Loadbmp fps drop
Post by: Ian Price on 2011-Oct-30
This goes back quite a long way, actually. I remember talking about this issue a year or more ago.
Title: Re: Loadbmp fps drop
Post by: MrTAToad on 2011-Oct-30
Might be time to make another post about it!
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-30
Ang on. If the loadbmp command is at fault and perhaps is reloading the file every loop then why does loading it as a sprite instead and drawspriting it equal almost exact fps figures?

Cheers
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-30
Grief. I threw pretty much everything at it. Everything from polyvector to 3D. I used 256 colour images instead of 24bit, lower res images zoomed up, several images split and drawn to make one big image, the lot pretty much. I found LOADBMP was the slowest, loading a sprite and pasting that every loop was very slightly faster, zooming a lower res sprite was about the same, 256 col made no difference (assume all the same in memory then), and 3D was the fastest coming out at about 50fps (so about 3-4 FPS better). But still, to just fill up a retina sized display it takes at least between 15 and 10fps? Crikey.

It seems though that it all depends on whats in the image. The one I had was brushed metal which is a lot of changing colours. My game that still runs at 60fps has a *lot* of black bits between pixels. In the end I went with 3 grey drawrects (needs to have darkened grey borders each side) and a nice big logo in the middle with not that many colours. FPS went right up again.

Cheers
Title: Re: Loadbmp fps drop
Post by: MrTAToad on 2011-Oct-30
Quote from: Crivens on 2011-Oct-30
Ang on. If the loadbmp command is at fault and perhaps is reloading the file every loop then why does loading it as a sprite instead and drawspriting it equal almost exact fps figures?

Cheers
I would be surprised if that is the case - unless the bitmap format is different to the screen or you are using very high resolutions.
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-30
So would I. I thought you mentioned it about though?

Cheers
Title: Re: Loadbmp fps drop
Post by: MrTAToad on 2011-Oct-30
Yes, its a possibility - the other, of course, is stretching to the screen size ...
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-30
I did that. Even with a lot smaller sized sprite zoomed to fit the screen I'm getting the same 13-14FPS drop.

Weirdly I started using a lot simpler wallpaper (big chunks of black and white sections) and the FPS went back to 60. Nice. Victory! After all the original wallpaper was quite detailed (brushed metal). So fair enough I left it at that. I added a few bits of code and a bit later compiled for the retina ipod again. And the FPS was back at 46. Eh?.... So I started hacking away at the changed code (WinMerge) and seriously I cannot see how it is now down to 46 again. The code I changed can be flipped in and out and there is no change. Get rid of the wallpaper (as a sprite rather than loadbmp) and it's back to 60FPS. Confused...

Cheers
Title: Re: Loadbmp fps drop
Post by: ampos on 2011-Oct-30
if !you aee going to draw the background each frame, perhaps it coild help to disable "clear backbuffer"...
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-31
Ok, sounds very interesting, how do I do that?

Cheers
Title: Re: Loadbmp fps drop
Post by: ampos on 2011-Oct-31
Clearscreen -1
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-31
Ah yes rings a bell. Hmm, gives me an idea for something else too... Thanks Ampos that could really help!

Cheers
Title: Re: Loadbmp fps drop
Post by: Kitty Hello on 2011-Oct-31
loadbmp is done once at the start of a program. The showscreen will use the loaded image later for updating the back buffer.
Internally it just does a DRAWSPRITE after the showscreen. The image format makes no difference. It's all converted to a BGRA 8888 texture internally.
Title: Re: Loadbmp fps drop
Post by: ampos on 2011-Oct-31
So LOADBMP "back.png" is the same as

Code (glbasic) Select
loadsprite "back.png",0
MAINLOOP
   drawsprite 0,0,0
   your_code_here
   showscreen()
ENDLOOP
   


Interesting.
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-31
I assumed it was. Although over the weekend doing the exact same code as you just posted gained on average about 1fps over the loadbmp command. Strange.

I still don't get how my recovered FPS went away again with almost identical code. Thought I had the answer with "the more complicated the picture the slower the update will be", but has gone back to 46FPS. Hmmm. Perhaps a temp glitch that gave me 60fps on retina... Although that doesn't explain why my game runs at 60fps on retina with a full whack 3D object covering the whole screen. But it does have lots of black in it...

Possibly I can use clearscreen -1 and then only paste the part of the image that was drawn over. It's *always* the center section, and a quick test yesterday showed it gain FPS the more of the wallpaper sprite I kept off the screen (5FPS gain when the full image was half off the screen for example or when I used a 3D object and it was small on the screen and therefore was only showing "half" of it's full self). Interestingly 3D gave me a couple of FPS points so I might revert to that too.

Cheers
Title: Re: Loadbmp fps drop
Post by: Kitty Hello on 2011-Oct-31
add a clearscreen -1 after the loadsprite, then it's the same.

Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-31
Hmm. So how come my DRAWSPRITE example was 1FPS faster than the LOADBMP one? And that was without the clearscreen -1 code.

Cheers
Title: Re: Loadbmp fps drop
Post by: Qube on 2011-Oct-31
Quote
add a clearscreen -1 after the loadsprite, then it's the same.
Really? - I only ask as when doing 2D games I found that method really dragged down the FPS but just using the command "LOADBMP" brought FPS up to 60 again. Huh! must of been doing something silly if that's the case.
Title: Re: Loadbmp fps drop
Post by: Crivens on 2011-Oct-31
Nice one Ampos. Use clearscreen -1 has put it between 70 and 80FPS now. Much better :) Because I always draw the full background every showscreen (like LOADBMP does) then I have nothing to worry about :) Out of interest I wonder why LOADBMP doesn't do the same if it literally uses clearscreen -1 like Gernot said?

Cheers