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:
parent
fa58cb6338
commit
f6358ad2ba
@ -50,9 +50,15 @@ public class ComponentRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<RocketComponent, Integer> lists = new HashMap<RocketComponent, Integer>();
|
private Map<RocketComponent, Integer> lists = new HashMap<RocketComponent, Integer>();
|
||||||
private boolean clearDisplayLists = false;
|
|
||||||
public void updateFigure() {
|
public void updateFigure(GLAutoDrawable drawable) {
|
||||||
clearDisplayLists = true;
|
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) {
|
public void renderGeometry(GL2 gl, RocketComponent c) {
|
||||||
@ -61,14 +67,7 @@ public class ComponentRenderer {
|
|||||||
|
|
||||||
glu.gluQuadricNormals(q, GLU.GLU_SMOOTH);
|
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)) {
|
if (lists.containsKey(c)) {
|
||||||
gl.glCallList(lists.get(c));
|
gl.glCallList(lists.get(c));
|
||||||
} else {
|
} else {
|
||||||
|
@ -28,7 +28,6 @@ public class RealisticRenderer extends RocketRenderer {
|
|||||||
private final float[] colorWhite = { 1, 1, 1, 1 };
|
private final float[] colorWhite = { 1, 1, 1, 1 };
|
||||||
private final float[] color = new float[4];
|
private final float[] color = new float[4];
|
||||||
|
|
||||||
private boolean needClearCache = false;
|
|
||||||
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
|
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
|
||||||
private Map<String, Texture> texCache = new HashMap<String, Texture>();
|
private Map<String, Texture> texCache = new HashMap<String, Texture>();
|
||||||
private float anisotrophy = 0;
|
private float anisotrophy = 0;
|
||||||
@ -69,10 +68,9 @@ public class RealisticRenderer extends RocketRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFigure() {
|
public void updateFigure(GLAutoDrawable drawable) {
|
||||||
super.updateFigure();
|
super.updateFigure(drawable);
|
||||||
|
clearCaches(drawable.getGL().getGL2());
|
||||||
needClearCache = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,12 +93,6 @@ public class RealisticRenderer extends RocketRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
public void renderComponent(GL2 gl, RocketComponent c, float alpha) {
|
||||||
|
|
||||||
if (needClearCache) {
|
|
||||||
clearCaches(gl);
|
|
||||||
needClearCache = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Appearance a = getAppearance(c);
|
final Appearance a = getAppearance(c);
|
||||||
final Decal t = a.getTexture();
|
final Decal t = a.getTexture();
|
||||||
final Texture tex = getTexture(t);
|
final Texture tex = getTexture(t);
|
||||||
|
@ -518,8 +518,13 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
public void updateFigure() {
|
public void updateFigure() {
|
||||||
log.debug("3D Figure Updated");
|
log.debug("3D Figure Updated");
|
||||||
cachedBounds = null;
|
cachedBounds = null;
|
||||||
rr.updateFigure();
|
canvas.invoke(true, new GLRunnable() {
|
||||||
internalRepaint();
|
@Override
|
||||||
|
public boolean run(GLAutoDrawable drawable) {
|
||||||
|
rr.updateFigure(drawable);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void internalRepaint() {
|
private void internalRepaint() {
|
||||||
|
@ -38,8 +38,8 @@ public abstract class RocketRenderer {
|
|||||||
public void dispose(GLAutoDrawable drawable) {
|
public void dispose(GLAutoDrawable drawable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFigure() {
|
public void updateFigure(GLAutoDrawable drawable) {
|
||||||
cr.updateFigure();
|
cr.updateFigure(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);
|
public abstract void renderComponent(GL2 gl, RocketComponent c, float alpha);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user