How do I create second GL context?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I create second GL context?

kitfox
I've written a program that builds a scenegraph and is able to render it to a JGLPanel.

I want to create a feature that can also capture images to render them offscreen.  I need to figure out how to create a second GLAutoDrawable in order to do this.  I was thinking of using PBuffers, but am open to any option that works.  

Because of the way my program is architected, the bit of the code that does the actual image capture should not be able to touch the JGLPanel in any way.  What I'm looking for is a way to create a surface I can draw to without having to first create a JGLPanel or JGLCanvas.

I tried the following (basing it off the HDR.java example code), but the getGL() call returns null:

[code]
        GLDrawableFactory fact = GLDrawableFactory.getFactory(GLProfile.getDefault());
        GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
        caps.setOnscreen(false);
        caps.setPBuffer(true);
        caps.setDoubleBuffered(false);
        GLPbuffer pbuf = fact.createGLPbuffer(null, caps, null, width, height, null);

        pbuf.getGL();  //Returns null
[/code]

How can I write this so that I have a live context I can render with?
Reply | Threaded
Open this post in threaded view
|

Re: How do I create second GL context?

kitfox
I tried adding the following, but am still getting null:

[code]
        GLContext glCtx = fact.getOrCreateSharedContext(null);
       
        GLPbuffer pbuf =
                fact.createGLPbuffer(null,
                caps, null,
                width, height,
                glCtx);
[/code]

And in case I made it sound confusing above - the reason I need the second context is that I'm using a plugin-like architecture.  The bit of code that handles rendering to the screen should know nothing about the code that handles rendering to the offscreen image (that is then saved to disk) and visa versa.  Both are passed the scenegraph they need to render via an interface.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create second GL context?

Sven Gothel
Administrator
On Monday, November 21, 2011 10:36:05 PM kitfox [via jogamp] wrote:

>
> I tried adding the following, but am still getting null:
>
> [code]
>         GLContext glCtx = fact.getOrCreateSharedContext(null);
>        
>         GLPbuffer pbuf =
>                 fact.createGLPbuffer(null,
>                 caps, null,
>                 width, height,
>                 glCtx);
> [/code]
>

Please check this commit and the test case I have changed ..

http://jogamp.org/git/?p=jogl.git;a=commit;h=12342c9e6122051fbdc91493c4d63515ad4613d1

getOrCreate...() is not for public use, I removed it from the API, it was a bug.

Just create the pbuffer drawable and force context creation via 1st display:
  http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java;h=fbc16953da053f7e0d45f1ba7a3e02c511b43532;hb=bf6504797d4823bc49d0340238dd32cab9f1612e#l122

then you can use the context: pbuf.getContext() for sharing.

~Sven