K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Posted
2004-10-26 07:23:00 » |
|
No matter what I do my buffered images are not accelerated.
Here is how I get my information:
System.out.println( img.getCapabilities(img.createGraphics().getDeviceConfiguration()).isAccelerated() );
It returns false.
167fps when I display one image on the screen. 2500fps without any images on screen.
I've tried at least 3-5 methods of creating the images, none of them are accelerated.
I've read several articles explaining that creating a BI from a constructor makes it a managed image.
BufferedImage b = ImageIO.read(new File(szI)); img = new BufferedImage( b.getWidth(), b.getHeight(), BufferedImage.TYPE_INT_ARGB );
Here is my code and it is not accelerated like it is said to be. Given that the code will not display the intended image but that can be fixed.
My problem is that managed images don't work as advertised.
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
princec
|
 |
«
Reply #1 - Posted
2004-10-26 07:42:12 » |
|
I didn't think BIs were ever accelerated. Cas 
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #2 - Posted
2004-10-26 08:26:18 » |
|
I didn't think BIs were ever accelerated. Cas  They are in 1.5 according to docs.
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
Games published by our own members! Check 'em out!
|
|
kevglass
|
 |
«
Reply #3 - Posted
2004-10-26 08:51:52 » |
|
Where does it say that? I thought the deal was that they'd "try their damndest to accelerate managed images".
Also I was under the impression that ImageIO.read() was going to attempt to return already accelerated images (which presumably would be a special subclass of buffered image or something?)
What you've done is copied (well not yet) the return of ImageIO into a new buffered image. I'd hope we still have the ability to create a BufferedImage that isn't accelerated (I might not want to use video mem up!) and hence the default constructor would create a non-accelerated image.
Could you point me in the direction of the articles and documentation you mention?
Kev
|
|
|
|
|
princec
|
 |
«
Reply #5 - Posted
2004-10-26 09:25:07 » |
|
You're using ARGB format which I seem to recall requires a special flag to accelerate (transAccel or something like that). Cas 
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #6 - Posted
2004-10-26 10:20:31 » |
|
I'm using it: System.setProperty( "sun.java2d.translaccel", "true" );
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
oNyx
|
 |
«
Reply #7 - Posted
2004-10-26 10:35:58 » |
|
You also need: System.setProperty("sun.java2d.accthreshold", "0");
if you want to have it accelerated asap (and not after some drawing... that getting accelerated is somewhat "lazy" in order to prevent temporary junk images from getting accelerated).
And there's also: System.setProperty("sun.java2d.ddforcevram", "true");
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #8 - Posted
2004-10-26 10:46:58 » |
|
Neither setting changes my frame rate. They are enabled by default anyhow.
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
Malohkan
|
 |
«
Reply #9 - Posted
2004-10-26 17:01:25 » |
|
Here's something I just discovered. When I start Rimscape fullscreen, the opening sequence has these results: with: System.setProperty("sun.java2d.accthreshold", "0"); FPS = 20 with System.setProperty("sun.java2d.accthreshold", "1"); FPS = 110 Pretty big difference  I think the culprit is my AffineTransform rotating all the ships and projectiles and such flying around, and every time it creates one, it tries to put it into VRAM, which is stupid because that particular rotation will never be drawn again, and even if it is, I doubt it's smart enough to reuse it. Try messing with that! EDIT: Just tried this test in Windowed mode: with: System.setProperty("sun.java2d.accthreshold", "0"); FPS = 80-86 with System.setProperty("sun.java2d.accthreshold", "1"); FPS = 100-110
|
|
|
|
Games published by our own members! Check 'em out!
|
|
trembovetski
|
 |
