Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bottleneck Drawing Large Image  (Read 3723 times)
0 Members and 1 Guest are viewing this topic.
Offline Tetragrammaton

Junior Newbie





« Posted 2008-05-29 01:46:00 »

I'm a Java game newbie, and I've got a bottleneck that I just can't understand. I've got an otherwise-finished game that's got unacceptable performance, and I've finally figured out the source of the problem.

I'm working with an 800x600 frame. When I draw a single 800x600 image over the whole thing (my background image), I get 20 FPS. But, if I take a 200x200 image and draw it 12 times in a grid, I get 50-100 FPS. It seems to me that there's the same amount of image data getting pushed to the buffer; why, then, does this screw up so badly?

I haven't tested this particular issue on Windows, but the slow version of my game runs even slower on there than on my Linux machine.

Examples of both the single image and the grid can be found here: http://forum.java.sun.com/thread.jspa?threadID=5299987
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2008-05-29 03:48:53 »

Use a maximum size of 2^16 (65536) pixels. E.g. 256x256.

弾幕 ☆ @mahonnaiseblog
Offline Tetragrammaton

Junior Newbie





« Reply #2 - Posted 2008-05-29 06:44:48 »

Do I have to tile then? Is scaling safe?
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2008-05-29 07:03:33 »

Tile it. Scaling isn't that fast.

If you're using several background images it might be a good idea to create some kind of Background class, which splits the background image into tiles (once - in the constructor) and draws all of the tiles in a draw() or render() method.

弾幕 ☆ @mahonnaiseblog
Offline Tetragrammaton

Junior Newbie





« Reply #4 - Posted 2008-05-29 07:27:44 »

Thanks for the help.

Honestly, I'm surprised that this doesn't seem to be an especially common issue. I'd expect "background drawing" to be so standard a task that Sun would provide a method to take care of it for us.

EDIT: Actually, this didn't give the expected performance boost. Tiling with separate 200x200 images just made it slower (as did tiling the same image, oddly enough). Commenting out these drawImage calls and replacing them with a fillRect to clear the image sends the FPS skyrocketing, still.

Any other ideas, or experiments to try?
Offline Wildern

Junior Member





« Reply #5 - Posted 2008-05-29 21:47:07 »

Any chance there is transparency in your image (ie: .png) ?
Offline Tetragrammaton

Junior Newbie





« Reply #6 - Posted 2008-05-30 00:05:18 »

There's no alpha channel in the .png and the BufferedImage type is RGB.

I really don't get this. The example I linked to in the first post shows the exact same sort of tiling, and it's fast. What's changed?
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #7 - Posted 2008-05-30 00:27:10 »

What is your OS, Java version, video board?

Dmitri
Offline Tetragrammaton

Junior Newbie





« Reply #8 - Posted 2008-05-30 03:18:04 »

Ubuntu Hardy Heron
Java 1.6
Some low-grade Quadro
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #9 - Posted 2008-05-30 06:43:46 »


Thanks for the data.

Could you please run your app with -Dsun.java2d.trace=count (let it run for a few seconds, then quit), with tiling and w/o it and post the output?

Dmitri
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 10
Projects: 2


Make it work; make it better.


« Reply #10 - Posted 2008-05-30 14:28:34 »

Check to make sure that your images are in the same format as your screen.  Otherwise you will lose performance as well.  To check this easily, follow these steps.

1.  Load your images.
2.  Create images that are compatable with the screen using GraphicsConfiguration.createCompatibleImage(int width,
 int height)
3. Copy your loaded images to the screen compatable ones created in step 2.
4. Use the screen compatable images created in step 2 to draw your images.

Offline Tetragrammaton

Junior Newbie





« Reply #11 - Posted 2008-05-30 17:55:37 »

Thanks for the data.

Could you please run your app with -Dsun.java2d.trace=count (let it run for a few seconds, then quit), with tiling and w/o it and post the output?

Dmitri


Of course. My game loads to a menu screen. On both runs I tried to rapidly get into the main game rendering section (with the background or tiles) and then let it run for several more seconds.

First, with the single large background graphic:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
354 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntArgb)
17543 calls to sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
354 calls to sun.java2d.loops.MaskBlit$General::MaskBlit(Any, SrcOverNoEa, IntArgb)
2 calls to sun.java2d.x11.X11PMBlitLoops::Blit("Integer RGB Pixmap", SrcNoEa, "Integer RGB Pixmap")
65905 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
354 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(Any, SrcOverNoEa, IntArgb)
184 calls to sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
57398 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(Any, SrcOverNoEa, IntRgb)
57398 calls to sun.java2d.loops.MaskBlit$General::MaskBlit(Any, SrcOverNoEa, IntRgb)
6 calls to X11FillRect
58673 calls to sun.java2d.loops.OpaqueCopyAnyToArgb::Blit(Any, SrcNoEa, IntArgb)
8507 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
921 calls to sun.java2d.loops.TransformHelper::TransformHelper(IntArgb, SrcNoEa, IntArgbPre)
267599 total calls to 13 different primitives


Second, tiling a single 200x200 image 12 times:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
40429 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
34754 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(Any, SrcOverNoEa, IntRgb)
135 calls to sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntArgb)
5675 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
34754 calls to sun.java2d.loops.MaskBlit$General::MaskBlit(Any, SrcOverNoEa, IntRgb)
2 calls to sun.java2d.x11.X11PMBlitLoops::Blit("Integer RGB Pixmap", SrcNoEa, "Integer RGB Pixmap")
135 calls to sun.java2d.loops.Blit$GeneralMaskBlit::Blit(Any, SrcOverNoEa, IntArgb)
35960 calls to sun.java2d.loops.OpaqueCopyAnyToArgb::Blit(Any, SrcNoEa, IntArgb)
6 calls to X11FillRect
1071 calls to sun.java2d.loops.TransformHelper::TransformHelper(IntArgb, SrcNoEa, IntArgbPre)
173 calls to sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
11638 calls to sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
135 calls to sun.java2d.loops.MaskBlit$General::MaskBlit(Any, SrcOverNoEa, IntArgb)
Offline Tetragrammaton

Junior Newbie





« Reply #12 - Posted 2008-05-30 18:08:11 »

Problem fixed!

It turns out that these images weren't accelerated because they were directly created from ImageIO.read. Images created with a BufferedImage constructor are managed images, but those taken directly from ImageIO.read are not.

By using a BufferedImage constructor and then using graphics.drawImage(ImageIO.read(---)), I was able to get my performance back to where it should be.

Thanks for everyone's help!
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #13 - Posted 2008-05-30 18:20:10 »

I believe the issue with some images read with ImageII not being accelerated
were resolved in 6u10 (I don't remember if they were forward ported to Java7
or openjdk6).

Dmitri
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #14 - Posted 2008-05-30 18:27:53 »

I believe the issue with some images read with ImageIO not being accelerated
were resolved in 6u10 (I don't remember if they were forward ported to Java7
or openjdk6).

Dmitri
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (34 views)
2013-05-17 21:29:12

alaslipknot (42 views)
2013-05-16 21:24:48

gouessej (72 views)
2013-05-16 00:53:38

gouessej (71 views)
2013-05-16 00:17:58

theagentd (79 views)
2013-05-15 15:01:13

theagentd (74 views)
2013-05-15 15:00:54

StreetDoggy (116 views)
2013-05-14 15:56:26

kutucuk (139 views)
2013-05-12 17:10:36

kutucuk (140 views)
2013-05-12 15:36:09

UnluckyDevil (148 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.115 seconds with 21 queries.