From 1ce5f6dc78e4c1636b89338bd428c2b6830b9189 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 12 Jan 2014 19:47:46 +0100 Subject: Workaround for slow HW rendering GLJPanel thinks it is a great idea to use glReadPixels. The Intel i965 DRI driver thinks otherwise and does no get more than 2 FPS on a i5-460M CPU (HD Graphics). With Mesa software rendering (LIBGL_ALWAYS_SOFTWARE=1), the performance gets stuck on 20 FPS or something. Unfortunately, the software renderer crashes since Mesa 10[1]. This workaround improves performance by replacing GLJPanel by GLCanvas as mentioned in the Jogamp wiki[2]. FPS now caps on 30 (but this can be bumped to 42 by changing Base.FPS to 60). [1]: https://bugs.freedesktop.org/show_bug.cgi?id=72926 [2]: http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing --- src/robotrace/Base.java | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/robotrace/Base.java b/src/robotrace/Base.java index 0f67ce6..e083afd 100644 --- a/src/robotrace/Base.java +++ b/src/robotrace/Base.java @@ -4,6 +4,7 @@ import com.jogamp.opengl.util.FPSAnimator; import com.jogamp.opengl.util.gl2.GLUT; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureIO; +import java.awt.BorderLayout; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; @@ -20,6 +21,7 @@ import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; import javax.media.opengl.awt.GLJPanel; import javax.media.opengl.glu.GLU; import javax.swing.UIManager; @@ -107,21 +109,26 @@ abstract public class Base { // Redirect OpenGL listener to the abstract render functions. GLJPanel glPanel = (GLJPanel) frame.glPanel; - glPanel.addGLEventListener(new GLEventDelegate()); + + // HACK: get better performance + GLCanvas glCanvas = new GLCanvas(); + frame.remove(glPanel); + frame.getContentPane().add(glCanvas, BorderLayout.CENTER); + glCanvas.addGLEventListener(new GLEventDelegate()); // Attach mouse and keyboard listeners. GLListener listener = new GLListener(); - glPanel.addMouseListener(listener); - glPanel.addMouseMotionListener(listener); - glPanel.addMouseWheelListener(listener); - glPanel.addKeyListener(listener); - glPanel.setFocusable(true); - glPanel.requestFocusInWindow(); - + glCanvas.addMouseListener(listener); + glCanvas.addMouseMotionListener(listener); + glCanvas.addMouseWheelListener(listener); + glCanvas.addKeyListener(listener); + glCanvas.setFocusable(true); + glCanvas.requestFocusInWindow(); + // Attach animator to OpenGL panel and begin refresh // at the specified number of frames per second. final FPSAnimator animator = - new FPSAnimator((GLJPanel) frame.glPanel, FPS, true); + new FPSAnimator(glCanvas, FPS, true); animator.setIgnoreExceptions(false); animator.setPrintExceptions(true); -- cgit v1.2.1