g4tools  5.4.0
Static Public Member Functions | Static Protected Member Functions | List of all members
tools::Xt::OpenGLArea Class Reference

Static Public Member Functions

static void paint (Widget a_this)
 
static WidgetClass widget_class ()
 

Static Protected Member Functions

static void initialize_class (void)
 
static void initialize_widget (Widget a_request, Widget a_this, ArgList, Cardinal *)
 
static void realize_widget (Widget a_this, XtValueMask *a_mask, XSetWindowAttributes *a_watbs)
 
static void destroy_widget (Widget a_this)
 
static Boolean set_values (Widget a_current, Widget, Widget a_this, ArgList, Cardinal *)
 
static void change_widget_size (Widget a_this)
 
static void draw_widget (Widget a_this, XEvent *a_event, Region a_region)
 
static OpenGLAreaPart_athis (Widget a_this)
 
static void CWarn (const char *a_msg)
 
static void CWarnF (const char *a_format,...)
 
static int make_current (Widget a_this)
 
static void event_handler (Widget a_this, XtPointer, XEvent *a_event, Boolean *)
 
static void install_colormap (Widget a_this)
 
static void uninstall_colormap (Widget a_this)
 
static Widget get_shell (Widget a_this)
 

Detailed Description

Definition at line 73 of file OpenGLArea.

Member Function Documentation

◆ _athis()

static OpenGLAreaPart& tools::Xt::OpenGLArea::_athis ( Widget  a_this)
inlinestaticprotected

Definition at line 299 of file OpenGLArea.

299 {return *(&(((OpenGLAreaWidget)a_this)->openGLArea));}

◆ change_widget_size()

static void tools::Xt::OpenGLArea::change_widget_size ( Widget  a_this)
inlinestaticprotected

Definition at line 259 of file OpenGLArea.

259  {
260 #ifdef OPENGLAREA_DEBUG
261  printf("debug : OpenGLArea : change_widget_size : %s\n",XtName(a_this));
262 #endif
263 
264  // Call the Resize procedure (XtInheritResize) :
265  if(widget_class()->core_class.superclass->core_class.resize!=NULL)
266  (widget_class()->core_class.superclass->core_class.resize)(a_this);
267 
268 #ifdef OPENGLAREA_DEBUG
269  printf("debug : OpenGLArea : change_widget_size : end\n");
270 #endif
271 }

◆ CWarn()

static void tools::Xt::OpenGLArea::CWarn ( const char *  a_msg)
inlinestaticprotected

Definition at line 300 of file OpenGLArea.

300  {
301  ::printf("%s",a_msg);
302  }

◆ CWarnF()

static void tools::Xt::OpenGLArea::CWarnF ( const char *  a_format,
  ... 
)
inlinestaticprotected

Definition at line 303 of file OpenGLArea.

303  {
304  va_list args;
305  va_start(args,a_format);
306  ::vprintf(a_format,args);
307  va_end(args);
308  }

◆ destroy_widget()

static void tools::Xt::OpenGLArea::destroy_widget ( Widget  a_this)
inlinestaticprotected

Definition at line 224 of file OpenGLArea.

224  {
225 #ifdef OPENGLAREA_DEBUG
226  printf("debug : OpenGLArea : destroy_widget : begin\n");
227 #endif
228  OpenGLAreaPart& athis = _athis(a_this);
229  if(athis.installColormap==True) {
230  uninstall_colormap (a_this);
231  athis.installColormap = False;
232  ::XFreeColormap(XtDisplay(a_this),a_this->core.colormap);
233  }
234  if(athis.glContext!=NULL) {
235  ::glXMakeCurrent(XtDisplay(a_this),None,NULL);
236  ::glXDestroyContext(XtDisplay(a_this),athis.glContext);
237  athis.glContext = NULL;
238  }
239 #ifdef OPENGLAREA_DEBUG
240  printf("debug : OpenGLArea : destroy_widget : end\n");
241 #endif
242  }

◆ draw_widget()

static void tools::Xt::OpenGLArea::draw_widget ( Widget  a_this,
XEvent *  a_event,
Region  a_region 
)
inlinestaticprotected

