/** * gdk_gl_window_new: * @glconfig: a #GdkGLConfig. * @window: the #GdkWindow to be used as the rendering area. * @attrib_list: (array) (allow-none): this must be set to NULL or empty (first attribute of None). * * Creates an on-screen rendering area. * attrib_list is currently unused. This must be set to NULL or empty * (first attribute of None). See GLX 1.3 spec. * * Return value: the new #GdkGLWindow. **/ GdkGLWindow * gdk_gl_window_new (GdkGLConfig *glconfig, GdkWindow *window, const int *attrib_list) { GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL); g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); /* * Get X Window. */ Window glxwindow = GDK_DRAWABLE_XID (GDK_DRAWABLE (window)); /* * Instantiate the GdkGLWindowImplX11 object. */ GdkGLWindow *glwindow = g_object_new (GDK_TYPE_GL_WINDOW, NULL); glwindow->drawable = GDK_DRAWABLE (window); g_object_add_weak_pointer (G_OBJECT (glwindow->drawable), (gpointer *) &(glwindow->drawable)); glwindow->glxwindow = glxwindow; glwindow->glconfig = glconfig; g_object_ref (G_OBJECT (glwindow->glconfig)); glwindow->is_destroyed = FALSE; return glwindow; }
/** * gdk_gl_drawable_get_current: * * Returns the current #GdkGLDrawable. * * Return value: (transfer none): the current #GdkGLDrawable or NULL if there is no current drawable. **/ GdkGLDrawable* gdk_gl_drawable_get_current (void) { GDK_GL_NOTE_FUNC (); GdkGLContext* glcontext = gdk_gl_context_get_current (); if (!glcontext) return NULL; return gdk_gl_context_get_gl_drawable (glcontext); }
/** * 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; }
/** * gdk_gl_font_use_pango_font_for_display: * @display: a #GdkDisplay. * @font_desc: a #PangoFontDescription describing the font to use. * @first: the index of the first glyph to be taken. * @count: the number of glyphs to be taken. * @list_base: the index of the first display list to be generated. * * Creates bitmap display lists from a #PangoFont. * * Return value: the #PangoFont used, or NULL if no font matched. **/ PangoFont * gdk_gl_font_use_pango_font_for_display (GdkDisplay *display, const PangoFontDescription *font_desc, int first, int count, int list_base) { PangoFontMap *font_map; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); g_return_val_if_fail (font_desc != NULL, NULL); GDK_GL_NOTE_FUNC (); font_map = pango_x_font_map_for_display (GDK_DISPLAY_XDISPLAY (display)); return gdk_gl_font_use_pango_font_common (font_map, font_desc, first, count, list_base); }
GdkGLContext * _gdk_win32_gl_context_impl_get_current (void) { static GdkGLContext *current = NULL; HGLRC hglrc; GDK_GL_NOTE_FUNC (); hglrc = wglGetCurrentContext (); if (hglrc == NULL) return NULL; if (current && GDK_GL_CONTEXT_HGLRC (current) == hglrc) return current; current = gdk_gl_context_lookup (hglrc); return current; }
GdkGLContext * gdk_win32_gl_context_foreign_new (GdkGLConfig *glconfig, GdkGLContext *share_list, HGLRC hglrc) { GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_GL_CONFIG_IMPL_WIN32 (glconfig), NULL); g_return_val_if_fail (hglrc != NULL, NULL); /* * Instantiate the GdkGLContextImplWin32 object. */ return gdk_gl_context_new_common (glconfig, share_list, (glconfig->is_rgba) ? GDK_GL_RGBA_TYPE : GDK_GL_COLOR_INDEX_TYPE, hglrc, TRUE); }
/** * gdk_gl_font_use_pango_font: * @font_desc: a #PangoFontDescription describing the font to use. * @first: the index of the first glyph to be taken. * @count: the number of glyphs to be taken. * @list_base: the index of the first display list to be generated. * * Creates bitmap display lists from a #PangoFont. * * Return value: the #PangoFont used, or NULL if no font matched. **/ PangoFont * gdk_gl_font_use_pango_font (const PangoFontDescription *font_desc, int first, int count, int list_base) { PangoFontMap *font_map; g_return_val_if_fail (font_desc != NULL, NULL); GDK_GL_NOTE_FUNC (); #ifdef GDKGLEXT_MULTIHEAD_SUPPORT font_map = pango_x_font_map_for_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); #else /* GDKGLEXT_MULTIHEAD_SUPPORT */ font_map = pango_x_font_map_for_display (gdk_x11_get_default_xdisplay ()); #endif /* GDKGLEXT_MULTIHEAD_SUPPORT */ return gdk_gl_font_use_pango_font_common (font_map, font_desc, first, count, list_base); }
/** * gdk_pixmap_unset_gl_capability: * @pixmap: a #GdkPixmap. * * Unset the OpenGL-capability of the @pixmap. * This function destroys the #GdkGLPixmap held by the @pixmap. * **/ void gdk_pixmap_unset_gl_capability (GdkPixmap *pixmap) { GdkGLPixmap *glpixmap; GDK_GL_NOTE_FUNC (); if (quark_gl_pixmap == 0) quark_gl_pixmap = g_quark_from_static_string (quark_gl_pixmap_string); /* * Destroy OpenGL resources explicitly, then unref. */ glpixmap = g_object_get_qdata (G_OBJECT (pixmap), quark_gl_pixmap); if (glpixmap == NULL) return; _gdk_gl_pixmap_destroy (glpixmap); g_object_set_qdata (G_OBJECT (pixmap), quark_gl_pixmap, NULL); }
GdkGLContextImpl * _gdk_win32_gl_context_impl_new_from_hglrc (GdkGLContext *glcontext, GdkGLConfig *glconfig, GdkGLContext *share_list, HGLRC hglrc) { GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_WIN32_GL_CONFIG (glconfig), NULL); g_return_val_if_fail (hglrc != NULL, NULL); /* * Instantiate the GdkGLContextImplWin32 object. */ return gdk_win32_gl_context_impl_new_common (glcontext, glconfig, share_list, GDK_GL_RGBA_TYPE, hglrc, TRUE); }
/** * gdk_window_unset_gl_capability: * @window: a #GdkWindow. * * Unset the OpenGL-capability of the @window. * This function destroys the #GdkGLWindow held by the @window. * **/ void gdk_window_unset_gl_capability (GdkWindow *window) { GdkGLWindow *glwindow; GDK_GL_NOTE_FUNC (); if (quark_gl_window == 0) quark_gl_window = g_quark_from_static_string (quark_gl_window_string); /* * Destroy OpenGL resources explicitly, then unref. */ glwindow = g_object_get_qdata (G_OBJECT (window), quark_gl_window); if (glwindow == NULL) return; GDK_GL_WINDOW_IMPL_GET_CLASS(glwindow->impl)->destroy_gl_window_impl(glwindow); g_object_set_qdata (G_OBJECT (window), quark_gl_window, NULL); }
/** * gdk_pixmap_set_gl_capability: * @pixmap: the #GdkPixmap 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 @pixmap. * This function creates a new #GdkGLPixmap held by the @pixmap. * attrib_list is currently unused. This must be set to NULL or empty * (first attribute of None). * * Return value: the #GdkGLPixmap used by the @pixmap if it is successful, * NULL otherwise. **/ GdkGLPixmap * gdk_pixmap_set_gl_capability (GdkPixmap *pixmap, GdkGLConfig *glconfig, const int *attrib_list) { GdkGLPixmap *glpixmap; GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_PIXMAP (pixmap), NULL); g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL); if (quark_gl_pixmap == 0) quark_gl_pixmap = g_quark_from_static_string (quark_gl_pixmap_string); /* If already set */ glpixmap = g_object_get_qdata (G_OBJECT (pixmap), quark_gl_pixmap); if (glpixmap != NULL) return glpixmap; /* * Create GdkGLPixmap */ glpixmap = gdk_gl_pixmap_new (glconfig, pixmap, attrib_list); if (glpixmap == NULL) { g_warning ("cannot create GdkGLPixmap\n"); return NULL; } g_object_set_qdata_full (G_OBJECT (pixmap), quark_gl_pixmap, glpixmap, (GDestroyNotify) g_object_unref); return glpixmap; }
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; }
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__ */ }
/* * 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; }
/** * gdk_gl_pixmap_new: * @glconfig: a #GdkGLConfig. * @pixmap: the #GdkPixmap to be used as the rendering area. * @attrib_list: this must be set to NULL or empty (first attribute of None). * * Creates an off-screen rendering area. * attrib_list is currently unused. This must be set to NULL or empty * (first attribute of None). See GLX 1.3 spec. * * Return value: the new #GdkGLPixmap. **/ GdkGLPixmap * gdk_gl_pixmap_new (GdkGLConfig *glconfig, GdkPixmap *pixmap, const int *attrib_list) { GdkGLPixmap *glpixmap; GdkGLPixmapImplX11 *impl; Display *xdisplay; XVisualInfo *xvinfo; Pixmap xpixmap; GLXPixmap glxpixmap; Window root_return; int x_return, y_return; unsigned int width_return, height_return; unsigned int border_width_return; unsigned int depth_return; GdkGL_GLX_MESA_pixmap_colormap *mesa_ext; GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_GL_CONFIG_IMPL_X11 (glconfig), NULL); g_return_val_if_fail (GDK_IS_PIXMAP (pixmap), NULL); xdisplay = GDK_GL_CONFIG_XDISPLAY (glconfig); xvinfo = GDK_GL_CONFIG_XVINFO (glconfig); /* * Get X Pixmap. */ xpixmap = GDK_DRAWABLE_XID (GDK_DRAWABLE (pixmap)); /* * Check depth of the X pixmap. */ if (!XGetGeometry (xdisplay, xpixmap, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return)) return NULL; if (depth_return != (unsigned int) xvinfo->depth) return NULL; /* * Create GLXPixmap. */ mesa_ext = gdk_gl_get_GLX_MESA_pixmap_colormap (glconfig); if (mesa_ext) { /* If GLX_MESA_pixmap_colormap is supported. */ GDK_GL_NOTE_FUNC_IMPL ("glXCreateGLXPixmapMESA"); glxpixmap = mesa_ext->glXCreateGLXPixmapMESA (xdisplay, xvinfo, xpixmap, GDK_GL_CONFIG_XCOLORMAP (glconfig)); } else { GDK_GL_NOTE_FUNC_IMPL ("glXCreateGLXPixmap"); glxpixmap = glXCreateGLXPixmap (xdisplay, xvinfo, xpixmap); } if (glxpixmap == None) return NULL; /* * Instantiate the GdkGLPixmapImplX11 object. */ glpixmap = g_object_new (GDK_TYPE_GL_PIXMAP_IMPL_X11, NULL); impl = GDK_GL_PIXMAP_IMPL_X11 (glpixmap); glpixmap->drawable = GDK_DRAWABLE (pixmap); g_object_add_weak_pointer (G_OBJECT (glpixmap->drawable), (gpointer *) &(glpixmap->drawable)); impl->glxpixmap = glxpixmap; impl->glconfig = glconfig; g_object_ref (G_OBJECT (impl->glconfig)); impl->is_destroyed = FALSE; return glpixmap; }
/* * 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; }
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; }