Carry init & dispose methods down into RenderStrategy, so that textures can be disposed of and reloaded.

This commit is contained in:
Bill Kuker 2012-07-02 21:33:49 +00:00 committed by U-WINDOWS-C28163E\Administrator
parent dc66d2a93e
commit d22cefa248
4 changed files with 31 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import java.util.Map;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLProfile;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
@ -35,10 +36,22 @@ public class RealisticRenderStrategy extends RenderStrategy {
private Map<URI, Texture> texCache = new HashMap<URI, Texture>();
@Override
public void clearCaches() {
public void updateFigure() {
needClearCache = true;
}
@Override
public void init(GLAutoDrawable drawable) {
oldTexCache = new HashMap<URI,Texture>();
texCache = new HashMap<URI,Texture>();
}
@Override
public void dispose(GLAutoDrawable drawable) {
oldTexCache = null;
texCache = null;
}
@Override
public boolean isDrawn(RocketComponent c) {
return true;

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.figure3d;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -13,8 +14,16 @@ public abstract class RenderStrategy {
public abstract void postGeometry(GL2 gl, RocketComponent c, float alpha);
public void clearCaches() {
public void updateFigure() {
}
public void init(GLAutoDrawable drawable) {
}
public void dispose(GLAutoDrawable drawable) {
}
}

View File

@ -375,6 +375,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
@Override
public void dispose(GLAutoDrawable drawable) {
log.verbose("GL - dispose() called");
rr.dispose(drawable);
}
@Override

View File

@ -39,9 +39,13 @@ public class RocketRenderer {
cr = new ComponentRenderer();
cr.init(drawable);
}
public void dispose(GLAutoDrawable drawable) {
currentStrategy.dispose(drawable);
}
public void updateFigure() {
currentStrategy.clearCaches();
currentStrategy.updateFigure();
cr.updateFigure();
}