Definition at line 273 of file OpenGLArea.

273  {
274 #ifdef OPENGLAREA_DEBUG
275  printf("debug : OpenGLArea : draw_widget : %s\n",XtName(a_this));
276 #endif
277 
278  if(widget_class()->core_class.superclass->core_class.expose!=NULL)
279  (widget_class()->core_class.superclass->core_class.expose)(a_this,a_event,a_region);
280 
281  if(make_current(a_this)==1) {
282 #ifdef OPENGLAREA_DEBUG
283  printf("debug : OpenGLArea : draw_widget : %s : make_current ok : call paintCallback...\n",XtName(a_this));
284 #endif
285  XoAnyCallbackStruct value;
286  value.reason = XoCR_PAINT;
287  value.event = a_event;
288  ::XtCallCallbacks(a_this,XoNpaintCallback,(XtPointer)&value);
289  ::glXSwapBuffers(XtDisplay(a_this),XtWindow(a_this));
290  ::glXMakeCurrent(XtDisplay(a_this),None,NULL);
291  }
292 
293 #ifdef OPENGLAREA_DEBUG
294  printf("debug : OpenGLArea : draw_widget : end\n");
295 #endif
296  }

◆ event_handler()

static void tools::Xt::OpenGLArea::event_handler ( Widget  a_this,
XtPointer  ,
XEvent *  a_event,
Boolean *   
)
inlinestaticprotected

Definition at line 316 of file OpenGLArea.

316  {
317  XoAnyCallbackStruct value;
318  value.reason = XoCR_EVENT;
319  value.event = a_event;
320  ::XtCallCallbacks(a_this,XoNeventCallback,(XtPointer)&value);
321  }

◆ get_shell()

static Widget tools::Xt::OpenGLArea::get_shell ( Widget  a_this)
inlinestaticprotected

Definition at line 406 of file OpenGLArea.

406  {
407  Widget widget = a_this;
408  while(1) {
409  if(widget==NULL) return NULL;
410  if(XtIsShell(widget)) return widget;
411  widget = XtParent(widget);
412  }
413  }

◆ initialize_class()

static void tools::Xt::OpenGLArea::initialize_class ( void  )
inlinestaticprotected

Definition at line 87 of file OpenGLArea.

87 {}

◆ initialize_widget()

static void tools::Xt::OpenGLArea::initialize_widget ( Widget  a_request,
Widget  a_this,
ArgList  ,
Cardinal *   
)
inlinestaticprotected

Definition at line 89 of file OpenGLArea.

