Example #1
0
static GdkColormap *
gdk_gl_config_setup_colormap (GdkScreen             *screen,
                              PIXELFORMATDESCRIPTOR *pfd,
                              gboolean               is_rgba)
{
  GDK_GL_NOTE_FUNC_PRIVATE ();

  if (is_rgba)
    {
      /*
       * For RGBA mode.
       */

      /* System default colormap. */

      GDK_GL_NOTE (MISC, g_message (" -- Colormap: system default"));

      return g_object_ref (G_OBJECT (gdk_screen_get_system_colormap (screen)));
    }
  else
    {
      /*
       * For color index mode.
       */

      /* New private colormap. */

      GDK_GL_NOTE (MISC, g_message (" -- Colormap: new allocated writable"));

      return gdk_colormap_new (gdk_screen_get_system_visual (screen), TRUE);
    }

  /* not reached */
  return NULL;
}
Example #2
0
/**
 * gdk_x11_gl_query_glx_extension:
 * @glconfig: a #GdkGLConfig.
 * @extension: name of GLX extension.
 *
 * Determines whether a given GLX extension is supported.
 *
 * Return value: TRUE if the GLX extension is supported, FALSE if not
 *               supported.
 **/
gboolean
gdk_x11_gl_query_glx_extension (GdkGLConfig *glconfig,
                                const char  *extension)
{
    static const char *extensions = NULL;
    const char *start;
    char *where, *terminator;
    int major, minor;

    g_return_val_if_fail (GDK_IS_X11_GL_CONFIG (glconfig), FALSE);

    /* Extension names should not have spaces. */
    where = strchr (extension, ' ');
    if (where || *extension == '\0')
        return FALSE;

    if (extensions == NULL)
    {
        /* Be careful not to call glXQueryExtensionsString if it
           looks like the server doesn't support GLX 1.1.
           Unfortunately, the original GLX 1.0 didn't have the notion
           of GLX extensions. */

        glXQueryVersion (GDK_GL_CONFIG_XDISPLAY (glconfig),
                         &major, &minor);

        if ((major == 1 && minor < 1) || (major < 1))
            return FALSE;

        extensions = glXQueryExtensionsString (GDK_GL_CONFIG_XDISPLAY (glconfig),
                                               GDK_GL_CONFIG_SCREEN_XNUMBER (glconfig));
    }

    /* It takes a bit of care to be fool-proof about parsing
       the GLX extensions string.  Don't be fooled by
       sub-strings,  etc. */
    start = extensions;
    for (;;)
    {
        where = strstr (start, extension);
        if (where == NULL)
            break;

        terminator = where + strlen (extension);

        if (where == start || *(where - 1) == ' ')
            if (*terminator == ' ' || *terminator == '\0')
            {
                GDK_GL_NOTE (MISC, g_message (" - %s - supported", extension));
                return TRUE;
            }

        start = terminator;
    }

    GDK_GL_NOTE (MISC, g_message (" - %s - not supported", extension));

    return FALSE;
}
Example #3
0
static gboolean
gdk_gl_pixmap_impl_x11_make_context_current (GdkGLDrawable *draw,
                                             GdkGLDrawable *read,
                                             GdkGLContext  *glcontext)
{
  GdkGLConfig *glconfig;
  GLXPixmap glxpixmap;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_PIXMAP_IMPL_X11 (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_PIXMAP_IMPL_X11 (draw)->glconfig;
  glxpixmap = GDK_GL_PIXMAP_IMPL_X11 (draw)->glxpixmap;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxpixmap == None || glxcontext == NULL)
    return FALSE;

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: screen number = %d",
      GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: visual id = 0x%lx",
      GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxpixmap, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      /* currently unused. */
      /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);
  /* currently unused. */
  /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Example #4
0
/* private at present... */
gboolean
_gdk_x11_gl_overlay_get_info (GdkVisual        *visual,
                              GdkGLOverlayInfo *overlay_info)
{
  __SOVPropArray *sov_props;
  VisualID xvisualid;
  int i;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  g_return_val_if_fail (GDK_IS_VISUAL (visual), FALSE);
  g_return_val_if_fail (overlay_info != NULL, FALSE);

  /* Get SOV properties. */

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  sov_props = gdk_gl_overlay_get_sov_props (gdk_visual_get_screen (visual));
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
  sov_props = gdk_gl_overlay_get_sov_props (NULL);
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */

  /* Look up SOV property for the visual. */

  xvisualid = GDK_VISUAL_XVISUAL (visual)->visualid;

  for (i = 0; i < sov_props->num; i++)
    {
      if ((VisualID) (sov_props->prop[i].overlay_visual) == xvisualid)
        {
          overlay_info->visual           = visual;
          overlay_info->transparent_type = sov_props->prop[i].transparent_type;
          overlay_info->value            = sov_props->prop[i].value;
          overlay_info->layer            = sov_props->prop[i].layer;

          GDK_GL_NOTE (MISC, g_message (" -- overlay visual"));
          GDK_GL_NOTE (MISC, g_print ("transparent_type = %d\n",
                                      overlay_info->transparent_type));
          GDK_GL_NOTE (MISC, g_print ("value = %u\n",
                                      overlay_info->value));
          GDK_GL_NOTE (MISC, g_print ("layer = %d\n",
                                      overlay_info->layer));

          return TRUE;
        }
    }

  /* meaningless */
  overlay_info->visual           = visual;
  overlay_info->transparent_type = GDK_GL_OVERLAY_TRANSPARENT_NONE;
  overlay_info->value            = 0;
  overlay_info->layer            = 0;

  GDK_GL_NOTE (MISC, g_message (" -- not overlay visual"));
      
  return FALSE;
}
Example #5
0
/**
 * gdk_window_set_gl_capability:
 * @window: the #GdkWindow to be used as the rendering area.
 * @glconfig: a #GdkGLConfig.
 * @attrib_list: this must be set to NULL or empty (first attribute of None).
 *
 * Set the OpenGL-capability to the @window.
 * This function creates a new #GdkGLWindow held by the @window.
 * attrib_list is currently unused. This must be set to NULL or empty
 * (first attribute of None).
 *
 * Return value: the #GdkGLWindow used by the @window if it is successful,
 *               NULL otherwise.
 **/
