Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  OpenGL VM flag degrade performance on Java2D???  (Read 1440 times)
0 Members and 1 Guest are viewing this topic.
Offline alesky

Junior Member


Medals: 2


mmm....


« Posted 2013-01-07 10:51:20 »

Quote
And without the "OpenGL" VM flag?

my situation was to have a game implemented without the flag for the OpenGL.
my framework (done in java2D) is completely based on the BufferedImageOp to draw on the fly effect!

how my frameworks works is this just create to any cycle the next immage and then the the drawable:

1  
2  
dbImage = JPanel.createImage(pWidth, pHeight); // create the double buffer immage
dbg = (Graphics2D) dbImage.getGraphics();


after that it is pass to the rendering that are 2D sprite based on the bufferedImmage
internalRenderGame(dbg);

any sprite before to be render on the dbg ( that i s the Graphics2D) is passed to a chain of effect that execute specific effect implemented as BufferedImageOp brightness, and transparence or affine trasfomration for scale and rotation

1  
2  
3  
//filtersToApplyare all the filter ot use: can be any, one of this or all -->brightness, transparence,scale and rotation
BufferedImage filtered = EffectManager.getInstance().chain(filtersToApply,image, position, size, color);
dbg.drawImage(filtered, (int)(position.getPosX() - filtered.getWidth()/2), (int)(position.getPosY() - size.getHeigh()/2), null);



in the end finally draw the final immage with all the sprite and background painted over
1  
2  
g = (Graphics2D) gamePanel.getGraphics();
g.drawImage(doFinalEffect(dbImage), 0, 0,pWidth,pHeight, null);

but before is possible to pass the final image (that is the immage with the background and all the sprites) again to a chain of effect (that is implemented has before as BufferedImageOp  brightness to make obscuration of all the immage)



ALL this story to explane that it is very easy nothing complex, and when i have activated the "OpenGL" VM flag -Dsun.java2d.opengl=True, my application is start to be very slow!!! it become a disaster, lost 30% of the frames!!!!
i would like to understand why, or at list to understand how to analyze
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #1 - Posted 2013-01-07 10:58:47 »

Its likely the Direct3d backend is just faster on your pc (that is if you are on Windows).

Also "-Dsun.java2d.opengl=True" is a bit of a debug mode and will give you verbose console output, highly unlikely but "-Dsun.java2d.opengl=true" maybe a tiny bit faster.

btw which graphics card are you on?
Offline alesky

Junior Member


Medals: 2


mmm....


« Reply #2 - Posted 2013-01-07 11:30:37 »

the output in the console is almost nothing, so modifying it din't recognize any effect

i'm working on my laptop and the graphics card is integrated on it:
Intel(R) HD Graphics Family

testing this card with the OpenGl Extensions viewer 3.0 i'm able to support with this card operation
openGL 2.2
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline The-Next

Senior Member


Medals: 5
Projects: 1



« Reply #3 - Posted 2013-01-07 18:07:06 »

Hi alesky!

I've been working a little bit with an intel HD3000 with Java2D in my laptop (JDK 7 and Windows 7) and:

I tried both flags: for using direct3D and openGL pipeline with:

    System.setProperty("sun.java2d.opengl", "True"); or    System.setProperty("sun.java2d.d3d", "True");

And I get much better performance with direct3D pipeline.

Also, I have to say that, for some reason, the global performance of intelHD with java2D is quite bad, maybe is a driver issue. I have also a Nvidia GT520 in the laptop. In theory Nvidia GPU is not much better than the intel HD, but the performance in java2D is much better, maybe 5 times faster. Also, sometimes, the intel behaves weirdly. The performance suddently drops when I add some extra pictures.

-------------------------------------------

About the code you show. Several months ago a did many microbenchs in order to get the best performance with java2D, but I don't remember all the details.

You use a jPanel for drawing the stuff?. Did you tried to use a BufferStrategy over a canvas instead? As far I remember it gives better performance.

Ok, then you apply a set of affineTransforms, right?, so you create an intermediate BufferedImage called "filtered" with all the changes. Do you tried directly to draw the image to dbg without creating that "filtered" image?

something like this:

dbg.scale(scaleX,scaleY);
dbg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,desired_alpha));
dbg.drawImage(image,brightness_operation,posX,posY);



also, are you creating a new image each cycle?

"dbImage = JPanel.createImage(pWidth, pHeight); // create the double buffer immage"

Why don't you reuse it, I found that the command clearRect is really efficient for clearing an image, is even more efficient than fillRect.

//-----------------------------

I would not mind to take a look at your full code, I enjoy optimizing Tongue

Cheers.
Offline davedes
« Reply #4 - Posted 2013-01-07 18:11:26 »

Personally I wouldn't rely on that flag - some systems won't support it, others will perform better, and some may even perform worse.

General consensus is: if you need reliable performance, Java2D is the wrong choice. Wink

Offline The-Next

