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 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,15 +67,8 @@ 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) ){
 | 
			
		||||
		
 | 
			
		||||
		if (lists.containsKey(c)) {
 | 
			
		||||
			gl.glCallList(lists.get(c));
 | 
			
		||||
		} else {
 | 
			
		||||
			int list = gl.glGenLists(1);
 | 
			
		||||
@ -220,7 +219,7 @@ public class ComponentRenderer {
 | 
			
		||||
		
 | 
			
		||||
		gl.glMatrixMode(GL.GL_TEXTURE);
 | 
			
		||||
		gl.glPushMatrix();
 | 
			
		||||
		gl.glScaled(1/(maxX-minX), 1/(maxY-minY), 0);
 | 
			
		||||
		gl.glScaled(1 / (maxX - minX), 1 / (maxY - minY), 0);
 | 
			
		||||
		gl.glTranslated(-minX, -minY - fs.getBodyRadius(), 0);
 | 
			
		||||
		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user