Author: paperwing
Date: 2012-03-14 12:02:12 -0700 (Wed, 14 Mar 2012)
New Revision: 28535
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MainInputProcessor.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/EdgeShapeDrawer.java
Log:
Attempt at increasing framerate by creating re-usable display lists for
rendering the current set of nodes and edges, which saves performing
calculations for the edges each frame. Noticed small increase in framerate,
should test again with similar implementation for node/edge picking. Added
DebugInputHandler and a dispose method to GraphicsHandler interface.
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -1,10 +1,14 @@
package org.cytoscape.paperwing.internal;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import javax.media.opengl.GL2;
+
import
org.cytoscape.paperwing.internal.coordinator.BirdsEyeCoordinatorProcessor;
import org.cytoscape.paperwing.internal.coordinator.CoordinatorProcessor;
import org.cytoscape.paperwing.internal.coordinator.MainCoordinatorProcessor;
@@ -49,7 +53,12 @@
* detail for nodes or edges that are far away.
*/
private List<ReadOnlyGraphicsProcedure> renderProcedures;
-
+
+ /**
+ * A Map containing rendering procedures that have re-usable display
lists.
+ */
+ Map<Class<? extends ReadOnlyGraphicsProcedure>, Integer>
renderProcedureLists;
+
public BirdsEyeGraphicsHandler() {
// Populate the list of rendering routines employed by this
handler.
@@ -60,6 +69,13 @@
renderProcedures.add(new RenderNodesProcedure());
renderProcedures.add(new RenderArcEdgesProcedure());
renderProcedures.add(new RenderBoundingBoxProcedure());
+
+ // Initialize the dictionary of display lists to be used for
rendering procedures that can be
+ // compiled into a re-usable display list
+ renderProcedureLists = new HashMap<Class<? extends
ReadOnlyGraphicsProcedure>, Integer>();
+
+ renderProcedureLists.put(RenderNodesProcedure.class, null);
+ renderProcedureLists.put(RenderArcEdgesProcedure.class, null);
}
@Override
@@ -78,11 +94,30 @@
// gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION,
// FloatBuffer.wrap(lightPosition));
+ GL2 gl = graphicsData.getGlContext();
+
for (ReadOnlyGraphicsProcedure renderProcedure :
renderProcedures) {
- renderProcedure.execute(graphicsData);
+ // Does this rendering procedure have a re-usable
display list?
+ if
(renderProcedureLists.get(renderProcedure.getClass()) != null) {
+
+ // Is it time to update the display list?
+ if (graphicsData.getUpdateScene() ||
graphicsData.getFramesElapsed() <= 2) {
+
gl.glNewList(renderProcedureLists.get(renderProcedure.getClass()),
GL2.GL_COMPILE_AND_EXECUTE);
+ renderProcedure.execute(graphicsData);
+ gl.glEndList();
+
+ graphicsData.setUpdateScene(false);
+ // If not, call the current list
+ } else {
+
gl.glCallList(renderProcedureLists.get(renderProcedure.getClass()));
+ }
+ } else {
+ renderProcedure.execute(graphicsData);
+ }
+
+// renderProcedure.execute(graphicsData);
}
-
// System.out.println(graphicsData.getFramesElapsed());
}
@@ -146,10 +181,23 @@
@Override
public void initializeGraphicsProcedures(GraphicsData graphicsData) {
+ GL2 gl = graphicsData.getGlContext();
+
for (ReadOnlyGraphicsProcedure renderProcedure :
renderProcedures) {
renderProcedure.initialize(graphicsData);
}
+
+ for (Entry<Class<? extends ReadOnlyGraphicsProcedure>, Integer>
entry : renderProcedureLists.entrySet()) {
+ renderProcedureLists.put(entry.getKey(),
gl.glGenLists(1));
+ }
}
-
+ @Override
+ public void dispose(GraphicsData graphicsData) {
+ GL2 gl = graphicsData.getGlContext();
+
+ for (Integer list : renderProcedureLists.values()) {
+ gl.glDeleteLists(list, 1);
+ }
+ }
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -188,6 +188,9 @@
@Override
public void dispose(GLAutoDrawable autoDrawable) {
coordinatorProcessor.unlinkCoordinator(coordinator);
+
+ GL2 gl = autoDrawable.getGL().getGL2();
+ gl.glDeleteLists(graphicsData.getSceneList(), 1);
}
/** Initialize the Graphics object, performing certain
@@ -225,6 +228,8 @@
handler.setupLighting(graphicsData);
shapePickingProcessor.initialize(graphicsData);
+
+ graphicsData.setSceneList(gl.glGenLists(1));
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/GraphicsHandler.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -114,10 +114,17 @@
/**
* Sets up the lighting. Should be called before the first frame of
rendering.
*
- * @param graphicsData @param graphicsData The current {@link
GraphicsData} object containing information
+ * @param graphicsData The current {@link GraphicsData} object
containing information
* about the current state of rendering as well as the current state of
the network.
*/
public void setupLighting(GraphicsData graphicsData);
+
+ /**
+ * Called when the GraphicsHandler is about to be disposed, to perform
any necessary cleanup
+ * @param graphicsData The current {@link GraphicsData} object
containing information
+ * about the current state of rendering as well as the current state of
the network.
+ */
+ public void dispose(GraphicsData graphicsData);
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -1,10 +1,12 @@
package org.cytoscape.paperwing.internal;
import java.nio.FloatBuffer;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.media.opengl.GL2;
@@ -50,12 +52,17 @@
*/
private List<ReadOnlyGraphicsProcedure> renderProcedures;
+ /**
+ * A Map containing rendering procedures that have re-usable display
lists.
+ */
+ Map<Class<? extends ReadOnlyGraphicsProcedure>, Integer>
renderProcedureLists;
+
public MainGraphicsHandler() {
- renderProcedures = new LinkedList<ReadOnlyGraphicsProcedure>();
-
+
// Populate the list of rendering routines that this
GraphicsHandler
// uses.
// The routines will be executed in the order that they are
added.
+ renderProcedures = new LinkedList<ReadOnlyGraphicsProcedure>();
renderProcedures.add(new ResetSceneProcedure());
renderProcedures.add(new PositionCameraProcedure());
@@ -63,8 +70,15 @@
renderProcedures.add(new RenderArcEdgesProcedure());
renderProcedures.add(new RenderSelectionBoxProcedure());
- renderProcedures.add(new RenderNodeLabelsProcedure());
+ // renderProcedures.add(new RenderNodeLabelsProcedure());
renderProcedures.add(new RenderLightsProcedure());
+
+ // Initialize the dictionary of display lists to be used for
rendering procedures that can be
+ // compiled into a re-usable display list
+ renderProcedureLists = new HashMap<Class<? extends
ReadOnlyGraphicsProcedure>, Integer>();
+
+ renderProcedureLists.put(RenderNodesProcedure.class, null);
+ renderProcedureLists.put(RenderArcEdgesProcedure.class, null);
}
@Override
@@ -82,8 +96,28 @@
// gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION,
// FloatBuffer.wrap(lightPosition));
+ GL2 gl = graphicsData.getGlContext();
+
for (ReadOnlyGraphicsProcedure renderProcedure :
renderProcedures) {
- renderProcedure.execute(graphicsData);
+ // Does this rendering procedure have a re-usable
display list?
+ if
(renderProcedureLists.get(renderProcedure.getClass()) != null) {
+
+ // Is it time to update the display list?
+ if (graphicsData.getUpdateScene() ||
graphicsData.getFramesElapsed() <= 2) {
+
gl.glNewList(renderProcedureLists.get(renderProcedure.getClass()),
GL2.GL_COMPILE_AND_EXECUTE);
+ renderProcedure.execute(graphicsData);
+ gl.glEndList();
+
+ graphicsData.setUpdateScene(false);
+ // If not, call the current list
+ } else {
+
gl.glCallList(renderProcedureLists.get(renderProcedure.getClass()));
+ }
+ } else {
+ renderProcedure.execute(graphicsData);
+ }
+
+// renderProcedure.execute(graphicsData);
}
}
@@ -148,11 +182,25 @@
@Override
public void initializeGraphicsProcedures(GraphicsData graphicsData) {
+ GL2 gl = graphicsData.getGlContext();
+
for (ReadOnlyGraphicsProcedure renderProcedure :
renderProcedures) {
renderProcedure.initialize(graphicsData);
}
+
+ for (Entry<Class<? extends ReadOnlyGraphicsProcedure>, Integer>
entry : renderProcedureLists.entrySet()) {
+ renderProcedureLists.put(entry.getKey(),
gl.glGenLists(1));
+ }
}
+ @Override
+ public void dispose(GraphicsData graphicsData) {
+ GL2 gl = graphicsData.getGlContext();
+
+ for (Integer list : renderProcedureLists.values()) {
+ gl.glDeleteLists(list, 1);
+ }
+ }
}
\ No newline at end of file
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -48,7 +48,7 @@
private float nearZ = 0.2f;
/** Distance from eye to the far clipping plane */
- private float farZ = 50f;
+ private float farZ = 500f;
/** The camera to use for transformation of 3D scene */
private SimpleCamera camera;
@@ -71,6 +71,15 @@
/** A boolean to disable real-time shape picking to improve framerate */
private boolean disableHovering;
+ /** The display list for drawing the entire scene, minus the
transformations performed to setup the scene */
+ private int sceneList = 0;
+
+ /** Whether the scene has been updated and needs to be redrawn */
+ private boolean updateScene = false;
+
+ /** Whether to display the current frames per second */
+ private boolean showFPS = false;
+
private Component container;
/** A {@link TaskFactoryListener} object that can be used to obtain the
current set of task factories */
@@ -308,4 +317,29 @@
public SubmenuTaskManager getSubmenuTaskManager() {
return submenuTaskManager;
}
+
+ public void setUpdateScene(boolean updateScene) {
+ this.updateScene = updateScene;
+ }
+
+ public boolean getUpdateScene() {
+ return updateScene;
+ }
+
+ public void setSceneList(int sceneList) {
+ this.sceneList = sceneList;
+ }
+
+ public int getSceneList() {
+ return sceneList;
+ }
+
+ public void setShowFPS(boolean showFPS) {
+ this.showFPS = showFPS;
+ }
+
+ public boolean getShowFPS() {
+ return showFPS;
+ }
+
}
Added:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -0,0 +1,30 @@
+package org.cytoscape.paperwing.internal.input;
+
+import java.util.Set;
+
+import org.cytoscape.paperwing.internal.data.GraphicsData;
+
+import com.jogamp.newt.event.KeyEvent;
+
+/**
+ * {@link InputHandler} object used to handle debug-related input
+ */
+public class DebugInputHandler implements InputHandler {
+
+ @Override
+ public void processInput(KeyboardMonitor keys, MouseMonitor mouse,
+ GraphicsData graphicsData) {
+
+ Set<Integer> pressed = keys.getPressed();
+
+ if (pressed.contains(KeyEvent.VK_M)) {
+ graphicsData.setUpdateScene(true);
+ }
+
+ // Toggle FPS display
+ if (pressed.contains(KeyEvent.VK_K)) {
+ graphicsData.setShowFPS(!graphicsData.getShowFPS());
+ }
+ }
+
+}
Property changes on:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MainInputProcessor.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MainInputProcessor.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MainInputProcessor.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -22,6 +22,8 @@
inputHandlers.add(new LightMovementInputHandler());
inputHandlers.add(new ContextMenuInputHandler());
+
+ inputHandlers.add(new DebugInputHandler());
}
public void processInput(KeyboardMonitor keys, MouseMonitor mouse,
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -127,6 +127,10 @@
}
}
+ if (graphicsData.getShowFPS()) {
+
+ }
+
textRenderer.endRendering();
gl.glPopMatrix();
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -95,8 +95,8 @@
// gl.glLoadName(33);
// Draw it only if the visual property says it is
visible
- if
(nodeView.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)
- &&
graphicsData.getViewingVolume().inside(new Vector3(x, y, z),
graphicsData.getNearZ() / 2)) {
+ if
(nodeView.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)) {
+ // &&
graphicsData.getViewingVolume().inside(new Vector3(x, y, z),
graphicsData.getNearZ() / 2)) {
gl.glPushMatrix();
gl.glTranslatef(x, y, z);
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/EdgeShapeDrawer.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/EdgeShapeDrawer.java
2012-03-14 18:51:10 UTC (rev 28534)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/shapes/EdgeShapeDrawer.java
2012-03-14 19:02:12 UTC (rev 28535)
@@ -20,7 +20,8 @@
public static enum EdgeShapeType {
REGULAR,
DASHED,
- DOTTED
+ DOTTED,
+ REGULAR_LINE_BASED // Test drawing edges using OpenGL lines
instead of polygons
}
private Map<EdgeShapeType, Integer> segmentLists;
@@ -33,6 +34,7 @@
initializeCylinder(gl);
initializeDashedCylinder(gl);
initializeDottedShape(gl);
+ initializeLineBasedSegment(gl);
}
/**
@@ -106,6 +108,25 @@
segmentLists.put(EdgeShapeType.DOTTED, listIndex);
}
+ /**
+ * Performs initialization for drawing a segment of a line, but uses
OpenGL lines instead of polygons to perform the drawing.
+ * The segment has length 1, and extends from the origin towards the
positive z-axis.
+ */
+ public void initializeLineBasedSegment(GL2 gl) {
+ int listIndex = gl.glGenLists(1);
+
+ gl.glNewList(listIndex, GL2.GL_COMPILE);
+ gl.glBegin(GL2.GL_LINES);
+
+ gl.glVertex3f(0.0f, 0.0f, 0.0f);
+ gl.glVertex3f(0.0f, 0.0f, 1.0f);
+
+ gl.glEnd();
+ gl.glEndList();
+
+ segmentLists.put(EdgeShapeType.REGULAR_LINE_BASED, listIndex);
+ }
+
public void drawSegment (GL2 gl, EdgeShapeType segmentType) {
Integer segmentList = segmentLists.get(segmentType);
@@ -113,4 +134,6 @@
gl.glCallList(segmentList);
}
}
+
+
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.