«
Reply #10 - Posted
2004-10-26 18:46:35 » |
|
Transformations are not accelerated in 1.5 (unless you're using the opengl pipeline). So if you're rendering an image using a transform (other than translation), the operation will be done by the software loops.
|
|
|
|
Malohkan
|
 |
«
Reply #11 - Posted
2004-10-26 20:00:22 » |
|
yeah, so the improvement I found was a result of not forcing the game to move everything to VRAM upon creation only to pull it right back out in order to do the software transformation. Instead I just never put it in VRAM since it doesn't help.
|
|
|
|
oNyx
|
 |
«
Reply #12 - Posted
2004-10-26 21:33:38 » |
|
>Instead I just never put it in VRAM since it doesn't help
You do. But not asap (and temporary "junk" images won't end up there too).
|
|
|
|
Malohkan
|
 |
«
Reply #13 - Posted
2004-10-26 23:44:43 » |
|
Well whatever is happening, it's much much faster now 
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #14 - Posted
2004-10-27 06:50:01 » |
|
I've done both. No change in performance.
C#.NET seems to accelerate images nicely. Why can't Java?
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
Mikael Grev
Junior Devvie  
Appearance is everything!
|
 |
«
Reply #15 - Posted
2004-10-27 07:43:01 » |
|
I have no trouble at all getting accelerated BI:s on my setup (1.5). Might it be the Gfx card, drivers, settings in windows or something else that is in your way. I use ATI cards, all kinds, dual screen and all. big res. No trouble. Though the PNG images from ImageIO is about 8x slower than unaccelerated (yes) ones. That is because of some transparency data incompatibility or something. They know about it anyway, so it will be a problem no more soon.  Cheers, Mikael Grev
|
|
|
|
oNyx
|
 |
«
Reply #16 - Posted
2004-10-27 07:56:42 » |
|
>Why can't Java?
How should we know?
Well, you can try BufferedImage.TRANSLUCENT instead.
like...
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferedImage bi = gc.createCompatibleImage(w,h,Transparency.TRANSLUCENT); Graphics2D g2d = (Graphics2D)bi.getGraphics(); g2d.setComposite(AlphaComposite.Src); copy.. dispose... yadda yadda (you wont need all this with 1.5)
If all fails do a (simple) test case.
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #17 - Posted
2004-10-27 09:48:41 » |
|
How should we know?
Sorry for upsetting you but when you are working on something for hours and come to a problem which takes much longer than needed it tends to frustrate people. Mikael Grev, I have an Ati Radeon 9700 Pro with an A64 3000+ and 1GB DDR400 RAM and an NForce 3 mobo.
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
oNyx
|
 |
«
Reply #18 - Posted
2004-10-27 12:31:27 » |
|
>Sorry for upsetting you You didn't  It's just... we can't know why it isn't working, because we don't have something specific to look at (a small test case). For example Cas suggested to set the transaccel flag to true and you said *then* that you already did that. Y'know... it kinda leads to a thread with 10 pages and no answer  If you want to get the answer you're looking for asap you should tell everything which is relevant in this order: -what you want to do (the "goal") -what you tried (the "way" - in detail [simple sample case preferred]) -what happened and what you've expected -additional "bonus points"/related/random questions here This way the reader can see what you want to do, how you tried to do it and what didn't worked. Thanks to that order he/she will be able pretty fast if he/she might be able to answer the question, because it's explained at the beginning. Reading across that part, which explains how you tried it, allows the reader to check common pitfalls and the like. And at the end there is a kind of summary, which can be used for comparison. Trust me... you'll get a usable answer faster this way 
|
|
|
|
Mikael Grev
Junior Devvie  
Appearance is everything!
|
 |
«
Reply #19 - Posted
2004-10-27 12:36:55 » |
|
Have you got the latest driver for the Gfx card? Installed DirectX 9? Check that you have full acceleration in windows turned on. run "dxdiag" and check if windows reports any problems.
Cheers, Mikael Grev
|
|
|
|
|
princec
|
 |
«
Reply #21 - Posted
2004-10-28 19:51:29 » |
|
I'll just, totally unhelpfully, add at this stage this is why we developed LWJGL :/ Cas 
|
|
|
|
oNyx
|
 |
«
Reply #22 - Posted
2004-10-29 02:30:47 » |
|
The testcase didn't compile right away. After some fixing it compiled and yea it wasn't accelerated at all. After adding thag GraphicsConfiguration stuff (I mentioned that before) it was accelerated after the image was drawn once. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| import java.awt.image.*; import java.awt.*; [...] static BufferedImage img = null; private GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); [...] public Main( int w, int h ) { render = new Renderer(w, h);
try { Image timg = ImageIO.read(new File("4.png")); img=gc.createCompatibleImage(timg.getWidth(null),timg.getHeight(null),Transparency.OPAQUE); Graphics2D g2d=(Graphics2D)img.getGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.drawImage(timg,0,0,null); g2d.dispose(); } catch ( IOException e ) { e.printStackTrace(); } } [...]
acc = img.getCapabilities(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()).isAccelerated(); [...] |
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #23 - Posted
2004-10-29 06:18:04 » |
|
THANK YOU oNyx.  Thanks, it works now. I'm going to analyse your code so I can understand what you've done compared to what I've done and didn't do.  I love you oNyx
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
kevglass
|
 |
«
Reply #24 - Posted
2004-10-29 06:22:21 » |
|
Aww, isn't appreciation grand.  Kev
|
|
|
|
K.I.L.E.R
Senior Devvie   
Java games rock!
|
 |
«
Reply #25 - Posted
2004-10-29 06:29:19 » |
|
Question, why doesn't Sun auto enable hardware acceleration for transparent images?
Why do I need to enable it via commandline when Sun can force it automatically?
|
Vorax: Is there a name for a "redneck" programmer? Jeff: Unemployed. 
|
|
|
oNyx
|
 |
«
Reply #26 - Posted
2004-10-29 07:02:23 » |
|
>Why do I need to enable it via commandline when Sun can >force it automatically?
Because it doesn't work with all configurations (crappy drivers are to blame). So Sun picked the correct choice... working > fast.
|
|
|
|
|