Posted by
ZooChar on
Nov 03, 2015; 5:11pm
URL: https://forum.jogamp.org/Sharing-context-between-drawables-issues-tp4035716.html
Hello,
I'm working on an SWT, non-gaming 3D application. I have a standard view which works fine, using the SWT_AWT bridge. One of the features that were requested of me require creating some sort of a thumbnail output, so using an offscreen drawable seems ideal. However, I'm running into multiple strange issues.
This is how I declare the offscreen drawable:
GLCapabilities caps = new GLCapabilities(shared.profile);
caps.setOnscreen(false);
caps.setHardwareAccelerated(true);
caps.setDoubleBuffered(false);
caps.setBackgroundOpaque(false);
GLDrawableFactory factory = GLDrawableFactory.getFactory(shared.profile);
drawable = factory.createOffscreenAutoDrawable(factory.getDefaultDevice(), caps, null, width, height);
drawable.setSharedContext(shared.context);
shared is just a class that I pass through the constructor. I tried various changes in the above, but they don't seem to make a difference (for instance, I tried also passing the same capabilities).
Now, I use this code to create an output image (same class):
public BufferedImage renderImage() {
drawable.display();
AWTGLReadBufferUtil util = new AWTGLReadBufferUtil(drawable.getGLProfile(), true);
image = util.readPixelsToBufferedImage(drawable.getGL().getGL3(), 0, 0, width, height, true);
return image;
}
And this
seems to work fine, however, I get this in the console:
Info: GLReadBufferUtil.readPixels: pre-exisiting GL error 0x502
Using the debugging tools it seems that I get this error whenever I use anything that was bound to the GL3 object in the main view, like for example binding a buffer or a texture. The actual GL3 object in the offscreen drawable seems to be a different instance than the one in the standard 3D view. I don't know if it's supposed to be this way or not, or if the actual GL3 objects have to be identical.
So, here's another issue that I'm having that complicates things. I have this code in a different place (in a SWT thread):
ThumbnailFactory factory = new ThumbnailFactory(session, scene.getSharedData(), 240, 240);
BufferedImage image = factory.renderImage();
Calling this code a SECOND time does not display the previous error, however, the output does not change at all. No matter what I do, I always get the same image from renderImage(). This is very strange, especially considering everything is a different instance.
To fix this second issue, I simply keep a reference to the first ThumbnailFactory class and reuse it. I really don't mind doing that (it's a good idea anyway), but I need to understand why this is happening and what I can do to address it.
Thank you for your time!