Add ability to change RenderStrategy on the fly.
This commit is contained in:
parent
f5c309d2cc
commit
a2afb106d5
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user