FrameBuffer in version 1.9.7

Anything libgdx related goes here!

FrameBuffer in version 1.9.7

Postby MMM1412 » Mon Oct 23, 2017 1:56 am

I am making a new app, and I want to publish it nextweek. I must use Libgdx 1.9.7 because i must use method batch.setBlendFunctionSeparate() for my app (new in 1.9.7), but version 1.9.7 change my app. FrameBuffer is a very important part of my app. Sometime I need to keep Colortexture when dispose Framebuffer.

here is my old code, in my app I must creat framebuffer many times with many other sizes, some of them keep colortexture or not
Code: Select all
buffer = new FrameBuffer(format,width,height,true) {
                @Override
                protected void disposeColorTexture(Texture colorTexture) {
                    if (!keeptexture) {
                        super.disposeColorTexture(colorTexture);
                    }
                }
            };


I dont know how to do it in version 1.9.7.

Anybody can help me in this problem ? or how i can use batch.setBlendFunctionSeparate() in version 1.9.6 ? Thanks so much !
MMM1412
 
Posts: 111
Joined: Mon Sep 14, 2015 10:48 am

Re: FrameBuffer in version 1.9.7

Postby tomski » Mon Oct 23, 2017 7:42 am

Subclass FrameBufferBuilder. See https://gist.github.com/Tom-Ski/b513ef5 ... f0e608e505 for an example.
tomski
 
Posts: 729
Joined: Wed Jun 26, 2013 6:06 pm

Re: FrameBuffer in version 1.9.7

Postby MMM1412 » Mon Oct 23, 2017 8:42 am

Perfect ! :D Thanks Tom
MMM1412
 
Posts: 111
Joined: Mon Sep 14, 2015 10:48 am

Re: FrameBuffer in version 1.9.7

Postby CoDi » Tue Oct 24, 2017 8:54 am

Tom, do you have a test which does both depth&stencil at the same time? The update totally broke my custom MRT class, and I'm about to fix that.

One of our render targets uses a GL_DEPTH24_STENCIL8 render buffer. Now out of the box, using FrameBufferBuilder with depth and stencil produces an incomplete buffer error at least on MacOS, which was the reason I changed to the combined format back then.

I'm still thinking about the best solution to solve or work around this with the new API.
Robotality - steamworks4j - @code_disaster - codi^r @ #libgdx
CoDi
 
Posts: 194
Joined: Sun Nov 24, 2013 11:55 am
Location: Hamelin, Germany

Re: FrameBuffer in version 1.9.7 and 1.9.8

Postby MMM1412 » Wed Mar 14, 2018 1:57 am

tomski wrote:Subclass FrameBufferBuilder. See https://gist.github.com/Tom-Ski/b513ef5 ... f0e608e505 for an example.


Hi I think there are some changes in 1.9.8. :oops:

i am not sure about it. But Framebuffer is very important part in my apps. My two new apps use framebuffer version 1.9.8 and 1.9.7 and there are crash reports i received as follow; this problem I solved in my old apps, in libgdx < 1.9.6. But now it come back.


Code: Select all
java.lang.IllegalStateException: frame buffer couldn't be constructed: missing attachment
 at com.badlogic.gdx.graphics.glutils.d.b(Unknown Source)
   at com.badlogic.gdx.graphics.glutils.d.a(Unknown Source)
   at com.badlogic.gdx.backends.android.j.onSurfaceCreated(Unknown Source)
   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1448)
   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1218)



My old apps use libgdx 1.9.6 , I fix this problem by code:


Code: Select all
try {
            buffer = new FrameBuffer(Pixmap.Format.RGBA8888, Config.Maxsize, Config.Maxsize, true);

        } catch (IllegalStateException e) {
            try {
                buffer = new FrameBuffer(Pixmap.Format.RGBA4444, Config.Maxsize, Config.Maxsize, true);
            } catch (IllegalStateException e1) {
                buffer = new FrameBuffer(Pixmap.Format.RGB565, Config.Maxsize, Config.Maxsize, true);
            }
        }*/




In libgdx 1.9.7 , My code use Tomski s' hint

Code: Select all
public class Mybuffer {
    private FrameBuffer buffer;
    private TextureRegion region;

    public Mybuffer(int width, int height, boolean hasDepth, final boolean keeptexxture) {

        try {
            buffer = SubclassedFramebufferBuilder.createBasicExtended(Pixmap.Format.RGBA8888, width, height,false,false,keeptexxture);

        } catch (Throwable e) {
            try {
                buffer = SubclassedFramebufferBuilder.createBasicExtended(Pixmap.Format.RGBA4444, width, height,false,false,keeptexxture);

            } catch (Throwable e) {
                buffer = SubclassedFramebufferBuilder.createBasicExtended(Pixmap.Format.RGB565, width, height,false,false,keeptexxture);

            }
        }
        region = new TextureRegion(buffer.getColorBufferTexture());


    }

    public void dispose() {
        buffer.dispose();
    }


    public TextureRegion getRegion() {
        return region;
    }

    public FrameBuffer getbufer() {
        return buffer;
    }

}


And libgdx 1.9.8 with new update for framebuffer. I must change SubclassedFramebufferBuilder of Tomski into

Code: Select all
public class SubclassedFramebufferBuilder extends GLFrameBuffer.FrameBufferBuilder {

    protected boolean keepColourTextures;

    public SubclassedFramebufferBuilder (int width, int height) {
        super(width, height);
    }

    public void keepColorTextures (boolean keepColorTextures) {
        this.keepColourTextures = keepColorTextures;
    }

    @Override
    public FrameBuffer build () {
        return new FrameBuffer(this) {
            @Override
            protected void disposeColorTexture (Texture colorTexture) {
                if (!keepColourTextures) {
                    super.disposeColorTexture(colorTexture);
                }
            }
        };
    }

    /**
     * Example use to create a convenience method
     */
    public static FrameBuffer createBasicExtended (Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil, boolean keepColorTextures) {
        SubclassedFramebufferBuilder frameBufferBuilder = new SubclassedFramebufferBuilder(width, height);
        frameBufferBuilder.addBasicColorTextureAttachment(format);
        frameBufferBuilder.keepColorTextures(keepColorTextures);

//        if (hasDepth) frameBufferBuilder.addDepthRenderBufferAttachment();   ////// not available at 1.9.8
//        if (hasStencil) frameBufferBuilder.addStencilRenderBufferAttachment();  //////not available at 1.9.8
        if (hasDepth) frameBufferBuilder.addBasicDepthRenderBuffer();/
        if (hasStencil) frameBufferBuilder.addBasicStencilRenderBuffer();
        return frameBufferBuilder.build();
    }
}



Really, they make me confusing, I just they work like old version. Anyone get same problem ?? :oops:
MMM1412
 
Posts: 111
Joined: Mon Sep 14, 2015 10:48 am

Re: FrameBuffer in version 1.9.7

Postby tenfour04 » Wed Mar 14, 2018 2:07 am

1.9.8 brought back the original FrameBuffer constructors so you can go back to your 1.9.6 method, I think.
tenfour04
 
Posts: 1179
Joined: Sat Jun 18, 2011 3:24 pm

Re: FrameBuffer in version 1.9.7

Postby MMM1412 » Thu Mar 15, 2018 7:53 am

I ll come back old version of framebuffer in libgdx 1.9.8. Really, I hope there are some tutorials to make the most of new framebuffer. Libgdx have everything I need, just make it stable and fix buges. All the best.
MMM1412
 
Posts: 111
Joined: Mon Sep 14, 2015 10:48 am


Return to Libgdx

Who is online

Users browsing this forum: Exabot [Bot] and 27 guests