89  {
90  if(a_request->core.width<=0) a_this->core.width = 100;
91  if(a_request->core.height<=0) a_this->core.height = 100;
92 
93 #ifdef OPENGLAREA_DEBUG
94  ::printf ("debug : OpenGLArea : InitializeWidget : %s\n",::XtName(a_this));
95 #endif
96 
97  OpenGLAreaPart& athis = _athis(a_this);
98  athis.visual = CopyFromParent;
99  athis.installColormap = False;
100  athis.glContext = NULL;
101 
102  Display* display;
103  Screen* screen;
104  int iscreen;
105  XVisualInfo* vinfo;
106  display = XtDisplay(a_this);
107  screen = XtScreen(a_this);
108  iscreen = XScreenNumberOfScreen(screen);
109 
110  {int error,event;
111  if(::glXQueryExtension(display,&error,&event)==0) {
112  CWarn ("X server does not have OpenGL extensions.\n");
113  }}
114 
115  if(athis.doubleBufferOn==True) {
116  int atbs_1[] = {
117  GLX_RGBA,
118  GLX_RED_SIZE, 1,
119  GLX_GREEN_SIZE, 1,
120  GLX_BLUE_SIZE, 1,
121  GLX_ALPHA_SIZE, 1,
122  GLX_DEPTH_SIZE, 1,
123  GLX_DOUBLEBUFFER,
124  None
125  };
126  vinfo = ::glXChooseVisual (display,iscreen,atbs_1);
127  if(vinfo==NULL) { //GLX_ALPHA_SIZE : problem with Xming. Try without it.
128  int atbs_2[] = {
129  GLX_RGBA,
130  GLX_RED_SIZE, 1,
131  GLX_GREEN_SIZE, 1,
132  GLX_BLUE_SIZE, 1,
133  GLX_DEPTH_SIZE, 1,
134  GLX_DOUBLEBUFFER,
135  None
136  };
137  vinfo = ::glXChooseVisual (display,iscreen,atbs_2);
138  }
139  } else {
140  int atbs_1[] = {
141  GLX_RGBA,
142  GLX_RED_SIZE, 1,
143  GLX_GREEN_SIZE, 1,
144  GLX_BLUE_SIZE, 1,
145  GLX_ALPHA_SIZE, 1,
146  GLX_DEPTH_SIZE, 1,
147  None
148  };
149  vinfo = ::glXChooseVisual (display,iscreen,atbs_1);
150  if(vinfo==NULL) { //GLX_ALPHA_SIZE : problem with Xming. Try without it.
151  int atbs_2[] = {
152  GLX_RGBA,
153  GLX_RED_SIZE, 1,
154  GLX_GREEN_SIZE, 1,
155  GLX_BLUE_SIZE, 1,
156  GLX_DEPTH_SIZE, 1,
157  None
158  };
159  vinfo = ::glXChooseVisual (display,iscreen,atbs_2);
160  }
161  }
162 
163  if(vinfo==NULL) {
164  CWarn ("Can't choose a visual.\n");
165  } else {
166  a_this->core.depth = vinfo->depth;
167  athis.visual = vinfo->visual;
168  if( (vinfo->depth ==DefaultDepth (display,iscreen)) &&
169  (vinfo->visual==DefaultVisual(display,iscreen)) ) {
170  a_this->core.colormap = XDefaultColormap (display,iscreen);
171  athis.installColormap = False;
172  } else {
173  a_this->core.colormap =
174  XCreateColormap (display,XRootWindow(display,iscreen),vinfo->visual, AllocNone);
175  athis.installColormap = True;
176  }
177  if(a_this->core.colormap==0L) {
178  CWarn ("Can't get/create a X colormap.\n");
179  }
180  athis.glContext = ::glXCreateContext (display,vinfo,NULL,GL_TRUE);
181  if(athis.glContext==NULL) {
182  athis.glContext = ::glXCreateContext (display,vinfo,NULL,GL_FALSE);
183  if(athis.glContext==NULL) {
184  CWarn ("Can't create a GLX context.\n");
185  }
186  }
187  ::XFree(vinfo);
188  }
189 
190  ::XtAddEventHandler
191  (a_this,ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask|KeyReleaseMask,0,event_handler,NULL);
192 
193 #ifdef OPENGLAREA_DEBUG
194  printf("debug : OpenGLArea : InitializeWidget : end\n");
195 #endif
196  }

◆ install_colormap()

static void tools::Xt::OpenGLArea::install_colormap ( Widget  a_this)
inlinestaticprotected

Definition at line 323 of file OpenGLArea.

323  {
324  // From Mesa/widgets/GLwDrawingArea.c/post_colormap routine.
325  // Could use also XtSetWMColormapWindows.
326  if( !XtIsWidget(a_this) || !XtIsRealized(a_this) ) return;
327  Widget shell = get_shell(a_this);
328  if(shell==NULL) return;
329  Display* display = XtDisplay (a_this);
330  Window wthis = XtWindow (a_this);
331  Window wshell = XtWindow (shell);
332  Window* ws = NULL;
333  int wn = 0;
334  ::XGetWMColormapWindows (display,wshell, &ws, &wn);
335  // Check if colormap of this is a colormap of a Window in list :
336  XWindowAttributes watbs;
337  XGetWindowAttributes (display,wthis,&watbs);
338  Colormap cmapthis = watbs.colormap;
339  int found = -1;
340  for(int count=0;count<wn;count++) {
341  Colormap cmap;
342  XGetWindowAttributes (display,ws[count],&watbs);
343  cmap = watbs.colormap;
344  if(cmap==cmapthis) {
345  ::XFree (ws);
346  return;
347  }
348  if(ws[count]==wshell) {
349  found = count;
350  }
351  }
352  // Have to add window of this in list :
353  if(wn==0) {
354  if(ws!=NULL) ::XFree(ws);
355  ws = (Window*)::malloc( 2 * sizeof(Window));
356  } else {
357  ws = (Window*)::realloc(ws,(wn + 2) * sizeof(Window));
358  }
359  if(ws==NULL) return;
360  if(found==-1) {
361  // Window of shell not in list :
362  ws[wn] = wthis; wn++;
363  ws[wn] = wshell;wn++;
364  } else {
365  ws[found] = wthis;
366  ws[wn] = wshell; wn++; // Shell must be last.
367  }
368  if (::XSetWMColormapWindows(display,wshell, ws, wn)==0) {
369  CWarnF ("install_colormap: can't install colormap of %s in %s.\n",XtName(a_this),XtName(shell));
370  }
371  ::free(ws);
372  }

