Simplify the RocketFigure3D updateFigure() method to take advantage of

JOGL's invoke & GLRunnable, rather than using flags, to simplify the
code.
This commit is contained in:
bkuker 2013-01-08 10:05:45 -05:00
parent fa58cb6338
commit f6358ad2ba
4 changed files with 86 additions and 90 deletions

View File

@ -50,9 +50,15 @@ public class ComponentRenderer {
}
private Map<RocketComponent, Integer> lists = new HashMap<RocketComponent, Integer>();
private boolean clearDisplayLists = false;
public void updateFigure() {
clearDisplayLists = true;
public void updateFigure(GLAutoDrawable drawable) {
log.debug("Clearing Display Lists");
GL2 gl = drawable.getGL().getGL2();
for (int i : lists.values()) {
gl.glDeleteLists(i, 1);
}
lists.clear();
}
public void renderGeometry(GL2 gl, RocketComponent c) {
@ -61,14 +67,7 @@ public class ComponentRenderer {
glu.gluQuadricNormals(q, GLU.GLU_SMOOTH);
if ( clearDisplayLists ){
log.debug("Clearing Display Lists");
for ( int i : lists.values() ){
gl.glDeleteLists(i,1);
}
lists.clear();
clearDisplayLists = false;
}
if (lists.containsKey(c)) {
gl.glCallList(lists.get(c));
} else {

View File

@ -28,7 +28,6 @@ public class RealisticRenderer extends RocketRenderer {
private final float[] colorWhite = { 1, 1, 1, 1 };
private final float[] color = new float[4];
private boolean needClearCache = false;
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
private Map<String, Texture> texCache = new HashMap<String, Texture>();
private float anisotrophy = 0;
@ -69,10 +68,9 @@ public class RealisticRenderer extends RocketRenderer {
}
@Override
public void updateFigure() {
super.updateFigure();
needClearCache = true;
public void updateFigure(GLAutoDrawable drawable) {
super.updateFigure(drawable);
clearCaches(drawable.getGL().getGL2());
}
@Override
@ -95,12 +93,6 @@ public class RealisticRenderer extends RocketRenderer {
@Override
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
if (needClearCache) {
clearCaches(gl);
needClearCache = false;
}
final Appearance a = getAppearance(c);
final Decal t = a.getTexture();
final Texture tex = getTexture(t);

View File

@ -518,8 +518,13 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
public void updateFigure() {
log.debug("3D Figure Updated");
cachedBounds = null;
rr.updateFigure();
internalRepaint();
canvas.invoke(true, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable drawable) {
rr.updateFigure(drawable);
return false;
}
});
}
private void internalRepaint() {

View File

@ -38,8 +38,8 @@ public abstract class RocketRenderer {
public void dispose(GLAutoDrawable drawable) {
}
public void updateFigure() {
cr.updateFigure();
public void updateFigure(GLAutoDrawable drawable) {
cr.updateFigure(drawable);
}
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);