Add ability to change RenderStrategy on the fly.

This commit is contained in:
Bill Kuker 2012-07-06 18:48:52 +00:00 committed by U-WINDOWS-C28163E\Administrator
parent f5c309d2cc
commit a2afb106d5
2 changed files with 29 additions and 0 deletions

View File

@ -48,6 +48,10 @@ import com.jogamp.opengl.util.awt.Overlay;
* @author Bill Kuker <bkuker@billkuker.com>
*/
public class RocketFigure3d extends JPanel implements GLEventListener {
public static final int TYPE_REALISTIC = 0;
public static final int TYPE_FIGURE = 1;
private static final long serialVersionUID = 1L;
private static final LogHelper log = Application.getLogger();
@ -612,4 +616,12 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
this.csl = newListener;
}
public void setType(int t){
if ( t == TYPE_FIGURE ){
rr.setRenderStrategy(new FigureRenderStrategy());
} else {
rr.setRenderStrategy(new RealisticRenderStrategy());
}
}
}

View File

@ -28,6 +28,7 @@ public class RocketRenderer {
private static final LogHelper log = Application.getLogger();
RenderStrategy currentStrategy = new FigureRenderStrategy();
RenderStrategy nextStrategy;
ComponentRenderer cr;
@ -35,6 +36,19 @@ public class RocketRenderer {
private final float[] colorBlack = { 0, 0, 0, 1 };
public void setRenderStrategy(RenderStrategy r){
nextStrategy = r;
}
private void checkRenderStrategy(GLAutoDrawable drawable){
if ( nextStrategy == null )
return;
currentStrategy.dispose(drawable);
nextStrategy.init(drawable);
currentStrategy = nextStrategy;
nextStrategy = null;
}
public void init(GLAutoDrawable drawable) {
cr = new ComponentRenderer();
cr.init(drawable);
@ -52,6 +66,7 @@ public class RocketRenderer {
public RocketComponent pick(GLAutoDrawable drawable,
Configuration configuration, Point p, Set<RocketComponent> ignore) {
checkRenderStrategy(drawable);
final GL2 gl = drawable.getGL().getGL2();
gl.glEnable(GL.GL_DEPTH_TEST);
@ -97,6 +112,8 @@ public class RocketRenderer {
public void render(GLAutoDrawable drawable, Configuration configuration,
Set<RocketComponent> selection) {
checkRenderStrategy(drawable);
if (cr == null)
throw new IllegalStateException(this + " Not Initialized");