[XForms] Patch: GLCanvas context sharing support.

jason cipriani jac4 at mindless.com
Fri May 14 15:31:01 EDT 2004


> Jason, Maybe I'm being slow, but I don't see why we need
> this patch -  can you give an example of how you would 
> use it.

AGL, GLX, and wGL all support GL context sharing. When two GL contexts are shared, what this means is that they share the same call list and (for GL >= 1.1) texturing namespaces. So, if you have a form with 4 GL canvases on it, the way it is now, and you want to display the same, say, 60K+ polygon surface model on all 4 canvases, you need to create 4 separate call lists. So you need to store the same call list in memory 4 times, and you need to take the time to generate 4 identical call lists. And if you have the same texture that you want to display on all 4 canvases, you have to load the same texture 4 times. Same deal.

For example (as far as texturing goes), if you wanted to display captured video on a surface, you may choose to copy the captured image to texture mapped memory to update that texture and display the video. Your frame rate -will- suffer if you have to load the same image into memory 4 times simply because you have 4 separate GL canvases. Also, in applications with huge amounts of textures, memory -does- become an issue when you have to load the same textures into memory 2, 3, or more times.

Context sharing, as far as XForms goes, allows you to use the same call lists and textures for multiple GL canvases. When you think about the impact this has on the amount of memory your application uses and the amount of time you have to spend processing call lists and textures, the benefits are clear. As a matter of fact, GLX makes it simple to share contexts: the glXCreateContext function can actually take, as a parameter, another context which you want to share data with. Problem is, of course, the XForms GL canvas doesn't provide a way for you to specify a context to share data with.

Also note that you can't begin sharing contexts after both contexts are created. You have to specify the context to share data with at the time you create a new context, so it's not something that you can do with GLX calls after you have already created and displayed the GL canvases. glXCopyContext will create a copy of the context but the new context will not share the same call list and texture namespace as the one it was copied from, and you cannot specify a context to share data with in the glXCopyContext call. It -must- be done in the glXCreateContext call. Even if glXCopyContext did work, there currently exists no clean way to change the GLXContext of a GL canvas, as far as I know, although you can "change" it by directly modifying the data in the GL canvases CSPEC.

> This definition doesn't always work - for example NVIDIA
> defines its glx.h file differently, so you have to have
> ...
> for glcanvas to work. Clearly not a good thing if we have to
> alter the test to cover all the internal structures of various
> vendor's glx.h files. 

Absolutely true. We use nVidia cards here and when we set up a new machine with XForms 1.0 we have to go modify forms.h to check for nVidia's glx.h defines. Dirty but, that's the way it was done, and now we have a whole bunch of apps that don't explicitly #include glcanvas.h. Angus wrote:

> #ifdef FORM_GLCANVAS_H
> #include FORM_GLCANVAS_H
> #endif
> 
> where FORM_GLCANVAS_H is defined either in your <config.h> file for 
> the project or is passed via a -D flag on the compiler command.

Which is a much better way to do it, and I think that forms.h should have that in it in the next release. What I wrote was a quick fix and actually what I am doing now is using a modified forms.h that just includes <GL/glx.h> and then includes <glcanvas.h> without checking for anything. Dirty but it works on my machine. Angus' way allows the least breaking of existing apps (in my case, I have some common make include files for everything so adding a -DFORM_GLCANVAS_H is trivial) while at the same time not relying on vendor-specific #defines in glx.h.

Hope that makes sense,
Jason
-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm




More information about the Xforms mailing list