◆ make_current()

static int tools::Xt::OpenGLArea::make_current ( Widget  a_this)
inlinestaticprotected

Definition at line 309 of file OpenGLArea.

309  {
310  if(!XtIsRealized(a_this)) return 0;
311  OpenGLAreaPart& athis = _athis(a_this);
312  if(athis.glContext==NULL) return 0;
313  return (int)::glXMakeCurrent(XtDisplay(a_this),XtWindow(a_this),athis.glContext);
314  }

◆ paint()

static void tools::Xt::OpenGLArea::paint ( Widget  a_this)
inlinestatic

Definition at line 75 of file OpenGLArea.

75  {
76  if(!XtIsRealized(a_this)) return;
77  if(make_current(a_this)==1) {
78  XoAnyCallbackStruct value;
79  value.reason = XoCR_PAINT;
80  value.event = 0;
81  ::XtCallCallbacks(a_this,XoNpaintCallback,(XtPointer)&value);
82  ::glXSwapBuffers(XtDisplay(a_this),XtWindow(a_this));
83  ::glXMakeCurrent(XtDisplay(a_this),None,NULL);
84  }
85  }

◆ realize_widget()

static void tools::Xt::OpenGLArea::realize_widget ( Widget  a_this,
XtValueMask *  a_mask,
XSetWindowAttributes *  a_watbs 
)
inlinestaticprotected

Definition at line 198 of file OpenGLArea.

198  {
199 #ifdef OPENGLAREA_DEBUG
200  printf("debug : OpenGLArea : realize_widget : %s\n",XtName(a_this));
201 #endif
202 
203  // Have to create window ourselves due to OpenGL that compells it's visual.
204  // In principle colormap is correctly set in a_watbsy.
205 
206  OpenGLAreaPart& athis = _athis(a_this);
207 
208  ::XtCreateWindow(a_this,(unsigned int)InputOutput,athis.visual,*a_mask,a_watbs);
209 
210  // Call the Realize procedure (XtInheritRealize) :
211  if(widget_class()->core_class.superclass->core_class.realize!=NULL)
212  (widget_class()->core_class.superclass->core_class.realize)(a_this, a_mask, a_watbs);
213 
214  // If window is delete, all seems ok :
215  if(athis.installColormap==True) install_colormap(a_this);
216 
217  //make_current(a_this);
218 
219 #ifdef OPENGLAREA_DEBUG
220  printf("debug : OpenGLArea : realize_widget : end\n");
221 #endif
222  }

◆ set_values()

static Boolean tools::Xt::OpenGLArea::set_values ( Widget  a_current,
Widget  ,
Widget  a_this,
ArgList  ,
Cardinal *   
)
inlinestaticprotected

Definition at line 244 of file OpenGLArea.

244  {
245  OpenGLAreaPart& athis = _athis(a_this);
246  if(athis.doubleBufferOn != ((OpenGLAreaWidget)a_current)->openGLArea.doubleBufferOn) {
247  // Can't change buffering here if X window is created.
248  // With OpenGL, buffering fix parameter of the X window.
249  // Buffering must be choosen before the execution of the
250  // Realize method that create the window.
251  if(XtIsRealized(a_this) && (athis.installColormap==True)) {
252  CWarn("Can't change buffering after \"realization\" of the widget.\n");
253  athis.doubleBufferOn = ((OpenGLAreaWidget)a_current)->openGLArea.doubleBufferOn;
254  }
255  }
256  return False;
257  }

