Multiple GlCanvases sharing ogl data (textures, vbos etc)

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

Multiple GlCanvases sharing ogl data (textures, vbos etc)

GiGurra
This post was updated on .
I've got an application with a couple of windows, and different windows which are often rendering the same shapes.
Currently I make use of vbos, one VBO per shape per window to store geometry in video memory, and I'm looking for a way for only storing each shape once in the video mem (only one VBO per shape).

From what I've google out, this can be done by either

1. Sharing data among contexts
or
2. Rendering to multiple drawables from a single context.

1, attempts: I tried #1 but I got problems. I tried creating a master context that would never be shut down by preallocating a final static GlContext with a simple new GlCanvas(capab).getContext(); This method though didn't work - The context seems to be created but when I create new GlCanvases with new GlCanvas(capab, masterCtx) they refused to share the VBOs (JVM crashes :().

My next attempt at it was saving a reference to the last created context and sending that as a "share with" pointer to the next Canvas to be created (new GlCanvas(capab, lastCtx)) - This worked, until I started shutting down some of the GlCanvases and then created new ones. Then for some reason I got JVM crashes.

Thirdly I tried saving the first ever created context from a GlCanvas, but that resulted in the same thing: Sharing worked fine when adding multiple new windows with new GlCanvas(capab, firstCtx), but as soon as I deleted one of them or more, and then created a new canvas I get JVM crashes.

2, I have not attempted: How would I go about using a single context to render on multiple drawables? I am not very good with openGL so I am not sure I understand what this actually means.

Both methods 1 and 2 seem fine to me if I can understand how to make them work with a couple of windows, do you know if there are any JOGL tutorials for this type of thing? My main issue seems to be that sharing goes nuts when I start shutting down windows and then recreating them.


----

Example:

1. I create canvas1. canvas1 allocates some VBOs on its context.
2. Then I create Canvas 2 with new GlCanvas(capab, canvas1.getContext())
3. Now I shut down canvas1 (my dispose method is empty on my listener)
4. I start a new canvas, canvas3. Both "new GlCanvas(capab, canvas1.getContext())" and "new GlCanvas(capab, canvas2.getContext())" result in JVM crashes





------------
UPDATE:  Nevm I was an idiot and now I solved it :). Method #1 working. Excellent!
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GlCanvases sharing ogl data (textures, vbos etc)

gouessej
Administrator
Hi!

Your first method works but if the context is lost for example when hiding a GLCanvas, you lose all your data. I advise you to use NEWT to avoid this situation. In my case, I wanted to share the data between a decorated window and a fullscreen window.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GlCanvases sharing ogl data (textures, vbos etc)

GiGurra
Thanks, I solved it by letting the program be aware of what windows are still active. If all windows are killed then all opengl "pointers" are cleared from java-side shared state. When creating a new window I check if there are any alive and reference that context as a sharewith. Little bit of extra bookkeeping but worth it for the performance gains :).
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GlCanvases sharing ogl data (textures, vbos etc)

GiGurra
This post was updated on .
In reply to this post by gouessej
Question:

if I use a NEWT window (GlWindow), create it, set visible, get its context, then set it to visible->false.
Will the context still be OK? until I destroy it? If so I could have an invisible newt window as a kind of base context... (This doesnt work with CLCanvas from AWT)
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GlCanvases sharing ogl data (textures, vbos etc)

gouessej
Administrator
If you hide a NEWT window, the context can still be used. If you destroy it, the context might be destroyed if it is not shared. Sven, can you confirm this?
Julien Gouesse | Personal blog | Website