[XForms] Patch: GLCanvas context sharing support.

jason cipriani jac4 at mindless.com
Thu May 13 18:21:06 EDT 2004


This patch allows support for context sharing in GLCanvases, a feature which should have been in there long, long ago. Not tested because something about 1.0.90 seems to have broken the GLCanvas stuff entirely (as in, none of the GLCanvas functions are in forms.h any more). So I'll have to get to the bottom of that first. In the mean time, here is the patch (glcanvas.c/glcanvas.h), if anybody has a version of 1.0.90 with working GLCanvases.

GLCanvases that share the same GLX Context will share GL call lists and (for GL version >= 1.1) textures.

TODO: Add support to fdesign for using shared GLCanvases.


--- orig/glcanvas.c     2004-05-13 17:43:51.000000000 -0400
+++ glcanvas.c  2004-05-13 17:57:37.000000000 -0400
@@ -38,6 +38,12 @@
  *   See ../DEMOS/gl.c for an example use of glcanvas.
  *   See ../DEMOS/glwin.c for an example use of fl_glwinopen
  *
+ *  13-may-2004: jason cipriani (jac4 at mindless.com):
+ *    - added support for glx context sharing.
+ *    - added the following functions:
+ *      - fl_add_glcanvas_shared()
+ *      - fl_create_glcanvas_shared()
+ *      - fl_get_glcanvas_shared_context()
  */
  
 #if defined(F_ID) || defined(DEBUG)
@@ -59,6 +65,7 @@
 {
     XVisualInfo *xvinfo;
     GLXContext context;
+    GLXContext context_shared; // Context to share data with.
     int direct;
     int glconfig[MAXATTRIB];
 }
@@ -91,7 +98,15 @@
 fl_add_glcanvas(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
                const char *label)
 {
-    FL_OBJECT * ob = fl_create_glcanvas(type, x, y, w, h, label);
+    return fl_add_glcanvas_shared(type, x, y, w, h, label, NULL);
+}
+
+FL_OBJECT *
+fl_add_glcanvas_shared (int type, FL_Coord x, FL_Coord y, FL_Coord w,
+                       FL_Coord h, const char *label, FL_OBJECT *shared_with)
+{
+    FL_OBJECT * ob = fl_create_glcanvas_shared(type, x, y, w, h, label,
+                                              shared_with);
     fl_add_object(fl_current_form, ob);
     return ob;
 }
@@ -151,6 +166,12 @@
     return GLPROP(ob)->context;
 }
  
+GLXContext
+fl_get_glcanvas_shared_context (FL_OBJECT *ob)
+{
+    return GLPROP(ob)->context_shared;
+}
+
 XVisualInfo *
 fl_get_glcanvas_xvisualinfo(FL_OBJECT * ob)
 {
@@ -169,15 +190,38 @@
 fl_create_glcanvas(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
                   const char *label)
 {
+    return fl_create_glcanvas_shared(type, x, y, w, h, label, NULL);
+}
+
+/* GLCanvas with context sharing. */
+FL_OBJECT *
+fl_create_glcanvas_shared(int type, FL_Coord x, FL_Coord y, FL_Coord w,
+                         FL_Coord h, const char *label, FL_OBJECT *shared_with)
+{
     FL_OBJECT *ob = fl_create_canvas(type, x, y, w, h, label);
+    GLXContext sctx;
  
     ob->objclass = FL_GLCANVAS;
     fl_modify_canvas_prop(ob, glx_init, glx_activate, glx_cleanup);
  
+    /* figure out glx context to share with. if shared_with is NULL or if it's
+     * not a GL canvas, then we can't do sharing. otherwise, the gl context to
+     * share with is chosen as follows:
+     *   - if shared_with is also sharing data with another glx context, use
+     *     the glx context shared_with is sharing data with, otherwise...
+     *   - use shared_with's actual glx context.
+     */
+    if (shared_with && shared_with->objclass == FL_GLCANVAS) {
+      if (!(sctx = fl_get_glcanvas_shared_context(shared_with)))
+       sctx = fl_get_glcanvas_context(shared_with);
+    } else
+      sctx = NULL;
+
     /* initialize glcanvas specific stuff */
     ob->c_vdata = fl_calloc(1, sizeof(CSPEC));
     memcpy(GLPROP(ob)->glconfig, glconfig, sizeof(glconfig));
     GLPROP(ob)->direct = GL_TRUE;
+    GLPROP(ob)->context_shared = sctx;
  
     return ob;
 }
@@ -208,7 +252,8 @@
     fl_set_canvas_depth(ob, vi->depth);
     fl_set_canvas_colormap(ob, fl_create_colormap(vi, 1));
  
-    context = glXCreateContext(fl_display, vi, None, GLPROP(ob)->direct);
+    context = glXCreateContext(fl_display, vi, GLPROP(ob)->context_shared,
+                              GLPROP(ob)->direct);
  
     if (!context)
     {



--- orig/glcanvas.h     2004-05-13 17:43:51.000000000 -0400
+++ glcanvas.h  2004-05-13 17:46:55.000000000 -0400
@@ -11,6 +11,15 @@
                const char *label
                );
  
+FL_EXPORT FL_OBJECT *fl_create_glcanvas_shared (
+               int type,
+               FL_Coord x,
+               FL_Coord y,
+               FL_Coord w,
+               FL_Coord h,
+               const char *label,
+               FL_OBJECT *shared_with
+               );
  
 FL_EXPORT FL_OBJECT *fl_add_glcanvas(
                int type,
@@ -21,6 +30,16 @@
                const char *label
                );
  
+FL_EXPORT FL_OBJECT *fl_add_glcanvas_shared (
+               int type,
+               FL_Coord x,
+               FL_Coord y,
+               FL_Coord w,
+               FL_Coord h,
+               const char *label,
+               FL_OBJECT *shared_with
+               );
+
  
 FL_EXPORT void fl_set_glcanvas_defaults(
                const int *config
@@ -58,6 +77,10 @@
                FL_OBJECT *ob
                );
  
+FL_EXPORT GLXContext fl_get_glcanvas_shared_context (
+               FL_OBJECT *ob
+               );
+
 FL_EXPORT Window fl_glwincreate(
                int *config,
                GLXContext *context,

-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: glcanvas.diff.tgz
Type: application/octet-stream
Size: 1518 bytes
Desc: not available
Url : attachments/20040513/ccec6cc0/attachment-0010.obj 


More information about the Xforms mailing list