◆ uninstall_colormap()

static void tools::Xt::OpenGLArea::uninstall_colormap ( Widget  a_this)
inlinestaticprotected

Definition at line 374 of file OpenGLArea.

374  {
375  if( !XtIsWidget(a_this) || !XtIsRealized(a_this) ) return;
376  Widget shell = get_shell (a_this);
377  if(shell==NULL) return;
378  Display* display = XtDisplay (a_this);
379  Window wthis = XtWindow (a_this);
380  Window wshell = XtWindow (shell);
381  Window* ws = NULL;
382  int wn = 0;
383  ::XGetWMColormapWindows (display,wshell, &ws, &wn);
384  if( (wn==0) || (ws==NULL) ) return;
385  Window* nws = (Window*)::malloc( wn * sizeof(Window));
386  if(nws==NULL) {
387  ::XFree (ws);
388  return;
389  }
390  int nwn = 0;
391  for(int count=0;count<wn;count++) {
392  if(ws[count]!=wthis) {
393  nws[nwn] = ws[count];
394  nwn++;
395  }
396  }
397  if(wn!=nwn) {
398  if (::XSetWMColormapWindows(display,wshell, nws, nwn)==0) {
399  CWarnF("uninstall_colormap: can't install colormap of %s in %s.\n",XtName(a_this),XtName(shell));
400  }
401  }
402  ::XFree (ws);
403  ::free (nws);
404  }

◆ widget_class()

static WidgetClass tools::Xt::OpenGLArea::widget_class ( )
inlinestatic

Definition at line 416 of file OpenGLArea.

416  {
417  static XtResource s_resources [] = {
418  {(String)XoNdoubleBufferOn,(String)"DoubleBufferOn",XtRBoolean,sizeof(Boolean),
419  XtOffset(OpenGLAreaWidget,openGLArea.doubleBufferOn),XtRImmediate,(XtPointer)True},
420  {(String)XoNpaintCallback,XtCCallback,XtRCallback,sizeof(XtCallbackList),
421  XtOffset(OpenGLAreaWidget,openGLArea.paintCallback),XtRImmediate,(XtPointer)NULL},
422  {(String)XoNeventCallback,XtCCallback,XtRCallback,sizeof(XtCallbackList),
423  XtOffset(OpenGLAreaWidget,openGLArea.eventCallback),XtRImmediate,(XtPointer)NULL}
424  };
425 
426  static OpenGLAreaClassRec s_openGLAreaClassRec = {
427  // Core Class Part :
428  {
429  (WidgetClass) &compositeClassRec, // pointer to superclass ClassRec
430  (String)"OpenGLArea", // widget resource class name
431  sizeof(OpenGLAreaRec), // size in bytes of widget record
432  initialize_class, // class_initialize
433  NULL, // dynamic initialization
434  FALSE, // has class been initialized?
435  initialize_widget, // initialize
436  NULL, // notify that initialize called
437  realize_widget, // XCreateWindow for widget
438  NULL, // widget semantics name to proc mapWidget
439  0, // number of entries in actions
440  s_resources, // resources for subclass fields
441  XtNumber(s_resources), // number of entries in resources
442  NULLQUARK, // resource class quarkified
443  TRUE, // compress MotionNotify for widget
444  TRUE, // compress Expose events for widget
445  TRUE, // compress enter and leave events
446  TRUE, // select for VisibilityNotify
447  destroy_widget, // free data for subclass pointers
448  change_widget_size, // geom manager changed widget size
449  draw_widget, // rediplay window
450  set_values, // set subclass resource values
451  NULL, // notify that SetValues called
452  XtInheritSetValuesAlmost, // SetValues got "Almost" geo reply
453  NULL, // notify that get_values called
454  XtInheritAcceptFocus, // assign input focus to widget
455  XtVersion, // version of intrinsics used
456  NULL, // list of callback offsets
457  XtInheritTranslations, // translations
458  XtInheritQueryGeometry, // return preferred geometry
459  XtInheritDisplayAccelerator, // display your accelerator
460  NULL // pointer to extension record
461  },
462  // Composite Class Part :
463  {
464  XtInheritGeometryManager, // geometry manager for children
465  XtInheritChangeManaged, // change managed state of child
466  XtInheritInsertChild, // physically add child to parent
467  XtInheritDeleteChild, // physically remove child
468  NULL // pointer to extension record
469  },
470  // OpenGLArea :
471  {
472  NULL
473  }
474  };
475  return (WidgetClass)&s_openGLAreaClassRec;
476  }

