×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Gdansk, Poland
    Posts
    139

    stretching an image

    I've got a 3D game that runs too slow ( Nokia 5800 : 9FPS ). Currently I am just painting directly to the screen. I am willing to trade some quality for performance.

    How about rendering to an smaller offscreen image ( I can render to a (scrWidth/2,scrHeight/2) image at 14 FPS which is acceptable ) ,stretching it and painting that to the screen?

    My problem is that I don't know how to efficiently stretch the image. Any tips?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: stretching an image

    My experience is that doubling the size of an image in real-time yields a massive hit in frame rate. My colleague experimented with this for supporting those few Nokia devices with screens 352x416 (by using a 176x208 version of a (2D) game, and doubling up), but the performance hit was too much.

    It's easy enough to do, simply using getRGB() to acquire the pixels as an int[], then copying the pixels to a larger array and using drawRGB() to paint the larger array onto the screen.

    (Possibly, using the Nokia API for this might be faster, if you can use a native pixel format.)

    The other technique is to use the 3D API to do it, but for us that proved even slower.

    Would be interested to know what results you get, if you feel like experimenting.

    Graham.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Gdansk, Poland
    Posts
    139

    Re: stretching an image

    I will experiment, although I am not holding my breath.

    There is something fishy with implementation of the M3G on S60 5th Edition phones. As I said before, on Nokia 3120 ( 240x320 ) the game runs at 21-22 FPS; it runs at 17-25 FPS on numerous S40 and S60 3rd edition phones I've tried it on.

    On all S60 5th it runs at around 8-9 FPS. More: amazingly, rendering to 320x180 (which is scrWidth/2, scrHeight/2) results in 14 FPS --> only 2/3 of the 3120 framerate!

    If I strip all textures and render to 640x360: 14 FPS

    And here comes the best part: if I comment out all Graphics.render() calls, so the paint() routine only bindsTarget(), releasesTarget() and does some internal computations to update the scene - but does not render anything 3D to the screen- 20 FPS, still slower than on 3120...

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: stretching an image

    No, I tried holding my breath, and it didn't help. I just turned a disturbing shade of blue, and passed out. There was no increase in performance of the code.

    When you paint to your 320x180 buffer, are you still binding and releasing on each paint() cycle, or just once? You need to do it every time when painting to the paint()'s Graphics argument, because it's a different object each time. But the buffer can have one, constant Graphics context. I have no idea how slow bindTarget() is, but might be an easy thing to experiment with, now that you have the code painting to a buffer.

    I'm afraid I don't have good data for S60-5th. It may be that something you are doing happens to be very inefficient on that implementation, though I have no idea what that might be.

    Lesson is: Series 40 is really good.

    Graham.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Location
    Gdansk, Poland
    Posts
    139

    Re: stretching an image

    The stretching does not give any speedup, only visibly lowers the quality. So forget that.

    However I did manage to increase the FPS to about 12.5-13.0 which is almost playable.

    1) I was using GameCanvas - turns out on S60 5th, it's 'flushGraphics()' routine takes 45 ms which alone limits the framerate to 1000/45 ~ 22 FPS. Flushing only part of the screen makes no measurable difference. On S40 and S60 3rd the GameCanvas and flushGraphics(), at least in my case, are much less of a bottleneck. Converting to pure Canvas shaved off some 40ms/paint cycle and got the FPS up to about 12.

    2) S60 5th also seems to be baaad with context switches. During play, every 1/10 of a second , I used to display current time ( the game is a 'do something as fast as you can' kind of thing ) For this I have a Thread which sleeps for 100ms and updates some variables. This turns out to completely kill graphics performance in one part of the game. Now I display an update only once a second and the part is suddenly playable.

    Again, that is not a problem on S40 and S60 3rd.


    Finally now it's the 3D rendering that dominates the execution time of the paint() routine.

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: stretching an image

    Interesting.

    I would certainly recommend you minimize the number of Threads, preferably no more than one. You might need additional Threads in the short term, while loading resources, for example, but during game execution one should be enough. See my recommended sample game structure, in which all updates are performed in a single thread. Too many threads can cause the event-thread to have fewer opportunities to run (more competition), leading to the game being unresponsive to input.

    Also, yes, always develop with Canvas, not GameCanvas. It's simpler, and this is usually better. Also, you find spurious problems that on some devices occur only with one or the other... switching from Canvas to GameCanvas is easy, but switching back is harder. GameCanvas can also take more memory (for it's buffer), making porting to lower-memory devices more difficult.

    Thanks for sharing your results!

    Cheers,
    Graham.

Similar Threads

  1. --- ???save image problem??? ---
    By ferenn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2007-10-01, 14:33
  2. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  3. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  4. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×