JME3 FrameBuffer setTargetIndex() confusion

Hey people!

This is my first post, and I wasn’t sure about where to put this, so I’m sorry if this is the wrong section!

I’m trying to render to different targets, but not simultaneously through MRT.

The method setTargetIndex from the FrameBuffer class has a bug, or is it me?


public void setTargetIndex(int index){

if (index < 0 || index >= 16)

throw new IllegalArgumentException();

if (colorBufs.size() >= index)

throw new IllegalArgumentException(“The target at " + index + " is not set!”);

colorBufIndex = index;


For example, if I add two color buffers through addColorTexture(), the colorBufs list will have size 2, and if I try to set framebuffer target to 0 (which would be default texture), it just throws an exception, due to the if (colorBufs.size() >= index)

I may be missing something, but it seems that line is doing the opposite thing: if I try to set any target that is less or equal than the color buffer list size, it will throw that exception, which is not what the user wll generally want, right?

Then, if I set the target index to anything greater than colorBufs.size(), an IndexOutOfBoundsException will be thrown, which is expected.

So this method will always throw an exception! (either directly or indirectly)

Can anyone explain why is this method doing this, or is it a bug?

Thanks and sorry for the long post!

Thanks, it is fixed in SVN

Thanks a lot! That was really fast :smiley:

One more thing I found: for the target index to have any effect, one must call setFrameBuffer for each target, right?

On LwjglRenderer, the method setFrameBuffer has these lines:


if (lastFb == fb) {

if (fb == null || !fb.isUpdateNeeded()){





If updateNeeded is not changed, when calling setFrameBuffer with the same fbo, the method will just return.

I resolved this by calling setUpdateNeeded from outside, but should it be called from setTargetIndex()?

I ask this question mainly because setUpdateNeeded is marked as internal use only, so that it shouldn’t be called from outside as I did, and maybe some day it becomes a private method and cannot be accessed.

Again, maybe I’m missing something, or maybe that’s the way the framebuffer should work.

Thanks again for the fix!