Hello Guest

SWT GLCanvas slow compared to AWTGLCanvas for me

  • 0 Replies
  • 4682 Views
SWT GLCanvas slow compared to AWTGLCanvas for me
« on: November 12, 2010, 21:59:40 »
Hi, I have question about how to properly(and efficiently) call OpenGL drwawing from outside SWT User Interface thread. I have a program, which I started to port from AWT to SWT. On AWT version I'm calling:
Code: [Select]
refresh = new Thread(){
public void run() {
while(true){
if (isVisible()) awtglcanvas.repaint();
                                         Display.sync(fps);
}
}
};
refresh.setDaemon(true);
refresh.start();
And I was able to run it smoothly without any significant CPU overload for even fps>100.
In SWT I do:
(initialization)
Code: [Select]
this.datagl = new GLData ();
datagl.doubleBuffer = true;
swtglcanvas = new GLCanvas(shell, SWT.NONE, datagl);
swtglcanvas.setBounds(0,0,x,y);
swtglcanvas.setCurrent();
try {
GLContext.useContext(swtglcanvas);
} catch(LWJGLException e) { e.printStackTrace(); }
and displaying in non User Interface Thread(similary):
Code: [Select]
Thread refresh = new Thread(){
public void run() {
while(swt_display.isDisposed()==false){
order_of_draw();
        org.lwjgl.opengl.Display.sync(fps);
}
}
};
refresh.setDaemon(true);
refresh.start();
,where "order_of_draw();" call the following:
Code: [Select]
public void order_of_draw(){
swt_display.asyncExec(new Runnable(){
public void run() {
                                        someLWJGLheavyDrawing();
swtglcanvas.swapBuffers();
}
}
});
}
However, this latter consume much of CPU at similar fps compared to AWT version(>80% cpu load, compared to ~1% in AWTGLCanvas at fps=60. At 10 fps it is ~20% cpu load versus ~0% cpu load). There must be something I do wrong, but what it is? LWJGL drawing code is identical on both version. Thanks in advance for any replies and sorry for my english.