コード例 #1
0
GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
{
	GHOST_TSuccess success = GHOST_kSuccess;
	if (type != m_drawingContextType) {
		success = removeDrawingContext();
		if (success) {
			success = installDrawingContext(type);
			m_drawingContextType = type;
		}
		else {
			m_drawingContextType = GHOST_kDrawingContextTypeNone;
		}
	}
	return success;
}
コード例 #2
0
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;
}