Can anyone tell me if I’m following the best practice in using offscreen buffers (pbuffers) and threads in the following senario. I have some objects that will render different layers. At a certain moment I need to display these layers and so I set a flag
buildTerrainLayer=true;
and call the GLCanvas display method:
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
glcanvas.display();
}
});
This will call the main display method which has the following code inside:
if (buildTerrainLayer)
{
buildTerrainLayer = false;
OffscreenRenderManager.buildTerrainLayer(drawable);
return;
}
…
Map texture to texture coordinates and display;
The OffscreenRenderManager will build the layer using pbuffers and copy the layer to a shared texture id and at the end of that process will call the glcanvas.display method, which will then display the texture image on the glcanas.
My question is, can I spawn the OffscreenRenderManager to another thread so it will build the layers image lazily and then copy this to the texture id shared between the main glcanavas and the pbuffer canvas, and then when that is finished request a refresh of the main glcanvas display, or is it necessary for the pbuffer code to run in the same thread as the main glcanvas display. What is the best practice where shared context’s and pbuffers and the main glcanvas are concerned.