JOGL 2 - SWT in MAC : cannot get GLContext

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

Re: JOGL 2 - SWT in MAC : cannot get GLContext

Sven Gothel
Administrator
On 03/01/2013 08:09 AM, Brian Capozzi [via jogamp] wrote:
> I have the same exact issue on Mac OS X 10.8.2.
>
> Just migrated to jogl-2.0-rc11 from 1.1
>

Thank you very much for providing the 1st useful information on this issue,
KUDOS!

> Any idea what is wrong here?  What can I do to provide you with additional input?
>

No external context at all ?

Please provide a small little example (unit test) so I can reproduce,
thank you very much.

~Sven
> Thanks,
> BC
>


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2 - SWT in MAC : cannot get GLContext

Brian Capozzi
In reply to this post by gouessej
Issue is resolved.  Or at least worked around.
Turns out if we call GLProfile.get() (which under the covers calls initSingleton()) prior to creating anything (Component, Display, etc.) then the context gets created correctly and our visualization works as expected.

But thanks for responding.
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2 - SWT in MAC : cannot get GLContext

Brian Capozzi
In reply to this post by Sven Gothel
Just wanted to reply specifically to you.  Thanks for responding to my initial query.

I was able to successfully run the jogl swt demo (SWTSnippet, brings up a torus) - and I noticed that GLProfile.get() was the first thing called.  Stepping through I saw that, indeed, the context being created was non-null for the swt demo.

I changed our code to call GLProfile.get() prior to any Component being created.  Sure enough, it now works on Mac OS X.  Even better, it now works over VNC.  So it must have been an initialization issue.

Prior to my change, we were creating a Component first and THEN calling GLProfile.get().  Now we are calling GLProfile.get() essentially as the first thing in the constructor for our main visualization UI element.  I suppose we could even add a static initialization block somewhere to take that "first thing" even further to an extreme.

If you could shed any light into _why_ this works - and why it didn't work the way we had done it previously, I would be much appreciative.

I was able to get the SWTSnippet demo to fail in exactly the same way as ours by moving the call to GLProfile.get() to just before the call to create the context.

e.g.,

