Problems With FilterPostProcessor in Multiple AWTPanels

I am using Multiple AWTpanels in my application and I would like to add some Filters to multiple views. I can easily add Shadows as a processor on a viewport, but as soon as I add a FilterPostProcessor( on my second viewport) I get the following exception. The problem only occurs when I want to add a FilterPostProcessor on a view that does not override the main frame buffer for example panel2.attachTo(false, viewPort2);
Bellow is a simple test case that shows this problem. If you comment out the line “setUpPostProcessors(viewPort2);” it will run but it will only be adding the post processors to the first viewport.

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Why did you change the output framebuffer?
	at com.jme3.system.awt.AwtPanel.postFrame(AwtPanel.java:293)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:987)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:251)
	at com.jme3.system.awt.AwtPanelsContext.updateInThread(AwtPanelsContext.java:188)
	at com.jme3.system.awt.AwtPanelsContext.access$100(AwtPanelsContext.java:44)
	at com.jme3.system.awt.AwtPanelsContext$AwtPanelsListener.update(AwtPanelsContext.java:68)
	at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:125)
	at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:151)
	at java.lang.Thread.run(Unknown Source)

[code title=“Simple Test Case”]
public class TestAwtFilters extends SimpleApplication
{
private static TestAwtFilters app;
private static AwtPanel panel, panel2;
private Vector3f lightDirection = new Vector3f(-5f, -4f, -4).normalizeLocal();
private DirectionalLight directionalLight;
private static int panelsClosed = 0;

private static void createWindowForPanel(AwtPanel panel, int location)
{
JFrame frame = new JFrame("Render Display " + location);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosed(WindowEvent e)
{
if (++panelsClosed == 2)
{
app.stop();
}
}
});
frame.pack();
frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
frame.setVisible(true);
}

public static void main(String[] args)
{
Logger.getLogger(“com.jme3”).setLevel(Level.WARNING);

  app = new TestAwtFilters();
  app.setShowSettings(false);
  AppSettings settings = new AppSettings(true);
  settings.setCustomRenderer(AwtPanelsContext.class);
  settings.setFrameRate(60);
  app.setSettings(settings);
  app.start();
  SwingUtilities.invokeLater(new Runnable()
  {
     public void run()
     {
        final AwtPanelsContext ctx = (AwtPanelsContext) app.getContext();
        panel = ctx.createPanel(PaintMode.Accelerated);
        panel.setPreferredSize(new Dimension(400, 300));
        ctx.setInputSource(panel);
        panel2 = ctx.createPanel(PaintMode.Accelerated);
        panel2.setPreferredSize(new Dimension(400, 300));
        createWindowForPanel(panel, 300);
        createWindowForPanel(panel2, 700);
     }
  });

}

public void simpleInitApp()
{
flyCam.setDragToRotate(true);
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry(“Box”, b);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));
geom.setMaterial(mat);
rootNode.attachChild(geom);
Box bGround = new Box(Vector3f.ZERO, 100, 0.01f, 100);
Geometry geomGround = new Geometry(“BoxGround”, bGround);
geomGround.setMaterial(mat);
rootNode.attachChild(geomGround);

  ViewPort viewPort2 = getRenderManager().createMainView("cameraClone", cam);
  viewPort2.attachScene(getRootNode());
  viewPort2.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 0.8f, 1f));
  viewPort2.setClearFlags(true, true, true);

  setUpLight();

  setUpPostProcessors(viewPort);

  // comment out this line to get it to run
  setUpPostProcessors(viewPort2);

  panel.attachTo(true, viewPort);
  panel2.attachTo(false, viewPort2);

}

protected void setUpLight()
{
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(al);
directionalLight = new DirectionalLight();
directionalLight.setColor(ColorRGBA.White);
directionalLight.setDirection(lightDirection);
rootNode.addLight(directionalLight);
}

public void setUpPostProcessors(ViewPort viewPortToAddTo)
{
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, 2048, 4);
dlsr.setLight(directionalLight);
dlsr.setLambda(0.55f);
dlsr.setShadowIntensity(0.6f);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.Dither);
viewPortToAddTo.addProcessor(dlsr);

  DepthOfFieldFilter dofFilter = new DepthOfFieldFilter();
  dofFilter.setFocusDistance(0);
  dofFilter.setFocusRange(50);
  dofFilter.setBlurScale(1.4f);

  FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
  fpp.addFilter(dofFilter);

  viewPortToAddTo.addProcessor(fpp);

}
}[/code]

1 Like

I tried to fix this one, but it’s tough.
I’ll need a little bit more time to figure it out. Basically the frameBuffers are mixed up

The AWT panel cannot handle the case where the framebuffer was altered … Since the resolution of the framebuffer depends on the panel’s size, it will require notifying whoever put the framebuffer in there to resize its own state as well…

Has there been any progress on this issue. FilterPostProcessors would be a very nice addition to my application at the moment.

I’m sorry, i didn’t get very far…
Actually there is a design issue between FPP and dual awt panels, it just can’t work at the moment.
This will need a redesign mostly.

This problem has resurfaced for us if there is anyone out there who can take a look at it. We simply avoided this issue by not doing FilterPostProcessor in multiple views, but we have come across a need for it now.

I am also looking for a solution to this problem. Anyone??