[JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

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

[JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

Djak
Hi,
it's me, again :)
I'm trying to share context within 2 GLCanvas and I got a problem.
Here is my old code working in 1.1.1 :
_____________________________________________________________________
GLCanvas canvas = new GLCanvas();
GLContext sharedContext = canvas.createContext(this.getGEngine().getContext());
_____________________________________________________________________

this.getGEngine().getContext() // return a GLContext from another GLCanvas

But this code doesn't work in JOGL2 because drawable member of class GLCanvas is null in :

_____________________________________________________________________
public GLContext createContext(GLContext shareWith) {
    return drawable.createContext(shareWith);
  }
_____________________________________________________________________

I found an alternative in adding the canvas in a frame :

_____________________________________________________________________
Frame f = new Frame();
f.add(canvas);
f.setSize(200, 200);
f.setVisible(true);
GLContext sharedContext = canvas.createContext(this.getGEngine().getContext());
_____________________________________________________________________

but actually I don't need a frame at this step.
Anyone may got a way to create a valid context on a GLCanvas without adding it to an AWT component ?

Thanks for the informations :)
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

gouessej
Administrator
Hi!

I have the same kind of problem with Ardor3D that I ported to JOGL 2 a few weeks ago. Which build of JOGL 2 do you use? Maybe we should write a bug report. Can you write a tiny testcase that was working on JOGL 1.1.1a and no more with JOGL 2 please?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

Djak
Hi,
Thanks, I use jogl-2.0-pre-20100924-windows-i586 build.
Here is a very tiny example :

__________________________________________________________________
Frame frame = new Frame("JOGL");
GLCanvas canvas = new GLCanvas();
canvas.setAutoSwapBufferMode(false);
frame.add(canvas);

...

GLCanvas canvas2 = new GLCanvas();
GLContext sharedContext = canvas2.createContext(canvas.getContext());
__________________________________________________________________

When I'll get more time, I'll do a test-case which compiles.
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

gouessej
Administrator
Please try to reproduce this problem with a more recent build.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

Djak
It's the same with jogl-2.0-pre-20101104-windows-i586.
I gonna try to make a test-case.
Bye
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

Djak
Actually, it seems than drawable member initialisation has been moved to addNotify() method of GLCanvas and not in constructor anymore :

JOGL2 :
__________________________________________________________________
 public void addNotify() {
    super.addNotify();
    if (!Beans.isDesignTime()) {
        disableBackgroundErase();

        if(null==device) {
            GraphicsConfiguration gc = super.getGraphicsConfiguration();
            if(null!=gc) {
                device = gc.getDevice();
            }
        }

        /*
* Save the chosen capabilities for use in getGraphicsConfiguration().
*/
        awtConfig = chooseGraphicsConfiguration(capabilities, chooser, device);
        if(DEBUG) {
            Exception e = new Exception("Created Config: "+awtConfig);
            e.printStackTrace();
        }
        if(null!=awtConfig) {
          // update ..
          chosen = awtConfig.getGraphicsConfiguration();

        }
        if(null==awtConfig) {
          throw new GLException("Error: AWTGraphicsConfiguration is null");
        }
        drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
        context = (GLContextImpl) drawable.createContext(shareWith);
        context.setSynchronized(true);

        if(DEBUG) {
            System.err.println("Created Drawable: "+drawable);
        }
        drawable.setRealized(true);
    }
  }
________________________________________________________________________________

JOGL 2
________________________________________________________________________________
 public GLCanvas(GLCapabilities capabilities,
                  GLCapabilitiesChooser chooser,
                  GLContext shareWith,
                  GraphicsDevice device) {
    super();

    if(null==capabilities) {
        capabilities = new GLCapabilities(defaultGLProfile);
    }
    glProfile = capabilities.getGLProfile();

    this.capabilities = capabilities;
    this.chooser = chooser;
    this.shareWith=shareWith;
    this.device = device;
  }
______________________________________________________________________________

JOGL 1.1.1

______________________________________________________________________________

 public GLCanvas(GLCapabilities glcapabilities, GLCapabilitiesChooser glcapabilitieschooser, GLContext glcontext, GraphicsDevice graphicsdevice)
    {
        drawableHelper = new GLDrawableHelper();
        autoSwapBufferMode = true;
        sendReshape = false;
        initAction = new InitAction();
        displayAction = new DisplayAction();
        swapBuffersAction = new SwapBuffersAction();
        displayOnEventDispatchThreadAction = new DisplayOnEventDispatchThreadAction();
        swapBuffersOnEventDispatchThreadAction = new SwapBuffersOnEventDispatchThreadAction();
        destroyAction = new DestroyAction();
        chosen = chooseGraphicsConfiguration(glcapabilities, glcapabilitieschooser, graphicsdevice);
        if(chosen != null)
        {
            glCapChooser = glcapabilitieschooser;
            glCaps = glcapabilities;
        }
        if(!Beans.isDesignTime())
        {
            drawable = GLDrawableFactory.getFactory().getGLDrawable(this, glcapabilities, glcapabilitieschooser);
            context = drawable.createContext(glcontext);
            context.setSynchronized(true);
        }
    }

_____________________________________________________________________________________________

But I'm not sure of what I'm saying and I don't know if it's a choice or an "error" :)
Reply | Threaded
Open this post in threaded view
|

Re: [JOGL1.1.1->JOGL2] Sharing context, drawable member of GLCanvas is null in createContext()

Djak
This post was updated on .
Hi,
cool, it works fine now with the jogl-2.0-b3-20101124-windows-i586 build
There's still something I wonder. I saw setSize() has been removed from GLDrawable. Actually, I usually resized my GLCanvas at initialization like this :
this.context.getGLDrawable().setSize(drawingSurfaceWidth, drawingSurfaceHeight);

this.context is a GLContext. But it may was a bad solution ?
Is still there a way to access and resize the GLCanvas (or other component) directly from the GLContext ?

Thanks in advance :)

(I know JOGL2 is on pre-release, so I hope I'm not bothering you with such questions, but maybe it's important to notify that at this point, I don't know :) )