GdkGLWindow *
gdk_window_set_gl_capability (GdkWindow   *window,
                              GdkGLConfig *glconfig,
                              const int   *attrib_list)
{
  GdkGLWindow *glwindow;

  GDK_GL_NOTE_FUNC ();

  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
  g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL);

  if (quark_gl_window == 0)
    quark_gl_window = g_quark_from_static_string (quark_gl_window_string);

  /* If already set */
  glwindow = g_object_get_qdata (G_OBJECT (window), quark_gl_window);
  if (glwindow != NULL)
    return glwindow;

  /*
   * Create GdkGLWindow
   */

  glwindow = gdk_gl_window_new (glconfig, window, attrib_list);
  if (glwindow == NULL)
    {
      g_warning ("cannot create GdkGLWindow\n");
      return NULL;
    }

  g_object_set_qdata_full (G_OBJECT (window), quark_gl_window, glwindow,
                           (GDestroyNotify) g_object_unref);

  /*
   * Set a background of "None" on window to avoid AIX X server crash
   */

  GDK_GL_NOTE (MISC,
    g_message (" - window->bg_pixmap = %p",
               (void*)gdk_window_get_background_pattern (window)));

  gdk_window_set_background_pattern (window, NULL);

  GDK_GL_NOTE (MISC,
    g_message (" - window->bg_pixmap = %p",
               (void*)gdk_window_get_background_pattern (window)));

  return glwindow;
}
Example #6
0
static gboolean
_gdk_win32_gl_context_impl_make_current (GdkGLContext *glcontext,
                                         GdkGLDrawable *draw,
                                         GdkGLDrawable *read)
{
  GdkGLWindowImplWin32 *impl;
  HDC hdc;
  HGLRC hglrc;

  g_return_val_if_fail (GDK_IS_WIN32_GL_CONTEXT (glcontext), FALSE);
  g_return_val_if_fail (GDK_IS_WIN32_GL_WINDOW (draw), FALSE);

  if (GDK_GL_WINDOW_IS_DESTROYED (GDK_GL_WINDOW (draw)) ||
      GDK_GL_CONTEXT_IS_DESTROYED (glcontext))
    return FALSE;

  impl = GDK_GL_WINDOW_IMPL_WIN32 (GDK_GL_WINDOW (draw)->impl);

  /* Get DC. */
  hdc = GDK_GL_WINDOW_IMPL_WIN32_HDC_GET (impl);

  /* Get GLRC. */
  hglrc = GDK_GL_CONTEXT_HGLRC (glcontext);

  GDK_GL_NOTE_FUNC_IMPL ("wglMakeCurrent");

  if (!wglMakeCurrent (hdc, hglrc))
    {
      g_warning ("wglMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      /* currently unused. */
      /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);
  /* currently unused. */
  /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (impl->glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  /*
   * Do *NOT* release DC.
   *
   * With some graphics card, DC owned by rendering thread will be needed.
   */

  return TRUE;
}
Example #7
0
/**
 * gdk_gl_query_gl_extension:
 * @extension: name of OpenGL extension.
 *
 * Determines whether a given OpenGL extension is supported.
 *
 * There must be a valid current rendering context to call
 * gdk_gl_query_gl_extension().
 *
 * gdk_gl_query_gl_extension() returns information about OpenGL extensions
 * only. This means that window system dependent extensions (for example,
 * GLX extensions) are not reported by gdk_gl_query_gl_extension().
 *
 * Return value: TRUE if the OpenGL extension is supported, FALSE if not 
 *               supported.
 **/
gboolean
gdk_gl_query_gl_extension (const char *extension)
{
  static const GLubyte *extensions = NULL;
  const GLubyte *start;
  GLubyte *where, *terminator;

  /* Extension names should not have spaces. */
  where = (GLubyte *) strchr (extension, ' ');
  if (where || *extension == '\0')
    return FALSE;

  if (extensions == NULL)
    extensions = glGetString (GL_EXTENSIONS);

  /* It takes a bit of care to be fool-proof about parsing the
     OpenGL extensions string.  Don't be fooled by sub-strings,
     etc. */
  start = extensions;
  for (;;)
    {
      /* If your application crashes in the strstr routine below,
         you are probably calling gdk_gl_query_gl_extension without
         having a current window.  Calling glGetString without
         a current OpenGL context has unpredictable results.
         Please fix your program. */
      where = (GLubyte *) strstr ((const char *) start, extension);
      if (where == NULL)
        break;

      terminator = where + strlen (extension);

      if (where == start || *(where - 1) == ' ')
        if (*terminator == ' ' || *terminator == '\0')
          {
            GDK_GL_NOTE (MISC, g_message (" - %s - supported", extension));
            return TRUE;
          }

      start = terminator;
    }

  GDK_GL_NOTE (MISC, g_message (" - %s - not supported", extension));

  return FALSE;
}
Example #8
0
gboolean
gdk_gl_window_make_context_current (GdkGLDrawable *draw, GdkGLContext *glcontext)
{
  GdkGLDrawable *read = draw;
  GdkGLConfig *glconfig;
  Window glxwindow;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_WINDOW (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_WINDOW (draw)->glconfig;
  glxwindow = GDK_GL_WINDOW (draw)->glxwindow;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxwindow == None || glxcontext == NULL)
    return FALSE;

  GDK_GL_NOTE (MISC, g_message (" -- Window: screen number = %d", GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
  GDK_GL_NOTE (MISC, g_message (" -- Window: visual id = 0x%lx", GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxwindow, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Example #9
0
static gboolean
gdk_gl_pixmap_impl_win32_make_context_current (GdkGLDrawable *draw,
                                               GdkGLDrawable *read,
                                               GdkGLContext  *glcontext)
{
  GdkGLPixmapImplWin32 *impl;
  HDC hdc;
  HGLRC hglrc;

  g_return_val_if_fail (GDK_IS_GL_PIXMAP_IMPL_WIN32 (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_WIN32 (glcontext), FALSE);

  if (GDK_GL_PIXMAP_IS_DESTROYED (draw) ||
      GDK_GL_CONTEXT_IS_DESTROYED (glcontext))
    return FALSE;

  impl = GDK_GL_PIXMAP_IMPL_WIN32 (draw);

  /* Get DC. */
  hdc = GDK_GL_PIXMAP_IMPL_WIN32_HDC_GET (impl);

  /* Get GLRC. */
  hglrc = GDK_GL_CONTEXT_HGLRC (glcontext);

  GDK_GL_NOTE_FUNC_IMPL ("wglMakeCurrent");

  if (!wglMakeCurrent (hdc, hglrc))
    {
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      /* currently unused. */
      /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);
  /* currently unused. */
  /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (impl->glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  /* Do *NOT* release DC. */

  return TRUE;
}
Example #10
0
static void
gdk_gl_context_insert (GdkGLContext *glcontext)
{
  GdkGLContextImplWin32 *impl;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  g_return_if_fail (GDK_IS_WIN32_GL_CONTEXT (glcontext));

  if (gl_context_ht == NULL)
    {
      GDK_GL_NOTE (MISC, g_message (" -- Create GL context hash table."));

      /* We do not know the storage type of HGLRC. We assume that it is
         a pointer as NULL values are specified for this type. */
      gl_context_ht = g_hash_table_new (g_direct_hash,
                                        g_direct_equal);
    }

  impl = GDK_GL_CONTEXT_IMPL_WIN32 (glcontext->impl);

  g_hash_table_insert (gl_context_ht, impl->hglrc, glcontext);
}
Example #11
0
static void
gdk_gl_context_remove (GdkGLContext *glcontext)
{
  GdkGLContextImplWin32 *impl;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  g_return_if_fail (GDK_IS_WIN32_GL_CONTEXT (glcontext));

  if (gl_context_ht == NULL)
    return;

  impl = GDK_GL_CONTEXT_IMPL_WIN32 (glcontext->impl);

  g_hash_table_remove (gl_context_ht, impl->hglrc);

  if (g_hash_table_size (gl_context_ht) == 0)
    {
      GDK_GL_NOTE (MISC, g_message (" -- Destroy GL context hash table."));
      g_hash_table_destroy (gl_context_ht);
      gl_context_ht = NULL;
    }
}
Example #12
0
static __SOVPropArray *
gdk_gl_overlay_get_sov_props (GdkScreen *screen)
{
  __SOVPropArray *sov_props;
  GdkWindow *root_window;
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  GdkDisplay *display;
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
  Display *xdisplay;
  Atom xa_sov;
  Status status;
  Atom actual_type;
  int actual_format;
  unsigned long nitems, bytes_after;
  unsigned char *prop = NULL;

  GDK_GL_NOTE_FUNC_PRIVATE ();

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  root_window = gdk_screen_get_root_window (screen);
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
  root_window = gdk_get_default_root_window ();
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */

  if (quark_sov_props == 0)
    quark_sov_props = g_quark_from_static_string (quark_sov_props_string);

  sov_props = g_object_get_qdata (G_OBJECT (root_window), quark_sov_props);
  if (sov_props != NULL)
    return sov_props;

  sov_props = g_malloc (sizeof (__SOVPropArray));

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  display = gdk_screen_get_display (screen);
  xdisplay = GDK_DISPLAY_XDISPLAY (display);
  xa_sov = gdk_x11_get_xatom_by_name_for_display (display, "SERVER_OVERLAY_VISUALS");
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
  xdisplay = gdk_x11_get_default_xdisplay ();
  xa_sov = gdk_x11_get_xatom_by_name ("SERVER_OVERLAY_VISUALS");
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */

  status = XGetWindowProperty (xdisplay, GDK_WINDOW_XWINDOW (root_window),
                               xa_sov, 0L, 1000000L, False, AnyPropertyType,
                               &actual_type, &actual_format,
                               &nitems, &bytes_after, &prop);
  if (status != Success ||
      actual_type == None ||
      actual_format != 32 ||
      nitems < 4)
    {
      GDK_GL_NOTE (MISC, g_message (" -- SERVER_OVERLAY_VISUALS: not supported"));

      if (prop != NULL)
        XFree (prop);

      sov_props->prop = NULL;
      sov_props->num = 0;
    }
  else
    {
      GDK_GL_NOTE (MISC, g_message (" -- SERVER_OVERLAY_VISUALS: supported"));

      sov_props->prop = (__SOVProp *) prop;
      sov_props->num = nitems / (sizeof (__SOVProp) / 4);
    }

  g_object_set_qdata_full (G_OBJECT (root_window), quark_sov_props, sov_props,
                           (GDestroyNotify) sov_prop_array_destroy);

#ifdef G_ENABLE_DEBUG
  if (gdk_gl_debug_flags & GDK_GL_DEBUG_MISC)
    {
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
      int screen_num = GDK_SCREEN_XNUMBER (screen);
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
      int screen_num = gdk_x11_get_default_screen ();
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
      int i;

      g_message (" -- SERVER_OVERLAY_VISUALS: properties");
      g_print ("screen\tvisual\ttype\tvalue\tlayer\n");
      for (i = 0; i < sov_props->num; i++)
        {
          g_print ("%d\t0x%lx\t%lu\t%lu\t%ld\n",
                   screen_num,
                   (VisualID) (sov_props->prop[i].overlay_visual),
                   (CARD32)   (sov_props->prop[i].transparent_type),
                   (CARD32)   (sov_props->prop[i].value),
                   (INT32)    (sov_props->prop[i].layer));
        }
    }
#endif /* G_ENABLE_DEBUG */

  return sov_props;
}
Example #13
0
GdkGLProc
gdk_gl_get_proc_address (const char *proc_name)
{
  typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *);
  static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1;
  gchar *file_name;
  GModule *module;
  GdkGLProc proc_address = NULL;

  GDK_GL_NOTE_FUNC ();

  if (glx_get_proc_address == (__glXGetProcAddressProc) -1) {
      /*
       * Look up glXGetProcAddress () function.
       */

      file_name = g_module_build_path (NULL, "GL");
      GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
      module = g_module_open (file_name, G_MODULE_BIND_LAZY);
      g_free (file_name);

      if (module) {
          g_module_symbol (module, "glXGetProcAddress", (gpointer) &glx_get_proc_address);
          if (glx_get_proc_address == NULL) {
            g_module_symbol (module, "glXGetProcAddressARB", (gpointer) &glx_get_proc_address);
            if (glx_get_proc_address == NULL) {
              g_module_symbol (module, "glXGetProcAddressEXT", (gpointer) &glx_get_proc_address);
            }
          }
          GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s", glx_get_proc_address ? "supported" : "not supported"));
          g_module_close (module);
      } else {
        g_warning ("Cannot open %s", file_name);
        glx_get_proc_address = NULL;
        return NULL;
      }
  }

  /* Try glXGetProcAddress () */

  if (glx_get_proc_address) {
    proc_address = glx_get_proc_address ((unsigned char *) proc_name);
    GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s", proc_address ? "succeeded" : "failed"));
    if (proc_address)
      return proc_address;
  }

  /* Try g_module_symbol () */

  /* libGL */
  file_name = g_module_build_path (NULL, "GL");
  GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
  module = g_module_open (file_name, G_MODULE_BIND_LAZY);
  g_free (file_name);

  if (module) {
    g_module_symbol (module, proc_name, (gpointer) &proc_address);
    GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", proc_address ? "succeeded" : "failed"));
    g_module_close (module);
  } else {
    g_warning ("Cannot open %s", file_name);
  }

  if (!proc_address) {
      /* libGLcore */
      file_name = g_module_build_path (NULL, "GLcore");
      GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
      module = g_module_open (file_name, G_MODULE_BIND_LAZY);
      g_free (file_name);

      if (module) {
        g_module_symbol (module, proc_name, (gpointer) &proc_address);
        GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s", proc_address ? "succeeded" : "failed"));
        g_module_close (module);
      }
  }

  return proc_address;
}
Example #14
0
static gboolean
gdk_gl_config_setup_pfd (CONST PIXELFORMATDESCRIPTOR *req_pfd,
			 PIXELFORMATDESCRIPTOR       *pfd)
{
  HDC hdc;
  PIXELFORMATDESCRIPTOR temp_pfd;
  PIXELFORMATDESCRIPTOR w_pfd, b_pfd;
  int w_pf, b_pf;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  /* Get DC. */
  hdc = GetDC (NULL);
  if (hdc == NULL)
    {
      g_warning ("cannot get DC");
      return FALSE;
    }

  w_pfd = *req_pfd;
  w_pfd.dwFlags &= ~PFD_DRAW_TO_BITMAP;
  w_pfd.dwFlags |= PFD_DRAW_TO_WINDOW;
  w_pf = _gdk_win32_gl_config_find_pixel_format (hdc, &w_pfd, &w_pfd);

  GDK_GL_NOTE (MISC, g_message (" -- pixel format for windows = 0x%x", w_pf));
  GDK_GL_NOTE (MISC, _gdk_win32_gl_print_pfd (&w_pfd));

  b_pfd = *req_pfd;
  b_pfd.dwFlags &= ~PFD_DRAW_TO_WINDOW;
  b_pfd.dwFlags |= PFD_DRAW_TO_BITMAP;
  b_pf = _gdk_win32_gl_config_find_pixel_format (hdc, &b_pfd, &b_pfd);

  GDK_GL_NOTE (MISC, g_message (" -- pixel format for bitmaps = 0x%x", b_pf));
  GDK_GL_NOTE (MISC, _gdk_win32_gl_print_pfd (&b_pfd));

  /* Release DC. */
  ReleaseDC (NULL, hdc);

  if (w_pf == 0 && b_pf == 0)
    return FALSE;

  if (w_pf == 0)
    {
      temp_pfd = b_pfd;
      temp_pfd.dwFlags = req_pfd->dwFlags;
    }
  else if (b_pf == 0)
    {
      temp_pfd = w_pfd;
      temp_pfd.dwFlags = req_pfd->dwFlags;
    }
  else
    {
      temp_pfd = w_pfd;
      temp_pfd.dwFlags = req_pfd->dwFlags;
      if (temp_pfd.cColorBits > b_pfd.cColorBits)
        {
          temp_pfd.cColorBits  = b_pfd.cColorBits;
          temp_pfd.cRedBits    = b_pfd.cRedBits;
          temp_pfd.cRedShift   = b_pfd.cRedShift;
          temp_pfd.cGreenBits  = b_pfd.cGreenBits;
          temp_pfd.cGreenShift = b_pfd.cGreenShift;
          temp_pfd.cBlueBits   = b_pfd.cBlueBits;
          temp_pfd.cBlueShift  = b_pfd.cBlueShift;
        }
      if (temp_pfd.cAlphaBits > b_pfd.cAlphaBits)
        {
          temp_pfd.cAlphaBits  = b_pfd.cAlphaBits;
          temp_pfd.cAlphaShift = b_pfd.cAlphaShift;
        }
      if (temp_pfd.cAccumBits > b_pfd.cAccumBits)
        {
          temp_pfd.cAccumBits      = b_pfd.cAccumBits;
          temp_pfd.cAccumRedBits   = b_pfd.cAccumRedBits;
          temp_pfd.cAccumGreenBits = b_pfd.cAccumGreenBits;
          temp_pfd.cAccumBlueBits  = b_pfd.cAccumBlueBits;
          temp_pfd.cAccumAlphaBits = b_pfd.cAccumAlphaBits;
        }
      temp_pfd.cDepthBits   = MIN (temp_pfd.cDepthBits,   b_pfd.cDepthBits);
      temp_pfd.cStencilBits = MIN (temp_pfd.cStencilBits, b_pfd.cStencilBits);
      temp_pfd.cAuxBuffers  = MIN (temp_pfd.cAuxBuffers,  b_pfd.cAuxBuffers);
    }

  *pfd = temp_pfd;

  return TRUE;
}
Example #15
0
/*
 * attrib_list is currently unused. This must be set to NULL or empty
 * (first attribute of None). See GLX 1.3 spec.
 */
GdkGLWindow *
_gdk_win32_gl_window_impl_new (GdkGLWindow *glwindow,
                               GdkGLConfig *glconfig,
                               GdkWindow   *window,
                               const int   *attrib_list)
{
  GdkGLWindowImplWin32 *win32_impl;

  HWND hwnd;
  DWORD wndclass_style;
  gboolean need_release_dc;
  HDC hdc = NULL;
  PIXELFORMATDESCRIPTOR pfd;
  int pixel_format;

  GDK_GL_NOTE_FUNC ();

  g_return_val_if_fail (GDK_IS_WIN32_GL_WINDOW (glwindow), NULL);
  g_return_val_if_fail (GDK_IS_WIN32_GL_CONFIG (glconfig), NULL);
  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);

  hwnd = (HWND) gdk_win32_window_get_handle (window);

  /* Private DC? */
  wndclass_style = GetClassLong (hwnd, GCL_STYLE);
  if (wndclass_style & CS_OWNDC)
    {
      GDK_GL_NOTE (MISC, g_message (" -- Private DC"));
      need_release_dc = FALSE;
    }
  else
    {
      GDK_GL_NOTE (MISC, g_message (" -- Common DC"));
      need_release_dc = TRUE;
    }

  /* Get DC. */
  hdc = GetDC (hwnd);
  if (hdc == NULL)
    {
      g_warning ("cannot get DC");
      goto FAIL;
    }

  /*
   * Choose pixel format.
   */

  pfd = *(GDK_GL_CONFIG_PFD (glconfig));
  /* Draw to window */
  pfd.dwFlags &= ~PFD_DRAW_TO_BITMAP;
  pfd.dwFlags |= PFD_DRAW_TO_WINDOW;

  /* Request pfd.cColorBits should exclude alpha bitplanes. */
  pfd.cColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  GDK_GL_NOTE_FUNC_IMPL ("ChoosePixelFormat");

  pixel_format = ChoosePixelFormat (hdc, &pfd);
  if (pixel_format == 0)
    {
      g_warning ("cannot choose pixel format");
      goto FAIL;
    }

  /*
   * Set pixel format.
   */

  GDK_GL_NOTE_FUNC_IMPL ("SetPixelFormat");

  if (!SetPixelFormat (hdc, pixel_format, &pfd))
    {
      g_warning ("cannot set pixel format");
      goto FAIL;
    }

  DescribePixelFormat (hdc, pixel_format, sizeof (pfd), &pfd);

  GDK_GL_NOTE (MISC, g_message (" -- impl->pixel_format = 0x%x", pixel_format));
  GDK_GL_NOTE (MISC, _gdk_win32_gl_print_pfd (&pfd));

  if (need_release_dc)
    {
      /* Release DC. */
      ReleaseDC (hwnd, hdc);
      hdc = NULL;
    }

  /*
   * Instantiate the GdkGLWindowImplWin32 object.
   */

  win32_impl = g_object_new (GDK_TYPE_GL_WINDOW_IMPL_WIN32, NULL);

  win32_impl->hwnd = hwnd;

  win32_impl->pfd = pfd;
  win32_impl->pixel_format = pixel_format;

  win32_impl->glconfig = glconfig;
  g_object_ref (G_OBJECT (win32_impl->glconfig));

  win32_impl->hdc = hdc;
  win32_impl->need_release_dc = need_release_dc;

  win32_impl->is_destroyed = FALSE;

  glwindow->impl = GDK_GL_WINDOW_IMPL(win32_impl);
  glwindow->window = window;
  g_object_add_weak_pointer (G_OBJECT (glwindow->window),
                             (gpointer *) &(glwindow->window));

  return glwindow;

 FAIL:

  /* Release DC. */
  if (need_release_dc && hdc != NULL)
    ReleaseDC (hwnd, hdc);

  return NULL;
}
Example #16
0
/*
 * attrib_list is currently unused. This must be set to NULL or empty
 * (first attribute of None). See GLX 1.3 spec.
 */
GdkGLPixmap *
gdk_gl_pixmap_new (GdkGLConfig *glconfig,
                   GdkPixmap   *pixmap,
                   const int   *attrib_list)
{
  GdkGLPixmap *glpixmap;
  GdkGLPixmapImplWin32 *impl;

  gint width, height;
  gint depth;
  GdkPixmap *pixmap_gl = NULL;

  HBITMAP hbitmap_gl;
  HDC hdc_gl = NULL;
  PIXELFORMATDESCRIPTOR pfd;
  int pixel_format;

  HBITMAP hbitmap_gdk;
  HDC hdc_gdk = NULL;

  GDK_GL_NOTE_FUNC ();

  g_return_val_if_fail (GDK_IS_GL_CONFIG_IMPL_WIN32 (glconfig), NULL);
  g_return_val_if_fail (GDK_IS_PIXMAP (pixmap), NULL);

  /*
   * Create offscreen rendering area.
   */

  gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
  depth = gdk_drawable_get_depth (GDK_DRAWABLE (pixmap));

  pixmap_gl = gdk_pixmap_new (NULL, width, height, depth);
  if (pixmap_gl == NULL)
    goto FAIL;

  /*
   * Source (OpenGL) DIB
   */

  hbitmap_gl = (HBITMAP) gdk_win32_drawable_get_handle (GDK_DRAWABLE (pixmap_gl));

  /* Create a memory DC. */
  hdc_gl = CreateCompatibleDC (NULL);
  if (hdc_gl == NULL)
    {
      g_warning ("cannot create a memory DC");
      goto FAIL;
    }

  /* Select the bitmap. */
  if (SelectObject (hdc_gl, hbitmap_gl) == NULL)
    {
      g_warning ("cannot select DIB");
      goto FAIL;
    }

  /*
   * Choose pixel format.
   */

  pfd = *(GDK_GL_CONFIG_PFD (glconfig));
  /* Draw to bitmap */
  pfd.dwFlags &= ~PFD_DRAW_TO_WINDOW;
  pfd.dwFlags |= PFD_DRAW_TO_BITMAP;

  /* Request pfd.cColorBits should exclude alpha bitplanes. */
  pfd.cColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  GDK_GL_NOTE_FUNC_IMPL ("ChoosePixelFormat");

  pixel_format = ChoosePixelFormat (hdc_gl, &pfd);
  if (pixel_format == 0)
    {
      g_warning ("cannot choose pixel format");
      goto FAIL;
    }

  /*
   * Set pixel format.
   */

  GDK_GL_NOTE_FUNC_IMPL ("SetPixelFormat");

  if (!SetPixelFormat (hdc_gl, pixel_format, &pfd))
    {
      g_warning ("cannot set pixel format");
      goto FAIL;
    }

  DescribePixelFormat (hdc_gl, pixel_format, sizeof (pfd), &pfd);

  GDK_GL_NOTE (MISC, g_message (" -- impl->pixel_format = 0x%x", pixel_format));
  GDK_GL_NOTE (MISC, _gdk_win32_gl_print_pfd (&pfd));

  /*
   * Destination (GDK) DIB
   */

  hbitmap_gdk = (HBITMAP) gdk_win32_drawable_get_handle (GDK_DRAWABLE (pixmap));

  /* Create a memory DC. */
  hdc_gdk = CreateCompatibleDC (hdc_gl);
  if (hdc_gdk == NULL)
    {
      g_warning ("cannot create a memory DC");
      goto FAIL;
    }

  /*
   * Instantiate the GdkGLPixmapImplWin32 object.
   */

  glpixmap = g_object_new (GDK_TYPE_GL_PIXMAP_IMPL_WIN32, NULL);
  impl = GDK_GL_PIXMAP_IMPL_WIN32 (glpixmap);

  glpixmap->drawable = GDK_DRAWABLE (pixmap);
  g_object_add_weak_pointer (G_OBJECT (glpixmap->drawable),
                             (gpointer *) &(glpixmap->drawable));

  impl->pixmap_gl = pixmap_gl;

  impl->width = width;
  impl->height = height;

  impl->pfd = pfd;
  impl->pixel_format = pixel_format;

  impl->glconfig = glconfig;
  g_object_ref (G_OBJECT (impl->glconfig));

  impl->hdc_gl = hdc_gl;

  impl->hdc_gdk = hdc_gdk;
  impl->hbitmap_gdk = hbitmap_gdk;

  impl->is_destroyed = FALSE;

  return glpixmap;

 FAIL:

  if (hdc_gdk != NULL)
    DeleteDC (hdc_gdk);

  if (hdc_gl != NULL)
    DeleteDC (hdc_gl);

  if (pixmap_gl != NULL)
    g_object_unref (G_OBJECT (pixmap_gl));

  return NULL;  
}
Example #17
0
GdkGLProc
gdk_gl_get_proc_address (const char *proc_name)
{
  typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *);
  static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1;
  const char *image_name;
  static const struct mach_header *libgl_image = NULL;
  static const struct mach_header *libglu_image = NULL;
  NSSymbol symbol;
  char *symbol_name;
  GdkGLProc proc_address;

  GDK_GL_NOTE_FUNC ();

  if (strncmp ("glu", proc_name, 3) != 0)
    {
      /* libGL */

      if (libgl_image == NULL)
        {
          image_name = g_getenv ("GDK_GL_LIBGL_PATH");
          if (image_name == NULL)
            image_name = _GDK_GL_LIBGL_PATH;

          GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name));

          libgl_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
          if (libgl_image == NULL)
            {
              g_warning ("Cannot add Mach-O image %s", image_name);
              return NULL;
            }
        }

      if (glx_get_proc_address == (__glXGetProcAddressProc) -1)
        {
          /*
           * Look up glXGetProcAddress () function.
           */

          symbol = NSLookupSymbolInImage (libgl_image,
                                          "_glXGetProcAddress",
                                          NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                          NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
          if (symbol == NULL)
            {
              symbol = NSLookupSymbolInImage (libgl_image,
                                              "_glXGetProcAddressARB",
                                              NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                              NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
              if (symbol == NULL)
                {
                  symbol = NSLookupSymbolInImage (libgl_image,
                                                  "_glXGetProcAddressEXT",
                                                  NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                                  NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
                }
            }
          GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s",
                                        symbol ? "supported" : "not supported"));
          if (symbol != NULL)
            glx_get_proc_address = NSAddressOfSymbol (symbol);
          else
            glx_get_proc_address = NULL;
        }

      /* Try glXGetProcAddress () */

      if (glx_get_proc_address != NULL)
        {
          proc_address = glx_get_proc_address (proc_name);
          GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s",
                                        proc_address ? "succeeded" : "failed"));
          if (proc_address != NULL)
            return proc_address;
        }

      /* Try Mach-O dyld */

      symbol_name = g_strconcat ("_", proc_name, NULL);

      symbol = NSLookupSymbolInImage (libgl_image,
                                      symbol_name,
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
      GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s",
                                    symbol ? "succeeded" : "failed"));

      g_free (symbol_name);

      if (symbol != NULL)
        return NSAddressOfSymbol (symbol);
    }
  else
    {
      /* libGLU */

      if (libglu_image == NULL)
        {
          image_name = g_getenv ("GDK_GL_LIBGLU_PATH");
          if (image_name == NULL)
            image_name = _GDK_GL_LIBGLU_PATH;

          GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name));

          libglu_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
          if (libglu_image == NULL)
            {
              g_warning ("Cannot add Mach-O image %s", image_name);
              return NULL;
            }
        }

      symbol_name = g_strconcat ("_", proc_name, NULL);

      symbol = NSLookupSymbolInImage (libglu_image,
                                      symbol_name,
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                      NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
      GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s",
                                    symbol ? "succeeded" : "failed"));

      g_free (symbol_name);

      if (symbol != NULL)
        return NSAddressOfSymbol (symbol);
    }

  return NULL;
}
Example #18
0
GdkGLProc
_gdk_x11_gl_get_proc_address (const char *proc_name)
{
#ifdef __APPLE__

#define _GDK_GL_LIBGL_PATH  "/usr/X11R6/lib/libGL.1.dylib"
#define _GDK_GL_LIBGLU_PATH "/usr/X11R6/lib/libGLU.1.dylib"

    typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *);
    static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1;
    const char *image_name;
    static const struct mach_header *libgl_image = NULL;
    static const struct mach_header *libglu_image = NULL;
    NSSymbol symbol;
    char *symbol_name;
    GdkGLProc proc_address;

    GDK_GL_NOTE_FUNC ();

    if (strncmp ("glu", proc_name, 3) != 0)
    {
        /* libGL */

        if (libgl_image == NULL)
        {
            image_name = g_getenv ("GDK_GL_LIBGL_PATH");
            if (image_name == NULL)
                image_name = _GDK_GL_LIBGL_PATH;

            GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name));

            libgl_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
            if (libgl_image == NULL)
            {
                g_warning ("Cannot add Mach-O image %s", image_name);
                return NULL;
            }
        }

        if (glx_get_proc_address == (__glXGetProcAddressProc) -1)
        {
            /*
             * Look up glXGetProcAddress () function.
             */

            symbol = NSLookupSymbolInImage (libgl_image,
                                            "_glXGetProcAddress",
                                            NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                            NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
            if (symbol == NULL)
            {
                symbol = NSLookupSymbolInImage (libgl_image,
                                                "_glXGetProcAddressARB",
                                                NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                                NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
                if (symbol == NULL)
                {
                    symbol = NSLookupSymbolInImage (libgl_image,
                                                    "_glXGetProcAddressEXT",
                                                    NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                                    NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
                }
            }
            GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s",
                                          symbol ? "supported" : "not supported"));
            if (symbol != NULL)
                glx_get_proc_address = NSAddressOfSymbol (symbol);
            else
                glx_get_proc_address = NULL;
        }

        /* Try glXGetProcAddress () */

        if (glx_get_proc_address != NULL)
        {
            proc_address = glx_get_proc_address ((unsigned char *) proc_name);
            GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s",
                                          proc_address ? "succeeded" : "failed"));
            if (proc_address != NULL)
                return proc_address;
        }

        /* Try Mach-O dyld */

        symbol_name = g_strconcat ("_", proc_name, NULL);

        symbol = NSLookupSymbolInImage (libgl_image,
                                        symbol_name,
                                        NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                        NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
        GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s",
                                      symbol ? "succeeded" : "failed"));

        g_free (symbol_name);

        if (symbol != NULL)
            return NSAddressOfSymbol (symbol);
    }
    else
    {
        /* libGLU */

        if (libglu_image == NULL)
        {
            image_name = g_getenv ("GDK_GL_LIBGLU_PATH");
            if (image_name == NULL)
                image_name = _GDK_GL_LIBGLU_PATH;

            GDK_GL_NOTE (MISC, g_message (" - Add Mach-O image %s", image_name));

            libglu_image = NSAddImage (image_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
            if (libglu_image == NULL)
            {
                g_warning ("Cannot add Mach-O image %s", image_name);
                return NULL;
            }
        }

        symbol_name = g_strconcat ("_", proc_name, NULL);

        symbol = NSLookupSymbolInImage (libglu_image,
                                        symbol_name,
                                        NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
                                        NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
        GDK_GL_NOTE (MISC, g_message (" - NSLookupSymbolInImage () - %s",
                                      symbol ? "succeeded" : "failed"));

        g_free (symbol_name);

        if (symbol != NULL)
            return NSAddressOfSymbol (symbol);
    }

    return NULL;

#else  /* __APPLE__ */

    typedef GdkGLProc (*__glXGetProcAddressProc) (const GLubyte *);
    static __glXGetProcAddressProc glx_get_proc_address = (__glXGetProcAddressProc) -1;
    gchar *file_name;
    GModule *module;
    GdkGLProc proc_address = NULL;

    GDK_GL_NOTE_FUNC ();

    if (strncmp ("glu", proc_name, 3) != 0)
    {
        if (glx_get_proc_address == (__glXGetProcAddressProc) -1)
        {
            /*
             * Look up glXGetProcAddress () function.
             */

            file_name = g_module_build_path (NULL, "GL");
            GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
            module = g_module_open (file_name, G_MODULE_BIND_LAZY);
            g_free (file_name);

            if (module != NULL)
            {
                g_module_symbol (module, "glXGetProcAddress",
                                 (gpointer) &glx_get_proc_address);
                if (glx_get_proc_address == NULL)
                {
                    g_module_symbol (module, "glXGetProcAddressARB",
                                     (gpointer) &glx_get_proc_address);
                    if (glx_get_proc_address == NULL)
                    {
                        g_module_symbol (module, "glXGetProcAddressEXT",
                                         (gpointer) &glx_get_proc_address);
                    }
                }
                GDK_GL_NOTE (MISC, g_message (" - glXGetProcAddress () - %s",
                                              glx_get_proc_address ? "supported" : "not supported"));
                g_module_close (module);
            }
            else
            {
                g_warning ("Cannot open %s", file_name);
                glx_get_proc_address = NULL;
                return NULL;
            }
        }

        /* Try glXGetProcAddress () */

        if (glx_get_proc_address != NULL)
        {
            proc_address = glx_get_proc_address ((unsigned char *) proc_name);
            GDK_GL_NOTE (IMPL, g_message (" ** glXGetProcAddress () - %s",
                                          proc_address ? "succeeded" : "failed"));
            if (proc_address != NULL)
                return proc_address;
        }

        /* Try g_module_symbol () */

        /* libGL */
        file_name = g_module_build_path (NULL, "GL");
        GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
        module = g_module_open (file_name, G_MODULE_BIND_LAZY);
        g_free (file_name);

        if (module != NULL)
        {
            g_module_symbol (module, proc_name, (gpointer) &proc_address);
            GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s",
                                          proc_address ? "succeeded" : "failed"));
            g_module_close (module);
        }
        else
        {
            g_warning ("Cannot open %s", file_name);
        }

        if (proc_address == NULL)
        {
            /* libGLcore */
            file_name = g_module_build_path (NULL, "GLcore");
            GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
            module = g_module_open (file_name, G_MODULE_BIND_LAZY);
            g_free (file_name);

            if (module != NULL)
            {
                g_module_symbol (module, proc_name, (gpointer) &proc_address);
                GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s",
                                              proc_address ? "succeeded" : "failed"));
                g_module_close (module);
            }
        }
    }
    else
    {
        /* libGLU */
        file_name = g_module_build_path (NULL, "GLU");
        GDK_GL_NOTE (MISC, g_message (" - Open %s", file_name));
        module = g_module_open (file_name, G_MODULE_BIND_LAZY);
        g_free (file_name);

        if (module != NULL)
        {
            g_module_symbol (module, proc_name, (gpointer) &proc_address);
            GDK_GL_NOTE (MISC, g_message (" - g_module_symbol () - %s",
                                          proc_address ? "succeeded" : "failed"));
            g_module_close (module);
        }
        else
        {
            g_warning ("Cannot open %s", file_name);
        }
    }

    return proc_address;

#endif /* __APPLE__ */
}