static void gdk_gl_config_init_attrib (GdkGLConfig *glconfig) { PIXELFORMATDESCRIPTOR *pfd; pfd = GDK_GL_CONFIG_PFD (glconfig); /* RGBA mode? */ glconfig->is_rgba = (pfd->iPixelType == PFD_TYPE_RGBA) ? TRUE : FALSE; /* Layer plane. */ if (pfd->bReserved != 0) { glconfig->layer_plane = pfd->bReserved & 0x0f; if (glconfig->layer_plane == 0) glconfig->layer_plane = -1 * ((pfd->bReserved & 0xf0) >> 4); }
/* * 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; }
/* * 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; }