Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  What makes Java2D slow and LWJGL fast?  (Read 2800 times)
0 Members and 1 Guest are viewing this topic.
Offline Zabot

Innocent Bystander





« Posted 2013-07-22 01:19:43 »

I'm the kind of person that likes to understand what makes things tick, evidenced by the drawer of torn apart electronics under my bed.  So anyway, what is it that makes Java2D such a slow way of rendering?  And conversely, what makes other libraries more efficient?  And why can't I do directly what any libraries do, so I can cut out the middle man and make things as streamlined as possible for the specific purpose?
Offline Troncoso

JGO Coder


Medals: 20



« Reply #1 - Posted 2013-07-22 01:51:54 »

Java2D uses the CPU to draw, LWGJL uses OpenGL, which utilizes the graphics card.

And, you can do directly what the libraries do. Someone had to right them, didn't they?
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #2 - Posted 2013-07-22 03:25:04 »

In order to abstract the nature of drawing graphics the Java2D API hides all the guts of OpenGL and the graphics pipeline.  So instead of working with vertex arrays, VBOs, textures, etc. you can happily work with lines, pixels, strings, and images.

Java2D will attempt to optimize things at first (e.g. images will be managed initially i.e. stored in the graphics card's memory).  But you can't have endless arbitrary images and perform pixel manipulations via a high level API before one hits the limits of what a graphics card can handle. Once you do then it's slows-ville (primarily because you're now transferring data between main memory and the graphics card for each frame).  It would be impossible to recover from this without exposing the nuts and bolts of the graphics pipeline which an API can't do without losing its integrity.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2013-07-22 08:14:53 »

Also Java2d places image quality and accuracy at the top of it's priorities - the same code will generate nearly exactly the same image regardless of platform or graphics hardware.

OpenGL allows a certain amount of slack for better performace. For example when you draw a triangle, exactly which pixels along the edge will be filled is not precisely defined. For games this really doesn't matter, as long as it's consistent, so we see j2d being 'slow' because it's worrying about something we don't care about.

This is also why when j2d is using OpenGL under the hood it's still (usually) slower than calling GL directly.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline gimbal

JGO Knight


Medals: 25



« Reply #4 - Posted 2013-07-22 11:18:32 »

Whenever I'm lazy and use Java2D, I limit myself to the following:

- disable hardware acceleration entirely, pure software pipeline
- only use OPAQUE and BITMASK images (createCompatibleImage())

Basically create the situation as it was before Java 6 update 10. Performance is quite stable then as you don't have any difference in behavior across systems and hardware. For my retro game remaking purposes that works just fine. But as soon as you want to do something that games of 20-25 years ago did not do (rotate, scale, alpha blend, whatever), you should immediately forget about Java2D entirely.
Offline JediSange

Innocent Bystander





« Reply #5 - Posted 2013-07-23 00:18:18 »

...But as soon as you want to do something that games of 20-25 years ago did not do (rotate, scale, alpha blend, whatever), you should immediately forget about Java2D entirely.

Curious, what would be an efficient way of accomplishing these things in Java now that Slick has been discontinued?
Offline davedes
« Reply #6 - Posted 2013-07-23 00:19:33 »

JediSange, see LibGDX. Pretty excellent library, much more powerful than Slick, much better optimized, and also ports to a variety of platforms (iOS, Android, WebGL).

http://libgdx.badlogicgames.com/

Offline philfrei
« Reply #7 - Posted 2013-07-23 00:53:26 »

...But as soon as you want to do something that games of 20-25 years ago did not do (rotate, scale, alpha blend, whatever), you should immediately forget about Java2D entirely.

Curious, what would be an efficient way of accomplishing these things in Java now that Slick has been discontinued?

I think this excellent tutorial:http://www.java-gaming.org/topics/java2d-clearing-up-the-air/27506/msg/0/view/topicseen.html#new is exactly what you are looking for, if you want to use Java2D as efficiently as possible.

"It's after the end of the world! Don't you know that yet?"
Offline gouessej
« Reply #8 - Posted 2013-07-24 18:38:50 »

Actually, there have been several attempts of creating high level libraries with the same design than Java2D but with a better hardware acceleration, for example a part of GTGE simulates Java2D.

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

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!