Hi,
I receive this error when adding a DirectionalLightShadowFilter on a FilterPostProcessor.
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.UnsupportedOperationException: FrameBuffer already initialized.
at com.jme3.texture.FrameBuffer.setDepthTexture(FrameBuffer.java:473)
at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:183)
at com.jme3.post.FilterPostProcessor.addFilter(FilterPostProcessor.java:116)
at org.impstack.litw.tool.DlsfError$MyDirecationalLightShadowFilterState.update(DlsfError.java:86)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:287)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:748)
my test case:
public class DlsfError extends SimpleApplication {
public static void main(String[] args) {
new DlsfError().start();
}
@Override
public void simpleInitApp() {
getStateManager().attachAll(new MySceneProcesserState(), new MyDirectionalLightShadowFilterState());
}
class MySceneProcesserState extends BaseAppState {
FilterPostProcessor fpp;
@Override
protected void initialize(Application app) {
fpp = new FilterPostProcessor(app.getAssetManager());
fpp.setNumSamples(app.getContext().getSettings().getSamples());
System.out.println("#samples: " + app.getContext().getSettings().getSamples());
app.getViewPort().addProcessor(fpp);
}
@Override
protected void onEnable() {
}
@Override
protected void onDisable() {
}
@Override
protected void cleanup(Application app) {
app.getViewPort().removeProcessor(fpp);
}
public FilterPostProcessor getFpp() {
return fpp;
}
}
class MyDirectionalLightShadowFilterState extends BaseAppState {
DirectionalLightShadowFilter dlsf;
DirectionalLight directionalLight;
long start;
boolean attached = false;
@Override
protected void initialize(Application app) {
directionalLight = new DirectionalLight(new Vector3f(-1, -1, 1).normalizeLocal(), ColorRGBA.White);
}
@Override
protected void onEnable() {
((SimpleApplication) getApplication()).getRootNode().addLight(directionalLight);
start = System.currentTimeMillis();
}
@Override
public void update(float tpf) {
if (System.currentTimeMillis() - start >= 1000 && !attached) {
dlsf = new DirectionalLightShadowFilter(getAssetManager(), 1024, 4);
dlsf.setLight(directionalLight);
dlsf.setEnabled(true);
dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
dlsf.setEdgesThickness(2);
dlsf.setShadowIntensity(0.75f);
dlsf.setLambda(0.65f);
dlsf.setShadowZExtend(50);
getState(MySceneProcesserState.class).getFpp().addFilter(dlsf);
attached = true;
System.out.println("attached!");
}
}
@Override
protected void onDisable() {
}
@Override
protected void cleanup(Application app) {
getState(MySceneProcesserState.class).getFpp().removeFilter(dlsf);
}
}
}
When you remove this line when setting up the FilterPostProcessor:
fpp.setNumSamples(app.getContext().getSettings().getSamples());
the error is gone and everything just works.
Am I doing something wrong here?
The way I am doing this in application states, is because I have the FilterPostProcessor setup on the viewport in an Application state. Other State’s can then grab the FilterPostProcessor to add filters they require. I simulate this behaviour in the testcase by waiting a bit before attaching the filter to the FilterPostProcessor.