The documentation for this class was generated from the following file:
tools::Xt::OpenGLArea::set_values
static Boolean set_values(Widget a_current, Widget, Widget a_this, ArgList, Cardinal *)
Definition: OpenGLArea:244
tools::Xt::OpenGLArea::destroy_widget
static void destroy_widget(Widget a_this)
Definition: OpenGLArea:224
tools::Xt::OpenGLAreaClassRec
struct tools::Xt::_OpenGLAreaClassRec OpenGLAreaClassRec
tools::Xt::OpenGLArea::CWarn
static void CWarn(const char *a_msg)
Definition: OpenGLArea:300
tools::Xt::OpenGLArea::get_shell
static Widget get_shell(Widget a_this)
Definition: OpenGLArea:406
tools::Xt::OpenGLArea::initialize_class
static void initialize_class(void)
Definition: OpenGLArea:87
XoCR_PAINT
#define XoCR_PAINT
Definition: OpenGLArea:37
tools::Xt::OpenGLArea::CWarnF
static void CWarnF(const char *a_format,...)
Definition: OpenGLArea:303
XoNdoubleBufferOn
#define XoNdoubleBufferOn
Definition: OpenGLArea:33
XoCR_EVENT
#define XoCR_EVENT
Definition: OpenGLArea:38
tools::realloc
bool realloc(T *&a_pointer, size_t a_new_size, size_t a_old_size, bool a_init=false)
Definition: realloc:9
tools::Xt::OpenGLAreaWidget
struct _OpenGLAreaRec * OpenGLAreaWidget
Definition: OpenGLArea:26
tools::Xt::OpenGLArea::uninstall_colormap
static void uninstall_colormap(Widget a_this)
Definition: OpenGLArea:374
tools::Xt::OpenGLAreaRec
struct tools::Xt::_OpenGLAreaRec OpenGLAreaRec
tools::Xt::OpenGLArea::initialize_widget
static void initialize_widget(Widget a_request, Widget a_this, ArgList, Cardinal *)
Definition: OpenGLArea:89
tools::Xt::OpenGLArea::install_colormap
static void install_colormap(Widget a_this)
Definition: OpenGLArea:323
tools::Xt::OpenGLArea::event_handler
static void event_handler(Widget a_this, XtPointer, XEvent *a_event, Boolean *)
Definition: OpenGLArea:316
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
XoNpaintCallback
#define XoNpaintCallback
Definition: OpenGLArea:34
tools::Xt::OpenGLArea::_athis
static OpenGLAreaPart & _athis(Widget a_this)
Definition: OpenGLArea:299
tools::Xt::OpenGLArea::make_current
static int make_current(Widget a_this)
Definition: OpenGLArea:309
tools::Xt::OpenGLArea::realize_widget
static void realize_widget(Widget a_this, XtValueMask *a_mask, XSetWindowAttributes *a_watbs)
Definition: OpenGLArea:198
tools::Xt::OpenGLArea::widget_class
static WidgetClass widget_class()
Definition: OpenGLArea:416
tools::Xt::OpenGLArea::draw_widget
static void draw_widget(Widget a_this, XEvent *a_event, Region a_region)
Definition: OpenGLArea:273
tools::Xt::OpenGLArea::change_widget_size
static void change_widget_size(Widget a_this)
Definition: OpenGLArea:259
XoNeventCallback
#define XoNeventCallback
Definition: OpenGLArea:35