GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextType type) { GHOST_TSuccess success; switch (type) { case GHOST_kDrawingContextTypeOpenGL: { if(m_stereoVisual) sPreferredFormat.dwFlags |= PFD_STEREO; // Attempt to match device context pixel format to the preferred format int iPixelFormat = EnumPixelFormats(m_hDC); if (iPixelFormat == 0) { success = GHOST_kFailure; break; } if (::SetPixelFormat(m_hDC, iPixelFormat, &sPreferredFormat) == FALSE) { success = GHOST_kFailure; break; } // For debugging only: retrieve the pixel format chosen PIXELFORMATDESCRIPTOR preferredFormat; ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &preferredFormat); // Create the context m_hGlRc = ::wglCreateContext(m_hDC); if (m_hGlRc) { if (s_firsthGLRc) { wglShareLists(s_firsthGLRc, m_hGlRc); } else { s_firsthGLRc = m_hGlRc; } success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; } else { success = GHOST_kFailure; } } break; case GHOST_kDrawingContextTypeNone: success = GHOST_kSuccess; break; default: success = GHOST_kFailure; } return success; }
GdkGLConfig *GLBase::MakeStandardConfig() { #ifdef _WINDOWS HDC hDC = GetDC(NULL); GdkGLConfig *ret = gdk_win32_gl_config_new_from_pixel_format(EnumPixelFormats(hDC)); DeleteDC(hDC); return ret; #else GdkGLConfig *ret = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGBA | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_DEPTH | GDK_GL_MODE_STENCIL)); if (ret == NULL) { ret = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGBA | GDK_GL_MODE_SINGLE | GDK_GL_MODE_DEPTH | GDK_GL_MODE_STENCIL)); if (ret == NULL) { printf("Cannot generate a suitable OpenGL Context Configuration, exiting....."); exit(-1); } } return ret; #endif }
GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextType type) { GHOST_TSuccess success; switch (type) { case GHOST_kDrawingContextTypeOpenGL: { // If this window has multisample enabled, use the supplied format if (m_multisampleEnabled) { if (SetPixelFormat(m_hDC, m_msPixelFormat, &sPreferredFormat) == FALSE) { success = GHOST_kFailure; break; } // Create the context m_hGlRc = ::wglCreateContext(m_hDC); if (m_hGlRc) { if (::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE) { if (s_firsthGLRc) { if (is_crappy_intel_card()) { if (::wglMakeCurrent(NULL, NULL) == TRUE) { ::wglDeleteContext(m_hGlRc); m_hGlRc = s_firsthGLRc; } else { ::wglDeleteContext(m_hGlRc); m_hGlRc = NULL; } } else { ::wglCopyContext(s_firsthGLRc, m_hGlRc, GL_ALL_ATTRIB_BITS); ::wglShareLists(s_firsthGLRc, m_hGlRc); } } else { s_firsthGLRc = m_hGlRc; } if (m_hGlRc) { success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; } else { success = GHOST_kFailure; } } else { success = GHOST_kFailure; } } else { success = GHOST_kFailure; } if (success == GHOST_kFailure) { printf("Failed to get a context....\n"); } } else { if (m_stereoVisual) sPreferredFormat.dwFlags |= PFD_STEREO; // Attempt to match device context pixel format to the preferred format int iPixelFormat = EnumPixelFormats(m_hDC); if (iPixelFormat == 0) { success = GHOST_kFailure; break; } if (::SetPixelFormat(m_hDC, iPixelFormat, &sPreferredFormat) == FALSE) { success = GHOST_kFailure; break; } // For debugging only: retrieve the pixel format chosen PIXELFORMATDESCRIPTOR preferredFormat; ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &preferredFormat); // Create the context m_hGlRc = ::wglCreateContext(m_hDC); if (m_hGlRc) { if (::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE) { if (s_firsthGLRc) { if (is_crappy_intel_card()) { if (::wglMakeCurrent(NULL, NULL) == TRUE) { ::wglDeleteContext(m_hGlRc); m_hGlRc = s_firsthGLRc; } else { ::wglDeleteContext(m_hGlRc); m_hGlRc = NULL; } } else { ::wglShareLists(s_firsthGLRc, m_hGlRc); } } else { s_firsthGLRc = m_hGlRc; } if (m_hGlRc) { success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure; } else { success = GHOST_kFailure; } } else { success = GHOST_kFailure; } } else { success = GHOST_kFailure; } if (success == GHOST_kFailure) { printf("Failed to get a context....\n"); } // Attempt to enable multisample if (m_multisample && WGL_ARB_multisample && !m_multisampleEnabled && !is_crappy_intel_card()) { success = initMultisample(preferredFormat); if (success) { // Make sure we don't screw up the context if (m_hGlRc == s_firsthGLRc) s_firsthGLRc = NULL; m_drawingContextType = GHOST_kDrawingContextTypeOpenGL; removeDrawingContext(); // Create a new window GHOST_TWindowState new_state = getState(); m_nextWindow = new GHOST_WindowWin32((GHOST_SystemWin32 *)GHOST_ISystem::getSystem(), m_title, m_left, m_top, m_width, m_height, new_state, type, m_stereo, m_multisample, m_parentWindowHwnd, m_multisampleEnabled, m_msPixelFormat); // Return failure so we can trash this window. success = GHOST_kFailure; break; } else { m_multisampleEnabled = GHOST_kSuccess; printf("Multisample failed to initialized\n"); success = GHOST_kSuccess; } } } } break; case GHOST_kDrawingContextTypeNone: success = GHOST_kSuccess; break; default: success = GHOST_kFailure; } return success; }