Esempio n. 1
0
bool GSWndWGL::CreateContext(int major, int minor)
{
	if ( !m_NativeDisplay || !m_NativeWindow )
	{
		fprintf( stderr, "Wrong display/window\n" );
		exit(1);
	}

	// GL2 context are quite easy but we need GL3 which is another painful story...
	m_context = wglCreateContext(m_NativeDisplay);
	if (!m_context) {
		fprintf(stderr, "Failed to create a 2.0 context\n");
		return false;
	}

	// FIXME test it
	// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
	// On linux it works without the extra temporary context, not sure the limitation still applied
	if (major >= 3) {
		AttachContext();

		// Create a context
		int context_attribs[] =
		{
			WGL_CONTEXT_MAJOR_VERSION_ARB, major,
			WGL_CONTEXT_MINOR_VERSION_ARB, minor,
			// FIXME : Request a debug context to ease opengl development
			// Note: don't support deprecated feature (pre openg 3.1)
			//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
			WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
#ifdef ENABLE_OGL_DEBUG
			| WGL_CONTEXT_DEBUG_BIT_ARB
#endif
			,
			WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
			0
		};

		PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
		if (!wglCreateContextAttribsARB) {
			fprintf(stderr, "Failed to init wglCreateContextAttribsARB function pointer\n");
			return false;
		}

		HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
		if (!context30) {
			fprintf(stderr, "Failed to create a 3.x context\n");
			return false;
		}

		DetachContext();
		wglDeleteContext(m_context);

		m_context = context30;
		fprintf(stderr, "3.x GL context successfully created\n");
	}

	return true;
}
Esempio n. 2
0
void GSWndWGL::Detach()
{
	// Actually the destructor is not called when there is only a GSclose/GSshutdown
	// The window still need to be closed
	DetachContext();

	if (m_context) wglDeleteContext(m_context);
	m_context = NULL;

	CloseWGLDisplay();
}
Esempio n. 3
0
void GSWndOGL::Detach()
{
	// Actually the destructor is not called when there is only a GSclose/GSshutdown
	// The window still need to be closed
	DetachContext();
	if (m_context) glXDestroyContext(m_NativeDisplay, m_context);

	if (m_NativeDisplay) {
		XCloseDisplay(m_NativeDisplay);
		m_NativeDisplay = NULL;
	}
}
Esempio n. 4
0
void GSWndEGL::Detach()
{
	// Actually the destructor is not called when there is only a GSclose/GSshutdown
	// The window still need to be closed
	DetachContext();
	eglDestroyContext(m_eglDisplay, m_eglContext);
	m_eglContext = NULL;
	eglDestroySurface(m_eglDisplay, m_eglSurface);
	m_eglSurface = NULL;
	CloseEGLDisplay();

	if (m_NativeDisplay) {
		XCloseDisplay(m_NativeDisplay);
		m_NativeDisplay = NULL;
	}
}
Esempio n. 5
0
void GSWndWGL::Detach()
{
	// Actually the destructor is not called when there is only a GSclose/GSshutdown
	// The window still need to be closed
	DetachContext();

	if (m_context) wglDeleteContext(m_context);
	m_context = NULL;

	CloseWGLDisplay();

	// Used by GSReplay.
	if (m_NativeWindow && m_managed)
	{
		DestroyWindow(m_NativeWindow);
		m_NativeWindow = NULL;
	}

}
Esempio n. 6
0
void GSWndWGL::CreateContext(int major, int minor)
{
	if (!m_NativeDisplay || !m_NativeWindow)
	{
		win_error("Wrong display/window", false);
		exit(1);
	}

	ASSERT(major >= 3);

	// GL2 context are quite easy but we need GL3 which is another painful story...
	m_context = wglCreateContext(m_NativeDisplay);
	if (!m_context)
		win_error("Failed to create a 2.0 context");

	// FIXME test it
	// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
	// On linux it works without the extra temporary context, not sure the limitation still applied
	AttachContext();

	// Create a context
	int context_attribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, major,
		WGL_CONTEXT_MINOR_VERSION_ARB, minor,
		// FIXME : Request a debug context to ease opengl development
		// Note: don't support deprecated feature (pre openg 3.1)
		//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
#ifdef ENABLE_OGL_DEBUG
			| WGL_CONTEXT_DEBUG_BIT_ARB
#else
			| GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
#endif
			,
		WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
		0
	};

	PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
	if (!wglCreateContextAttribsARB)
		win_error("Failed to init wglCreateContextAttribsARB function pointer");

	HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
	if (!context30) {
		win_error("Failed to create a 3.x context with standard flags", false);
		// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
		context_attribs[2*2+1] = 0;

		context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
	}

	DetachContext();
	wglDeleteContext(m_context);

	if (!context30)
		win_error("Failed to create a 3.x context with compatible flags");

	m_context = context30;
	fprintf(stderr, "3.x GL context successfully created\n");
}