If you set stereo_mode to 6 while running pymol embedded in a widget (via the 
pymol2 interface) pymol crashes.

This is because the code in pymol that figures out which screen lines get the 
left and right eyes assumes that pymol's OpenGL context was created with glut. 
The glut calls crash if the context was created some other way. 

I couldn't figure out an OpenGL only non-glut way to get the stencil parity 
(does anyone have any suggestions?), so instead the patch below adds a 
stereo_stencil_parity option to pymol. If stereo_stencil_parity is -1 (the 
default) pymol uses glut to figure out the stencil parity. If 
stereo_stencil_parity is 0 or 1 then pymol uses that value for the stencil 
party instead of trying to figure it out itself. This allows the embedding 
application to use its native windowing system to figure out the stencil party 
before calling pymol.draw.  For example, if embedding pymol in a qt widget....

class PymolQtWidget(QGLWidget):
    def paintGL(self):
        glViewport(0,0,self.width(), self.height())
        bottom = self.mapToGlobal(QtCore.QPoint(0,self.height())).y()
        self.pymol.cmd.set("stereo_stencil_parity", bottom & 0x1)
        self.pymol.draw()



Index: pymol/setting.py
===================================================================
--- pymol/setting.py    (revision 12330)
+++ pymol/setting.py    (revision 12332)
@@ -678,7 +678,7 @@
         heavy_neighbor_cutoff              = 639       # see 
wizard/measurement.py
         polar_neighbor_cutoff              = 640       # see 
wizard/measurement.py
         surface_residue_cutoff             = 641        # see menu.py
-        
+        stereo_stencil_parity              = 642
     setting_sc = Shortcut(SettingIndex.__dict__.keys())
     
     index_list = []
Index: src/layer0/PyMOLOptions.h
===================================================================
--- src/layer0/PyMOLOptions.h   (revision 12330)
+++ src/layer0/PyMOLOptions.h   (revision 12332)
@@ -37,7 +37,7 @@
 
   int multisample, window_visible, read_stdin, presentation, 
defer_builds_mode, full_screen, sphere_mode, stereo_capable,       /* for 
informing PyMOL as to the capabilities of the context */
     stereo_mode, zoom_mode, no_quit;    /* prevent any action from quitting or 
killing PyMOL */
-  
+  int stereo_stencil_parity;
   /* WARNING: for the sake of forward compability, never delete or
      move any fields in the above ...initialization struct in PyMOL.c */
 
Index: src/layer1/Setting.c
===================================================================
--- src/layer1/Setting.c        (revision 12330)
+++ src/layer1/Setting.c        (revision 12332)
@@ -697,6 +697,7 @@
   float fast_idle = SettingGetGlobal_f(G, cSetting_slow_idle);
   int mouse_grid = SettingGetGlobal_b(G, cSetting_mouse_grid);
   int mouse_z_scale = SettingGetGlobal_i(G,cSetting_mouse_scale);
+  int stereo_stencil_parity=SettingGetGlobal_i(G, 
cSetting_stereo_stencil_parity);
   register CSetting *I = G->Setting;
   if(list)
     if(PyList_Check(list))
@@ -741,7 +742,7 @@
   if(G->Option->no_quit) {
     SettingSet_b(I, cSetting_presentation_auto_quit, 0);
   }
-
+ SettingSet_i(I, cSetting_stereo_stencil_parity, stereo_stencil_parity);
 #ifdef _PYMOL_ACTIVEX
   SettingSet_i(I, cSetting_max_threads, 1);
   SettingSet_b(I, cSetting_async_builds, 0);
@@ -3908,5 +3909,6 @@
     set_f(I, cSetting_heavy_neighbor_cutoff, 3.5F);
     set_f(I, cSetting_polar_neighbor_cutoff, 3.5F);
     set_f(I, cSetting_surface_residue_cutoff, 2.5F);
+    set_i(I, cSetting_stereo_stencil_parity, G->Option->stereo_stencil_parity);
   }
 }
Index: src/layer1/Setting.h
===================================================================
--- src/layer1/Setting.h        (revision 12330)
+++ src/layer1/Setting.h        (revision 12332)
@@ -875,6 +875,7 @@
 #define cSetting_heavy_neighbor_cutoff      639
 #define cSetting_polar_neighbor_cutoff      640
 #define cSetting_surface_residue_cutoff     641
+#define cSetting_stereo_stencil_parity      642
 
 /* when you add a new setting also remember:
    layer1/Setting.c
@@ -885,7 +886,7 @@
 
 /* cSetting_ss_INIT must always be last setting_index +1 */
 
-#define cSetting_INIT                       641
+#define cSetting_INIT                       643
 
 
 #endif
Index: src/layer1/P.c
===================================================================
--- src/layer1/P.c      (revision 12330)
+++ src/layer1/P.c      (revision 12332)
@@ -1969,6 +1969,7 @@
   rec->stereo_mode = PyInt_AsLong(PyObject_GetAttrString(options, 
"stereo_mode"));
   rec->zoom_mode = PyInt_AsLong(PyObject_GetAttrString(options, "zoom_mode"));
   rec->no_quit = PyInt_AsLong(PyObject_GetAttrString(options, "no_quit"));
+  rec->stereo_stencil_parity = PyInt_AsLong(PyObject_GetAttrString(options, 
"stereo_stencil_parity"));
 
   if(load_str) {
     if(load_str[0]) {
Index: src/layer1/Scene.c
===================================================================
--- src/layer1/Scene.c  (revision 12330)
+++ src/layer1/Scene.c  (revision 12332)
@@ -7180,8 +7180,12 @@
 {
   register CScene *I = G->Scene;
   if( I->StereoMode == cStereo_stencil_by_row ) {
-    int bottom = p_glutGet(P_GLUT_WINDOW_Y) + p_glutGet(P_GLUT_WINDOW_HEIGHT);
-    int parity = bottom & 0x1;
+    int parity = (int) SettingGet(G, cSetting_stereo_stencil_parity);
+    if (parity == -1)
+    {
+        int bottom = p_glutGet(P_GLUT_WINDOW_Y) + 
p_glutGet(P_GLUT_WINDOW_HEIGHT);
+        int parity = bottom & 0x1;
+    }
     if(parity != I->StencilParity) {
       I->StencilValid = false;
       I->StencilParity = parity;
Index: src/layer5/PyMOL.c
===================================================================
--- src/layer5/PyMOL.c  (revision 12330)
+++ src/layer5/PyMOL.c  (revision 12332)
@@ -813,6 +813,7 @@
   ov_word lex_heavy_neighbor_cutoff;
   ov_word lex_polar_neighbor_cutoff;
   ov_word lex_surface_residue_cutoff;
+  ov_word lex_stereo_stencil_parity;
 } _CPyMOL;
 
 
@@ -1614,6 +1615,7 @@
   LEX_SETTING(heavy_neighbor_cutoff, 639);
   LEX_SETTING(polar_neighbor_cutoff, 640);
   LEX_SETTING(surface_residue_cutoff, 641);
+  LEX_SETTING(stereo_stencil_parity, 642);
   return_OVstatus_SUCCESS;
 }
 
@@ -2839,6 +2841,7 @@
   0,                            /* stereo mode */
   -1,                           /* zoom mode */
   0,                            /* no quit */
+  -1,                           /* stereo stencil parity */
 };
 
 CPyMOLOptions *PyMOLOptions_New(void)

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
PyMOL-users mailing list ([email protected])
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/[email protected]

Reply via email to