THIS FAILS:
public static void main(String [] args) {
           
            final Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            Composite comp = new Composite(shell, SWT.NONE);
            comp.setLayout(new FillLayout());
            GLData data = new GLData ();
            data.doubleBuffer = true;
            final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

            canvas.setCurrent();
           
            final GLProfile gl2Profile = GLProfile.get(GLProfile.GL2);
            final GLContext context = GLDrawableFactory.getFactory(gl2Profile).createExternalGLContext();
...
throws:

Exception in thread "main" javax.media.opengl.GLException: Error: current Context (CGL) null, no Context (NS)
        at jogamp.opengl.macosx.cgl.MacOSXExternalCGLContext.create(MacOSXExternalCGLContext.java:92)
        at jogamp.opengl.macosx.cgl.MacOSXCGLDrawableFactory.createExternalGLContextImpl(MacOSXCGLDrawableFactory.java:395)
        at jogamp.opengl.GLDrawableFactoryImpl.createExternalGLContext(GLDrawableFactoryImpl.java:446)
        at com.barelymoon.graphics.SWTSnippet.main(SWTSnippet.java:60)

vs. the actual swt demo code:

final GLProfile gl2Profile = GLProfile.get(GLProfile.GL2);
                final Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            Composite comp = new Composite(shell, SWT.NONE);
            comp.setLayout(new FillLayout());
            GLData data = new GLData ();
            data.doubleBuffer = true;
            final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

            canvas.setCurrent();
           
            final GLContext context = GLDrawableFactory.getFactory(gl2Profile).createExternalGLContext();
...
which works correctly.

Which is what led me to my work-around.

Thanks,
BC


Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2 - SWT in MAC : cannot get GLContext

Sven Gothel
Administrator
On 03/01/2013 08:27 PM, Brian Capozzi [via jogamp] wrote:

> Just wanted to reply specifically to you.  Thanks for responding to my initial
> query.
>
> I was able to successfully run the jogl swt demo (SWTSnippet, brings up a
> torus) - and I noticed that GLProfile.get() was the first thing called.
>  Stepping through I saw that, indeed, the context being created was non-null
> for the swt demo.
>
> I changed our code to call GLProfile.get() prior to any Component being
> created.  Sure enough, it now works on Mac OS X.  Even better, it now works
> over VNC.  So it must have been an initialization issue.
>
> Prior to my change, we were creating a Component first and THEN calling
> GLProfile.get().  Now we are calling GLProfile.get() essentially as the first
> thing in the constructor for our main visualization UI element.  I suppose we
> could even add a static initialization block somewhere to take that "first
> thing" even further to an extreme.
-> GLProfile.initSingleton()

Usually not needed, however if you avoid GLProfile or use some of it's
methods 'later' (after low level GL stuff) .. well, it didn't work on OSX
at least. We could walk through and try to fix it, but I guess this is
good enough for this use case (external context via factory).

>
> If you could shed any light into _why_ this works - and why it didn't work the
> way we had done it previously, I would be much appreciative.

GLProfile initialization walks probes all available GLContext profiles
on the so called 'default device'. This does initialize a few device depended
resources, which might be missing -> bug in OSX.

Since all 'normal' JOGL applications using a GLProfile instance to start
anything, initialization is guaranteed.

We could put in your use case below as a unit test and associate a bug entry
to fix it in some time.
If you are familiar w/ git, please send me a git-patch or pull request.
Simply use one of our SWT unit tests as a template.

Thank you.

~Sven


>
> I was able to get the SWTSnippet demo to fail in exactly the same way as ours
> by moving the call to GLProfile.get() to just before the call to create the
> context.
>
> e.g.,
>
> THIS FAILS:
> public static void main(String [] args) {
>            
>             final Display display = new Display();
>             Shell shell = new Shell(display);
>             shell.setLayout(new FillLayout());
>             Composite comp = new Composite(shell, SWT.NONE);
>             comp.setLayout(new FillLayout());
>             GLData data = new GLData ();
>             data.doubleBuffer = true;
>             final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);
>
>             canvas.setCurrent();
>            
>             final GLProfile gl2Profile = GLProfile.get(GLProfile.GL2);
>             final GLContext context =
> GLDrawableFactory.getFactory(gl2Profile).createExternalGLContext();
> ...
> throws:
>
> Exception in thread "main" javax.media.opengl.GLException: Error: current
> Context (CGL) null, no Context (NS)
>         at
> jogamp.opengl.macosx.cgl.MacOSXExternalCGLContext.create(MacOSXExternalCGLContext.java:92)
>
>         at
> jogamp.opengl.macosx.cgl.MacOSXCGLDrawableFactory.createExternalGLContextImpl(MacOSXCGLDrawableFactory.java:395)
>
>         at
> jogamp.opengl.GLDrawableFactoryImpl.createExternalGLContext(GLDrawableFactoryImpl.java:446)
>
>         at com.barelymoon.graphics.SWTSnippet.main(SWTSnippet.java:60)
>
> vs. the actual swt demo code:
>
> final GLProfile gl2Profile = GLProfile.get(GLProfile.GL2);
>                 final Display display = new Display();
>             Shell shell = new Shell(display);
>             shell.setLayout(new FillLayout());
>             Composite comp = new Composite(shell, SWT.NONE);
>             comp.setLayout(new FillLayout());
>             GLData data = new GLData ();
>             data.doubleBuffer = true;
>             final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);
>
>             canvas.setCurrent();
>            
>             final GLContext context =
> GLDrawableFactory.getFactory(gl2Profile).createExternalGLContext();
> ...
> which works correctly.
>
> Which is what led me to my work-around.
>
> Thanks,
> BC


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2 - SWT in MAC : cannot get GLContext

Brian Capozzi
Swen -

thanks much for the responses...

Will do re: git

Thanks,
BC
12