summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2014-01-12 19:47:46 +0100
committerPeter Wu <lekensteyn@gmail.com>2014-01-12 19:47:46 +0100
commit1ce5f6dc78e4c1636b89338bd428c2b6830b9189 (patch)
tree459131fccead48232a825c9cbf99648af69182b1
parentcc500dd153608caa4c6ada41ee8a2906b714f1fb (diff)
download2iv60-robots-1ce5f6dc78e4c1636b89338bd428c2b6830b9189.tar.gz
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
-rw-r--r--src/robotrace/Base.java25
1 files 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);