How to share context between GLAutoDrawable and GLOffscreenAutoDrawable

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

How to share context between GLAutoDrawable and GLOffscreenAutoDrawable

voyta
Hi,
is there any way to share context between GLAutoDrawable and GLOffscreenAutoDrawable?

I tried following code:

   public static void main(String[] args) {
       
      // profile and capabilities
      GLProfile glProfile = GLProfile.getDefault();
      GLCapabilities caps = new GLCapabilities(glProfile);
      caps.setHardwareAccelerated(false);
      caps.setOnscreen(false);
 
      // shared drawable
      GLAutoDrawable sharedDrawable = GLDrawableFactory.getFactory(glProfile).createDummyAutoDrawable(null, true, caps, null);
      sharedDrawable.display();

      // offscreen drawable
      GLOffscreenAutoDrawable offscreenDrawable = GLDrawableFactory.getFactory(glProfile).createOffscreenAutoDrawable(null, caps, null, 300, 300);
     
      // share context
      offscreenDrawable.setSharedAutoDrawable(sharedDrawable);
      offscreenDrawable.display();
     
      GLContext ctx = offscreenDrawable.getContext();
      ctx.makeCurrent();
     
      // render some picture
      GL2 gl = offscreenDrawable.getGL().getGL2();    
      gl.glBegin (GL2.GL_LINES);//static field
      gl.glVertex3f(0.50f,-0.50f,0);
      gl.glVertex3f(-0.50f,0.50f,0);
      gl.glEnd();
     
      // save to file
      BufferedImage im = new AWTGLReadBufferUtil(offscreenDrawable.getGLProfile(), false).readPixelsToBufferedImage(offscreenDrawable.getGL(), 0, 0, 400, 400, true);
      try {
        boolean bb = ImageIO.write(im,"png",new File("im.png"));
      } catch (IOException ex) {
        Logger.getLogger(OffscreenFrame.class.getName()).log(Level.SEVERE, null, ex);
      }
   }
   
This works as intended when I use hardware accreleration. But when I turn off my graphic card (and use GDI Generic instead), it gives me following error:

Exception in thread "main" com.jogamp.opengl.GLException: wglShareLists(0x10001, 0x10002) failed: werr 0
        at jogamp.opengl.windows.wgl.WindowsWGLContext.createImpl(WindowsWGLContext.java:424)
        at jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:763)
        at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:648)
        at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:586)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1279)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
        at jogamp.opengl.GLAutoDrawableBase.defaultDisplay(GLAutoDrawableBase.java:467)
        at com.jogamp.opengl.GLAutoDrawableDelegate.display(GLAutoDrawableDelegate.java:190)
        at offscreenRender.OffscreenFrame.main(OffscreenFrame.java:51)
       
Thanks,
Vojta
Reply | Threaded
Open this post in threaded view
|

Re: How to share context between GLAutoDrawable and GLOffscreenAutoDrawable

gouessej
Administrator
Hi

Microsoft GDI renderer isn't very reliable, there is probably nothing we can do to make it work better. Moreover, display lists are poorly implemented in numerous drivers, it's not new, it was already the case more than ten years ago, you should use another mean of storing unchanged or rarely changed geometry.
Julien Gouesse | Personal blog | Website