Multiple AWTGLCanvas'es sharing the same OpenGL context?

Started by Kai, January 23, 2009, 16:02:32

Previous topic - Next topic

Kai

Hi,

is it somehow possible to create multiple JFrame's with AWTGLCanvas'es that are sharing the same OpenGL context and not only the display lists?

What I want to achieve is a multi-screen application (all windows show the same scene) but without having to duplicate everything (texture objects, VBOs, shader programs, other states) for each canvas.
So whenever I generate a new VBO it should be accessible from any canvas.

I inspected the AWTGLCanvas class and it generates a new Context for each canvas.
Contexts can be shared but the X-server documentation states that with glXCreateNewContext (which will be invoked in that case) only display lists get shared.

So, is the sharing of all OpenGL context state even possible when having multiple windows?

Kai

I clearly shoud've read some of the OpenGL extensions specifications, which I did now :-), to find that nearly everything gets shared among multiple contexts (and not only display lists).
These are:
- Texture objects
- Shader Objects / Programs
- Framebuffer Objects
- Vertex Buffer Objects
- (... maybe some more but I only rely on these above)
Note that only all properties of these objects will be shared but not which of them are bound on each context!
(I struggled with that after building up an example application that creates multiple windows but only create one shared VBO that will be rendered in each window separately.)

So this thread has now merely become an information for those of you who want to do such stuff, too :-).

DanDanger

Here is the basic code i use to create a shared opengl canvas.
MetalViewGL.create () creates canvases which all share the same context.



public class MetalViewGL extends AWTGLCanvas
{
	static public PixelFormat pf;
	static public GraphicsDevice gd;
	static public Drawable sd;
	
	static MetalViewGL create ()
	{
		try
		{
			if ( gd == null )
			{
				gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
				pf = new PixelFormat();
			}
			
			MetalViewGL out = new MetalViewGL();
			if ( sd == null )
				sd = out;
			return out;
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return null;
	}
	
	private MetalViewGL() throws LWJGLException
	{
		super(gd, pf,sd);
	}
}