Senior Member


Medals: 5
Projects: 1



« Reply #5 - Posted 2013-01-07 18:18:53 »

Oh, yes! davedes post remind me an important thing. Sometimes Java2D cannot recognize the hardware, so the direct3D pipeline cannot be activated. This happens for example in laptops with nvidia optimus.

You can solve this with the environment variable J2D_D3D_NO_HWCHECK=true, so you deactivate any hardware checking and pipeline can be enabled.

I would love to try java2D in more computers. But yes, it seems that if you go outside standard configurations, weird things can happen. That makes development more thrilling  Grin
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #6 - Posted 2013-01-07 22:08:06 »

Setting flags like that always screams to me "I can determine what Java2D pipeline will run faster on this machine better than Java2D itself can."  Do you think the JVM is picking the wrong pipeline for some reason?
Offline alesky

Junior Member


Medals: 2


mmm....


« Reply #7 - Posted 2013-01-08 00:55:20 »

Next thanks to you
regarding the optimization i want to answer to all your idea just to share our knowledge

firs of all
The chose of the JPanel happen for one specific reason the method JPanel.createImage(pWidth, pHeight)
hire the official link to java doc http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#createImage(java.awt.image.ImageProducer)
this method must be called each time in the cycle, because it manage automatically for you the double buffering strategy
increasing the performance, so for this reason this object is used by double buffering i can not reuse the same object clearing the immage

never tried to do it by canvas, is there a specific method to do it automatically? the old AWT expose something to do it? if exsist let me know i want to try it


Quote
Ok, then you apply a set of affineTransforms, right?, so you create an intermediate BufferedImage called "filtered" with all the changes. Do you tried directly to draw the image to dbg without creating that "filtered" image?

this part of the code is already optimized, the solution applied is this:
every image transformed in the chain of effect is stored in a repository  keeping with it information of the kind of transformation performed over it, so every time that  on a image is required to execute same effect, first of all I look in the repository if that image with that kind of transformation already exists in this case this image is get and reused, other ways a new image with effect is created and saved in the repository.
this make in my case a huge increasing of the performance and aloud to me to work on image modification on the fly
but the back side of this solution is the memory used to store images in the repository

instead regarding this fact (davedes please don't take it personally, but i have to write this)
Quote
General consensus is: if you need reliable performance, Java2D is the wrong choice
the fact that exist technologies that are better of the Java2D is something that also the kids know,
so if i use this specific section of the forum called Java2D, and not OpenGL Development may be ther is a reason what u think?
http://www.java-gaming.org/boards/java-2d/15/view.html

if i can get 1 euro for all the guys that write in this forum,
Quote
General consensus is: if you need reliable performance, Java2D is the wrong choice
i will become one of the most reach person in the word (ok i will open a topic for this  Grin)
 
regarding the real discussion of this topic,
Quote
Setting flags like that always screams to me
me too!!!

i want to try to set the variable J2D_D3D_NO_HWCHECK=true and try to activate the direct3D. i will let to know how it works

Offline The-Next

Senior Member


Medals: 5
Projects: 1



« Reply #8 - Posted 2013-01-08 06:11:05 »

alesky, I show you a skeleton of a canvas ready for drawing anything you want. I use a VolatileImage as a intermediate buffer. I set the same name you used. If you try it, it would be great some result comparison  Cheesy

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  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
public class Zoom_canvas extends Canvas {
   
   
     

    protected BufferStrategy buffer;  //BufferStratrgy
   protected VolatileImage dbImage ; //VolatileImage as intermediate buffer

   

    public Zoom_canvas() {   //constructor
       this.setIgnoreRepaint(true); //we repaint manually
       this.setFocusable(false);

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
        dbImage = gc.createCompatibleVolatileImage(this.getWidth, this.getHeight, Transparency.TRANSLUCENT); //initialize the VolatileImage
   }

    public void dispose() {
        buffer.dispose();
    }

    public void Init() { //call this before starting game loop, it initializes the bufferStrategy
       createBufferStrategy(2);  //double buffering
       buffer = getBufferStrategy();
    }

    public void PerformDraw() {  //public drawing method, call this from your game loop for update image

        Graphics g;
        try {
            g = buffer.getDrawGraphics();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        this.paint((Graphics2D) g);
        g.dispose();

        if (!buffer.contentsLost()) {
            buffer.show();
        }
    }

    private void paint(Graphics2D g) { //real drawing method

        super.paint(g);

        Graphics2D ga = (Graphics2D) dbImage.getGraphics();
        ga.setBackground(new Color(0, 0, 0, 0));
        ga.clearRect(0, 0, dbImage.getWidth(), dbImage.getHeight()); // we clear the intermediate buffer

//===============================        
//... TO DO, ADD dome drawing here using "ga"!!!
//===============================
       ga.dispose();

        g.drawImage(dbImage, 0, 0, null);
        g.dispose();
    }
}
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.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!