Beispiel #1
0
/*
** - get a DC if one doesn't exist
** - create an HGLRC if one doesn't exist
*/
static qbool GLW_InitDriver( int colorbits )
{
	int		tpfd;
	int		depthbits, stencilbits;
	static PIXELFORMATDESCRIPTOR pfd;		// save between frames since 'tr' gets cleared

	ri.Printf( PRINT_DEVELOPER, "Initializing OpenGL driver\n" );

	//
	// get a DC for our window if we don't already have one allocated
	//
	if ( glw_state.hDC == NULL )
	{
		if ( ( glw_state.hDC = GetDC( g_wv.hWnd ) ) == NULL )
		{
			ri.Printf( PRINT_ALL, "...Get DC failed\n" );
			return qfalse;
		}
		ri.Printf( PRINT_DEVELOPER, "...Get DC succeeded\n" );
	}

	if ( colorbits == 0 )
	{
		colorbits = glw_state.desktopBPP;
	}

	//
	// implicitly assume Z-buffer depth == desktop color depth
	//
	if ( r_depthbits->integer == 0 ) {
		if ( colorbits > 16 ) {
			depthbits = 24;
		} else {
			depthbits = 16;
		}
	} else {
		depthbits = r_depthbits->integer;
	}

	//
	// do not allow stencil if Z-buffer depth likely won't contain it
	//
	stencilbits = r_stencilbits->integer;
	if ( depthbits < 24 )
	{
		stencilbits = 0;
	}

	//
	// make two attempts to set the PIXELFORMAT
	//

	//
	// first attempt: r_colorbits, depthbits, and r_stencilbits
	//
	if ( !glw_state.pixelFormatSet )
	{
		GLW_CreatePFD( &pfd, colorbits, depthbits, stencilbits, (qbool)r_stereo->integer );
		if ( ( tpfd = GLW_MakeContext( &pfd ) ) != TRY_PFD_SUCCESS )
		{
			if ( tpfd == TRY_PFD_FAIL_HARD )
			{
				ri.Printf( PRINT_WARNING, "...failed hard\n" );
				return qfalse;
			}

			//
			// punt if we've already tried the desktop bit depth and no stencil bits
			//
			if ( ( r_colorbits->integer == glw_state.desktopBPP ) && !stencilbits )
			{
				ReleaseDC( g_wv.hWnd, glw_state.hDC );
				glw_state.hDC = NULL;
				ri.Printf( PRINT_ALL, "...failed to find an appropriate PIXELFORMAT\n" );
				return qfalse;
			}

			//
			// second attempt: desktop's color bits and no stencil
			//
			if ( colorbits > glw_state.desktopBPP )
				colorbits = glw_state.desktopBPP;

			GLW_CreatePFD( &pfd, colorbits, depthbits, 0, (qbool)r_stereo->integer );
			if ( GLW_MakeContext( &pfd ) != TRY_PFD_SUCCESS )
			{
				if ( glw_state.hDC )
				{
					ReleaseDC( g_wv.hWnd, glw_state.hDC );
					glw_state.hDC = NULL;
				}
				ri.Printf( PRINT_ALL, "...failed to find an appropriate PIXELFORMAT\n" );
				return qfalse;
			}
		}

		// report if stereo is desired but unavailable
		//
		if ( r_stereo->integer && !( pfd.dwFlags & PFD_STEREO ) )
		{
			ri.Printf( PRINT_ALL, "...failed to select stereo pixel format\n" );
			glConfig.stereoEnabled = qfalse;
		}
	}

	// store PFD specifics
	//
	glConfig.colorBits = ( int ) pfd.cColorBits;
	glConfig.depthBits = ( int ) pfd.cDepthBits;
	glConfig.stencilBits = ( int ) pfd.cStencilBits;

	return qtrue;
}
Beispiel #2
0
//	- get a DC if one doesn't exist
//	- create an HGLRC if one doesn't exist
static bool GLW_InitDriver( int colorbits ) {
	static PIXELFORMATDESCRIPTOR pfd;		// save between frames since 'tr' gets cleared

	common->Printf( "Initializing OpenGL driver\n" );

	//
	// get a DC for our window if we don't already have one allocated
	//
	if ( maindc == NULL ) {
		common->Printf( "...getting DC: " );

		if ( ( maindc = GetDC( GMainWindow ) ) == NULL ) {
			common->Printf( "failed\n" );
			return false;
		}
		common->Printf( "succeeded\n" );
	}

	if ( colorbits == 0 ) {
		colorbits = desktopBitsPixel;
	}

	//
	// implicitly assume Z-buffer depth == desktop color depth
	//
	int depthbits;
	if ( r_depthbits->integer == 0 ) {
		if ( colorbits > 16 ) {
			depthbits = 24;
		} else {
			depthbits = 16;
		}
	} else {
		depthbits = r_depthbits->integer;
	}

	//
	// do not allow stencil if Z-buffer depth likely won't contain it
	//
	int stencilbits = r_stencilbits->integer;
	if ( depthbits < 24 ) {
		stencilbits = 0;
	}

	//
	// make two attempts to set the PIXELFORMAT
	//

	//
	// first attempt: r_colorbits, depthbits, and r_stencilbits
	//
	if ( !pixelFormatSet ) {
		GLW_CreatePFD( &pfd, colorbits, depthbits, stencilbits, !!r_stereo->integer );
		int tpfd = GLW_MakeContext( &pfd );
		if ( tpfd != TRY_PFD_SUCCESS ) {
			if ( tpfd == TRY_PFD_FAIL_HARD ) {
				if ( maindc ) {
					ReleaseDC( GMainWindow, maindc );
					maindc = NULL;
				}

				common->Printf( S_COLOR_YELLOW "...failed hard\n" );
				return false;
			}

			//
			// punt if we've already tried the desktop bit depth and no stencil bits
			//
			if ( ( r_colorbits->integer == desktopBitsPixel ) && ( stencilbits == 0 ) ) {
				if ( maindc ) {
					ReleaseDC( GMainWindow, maindc );
					maindc = NULL;
				}

				common->Printf( "...failed to find an appropriate PIXELFORMAT\n" );

				return false;
			}

			//
			// second attempt: desktop's color bits and no stencil
			//
			if ( colorbits > desktopBitsPixel ) {
				colorbits = desktopBitsPixel;
			}
			GLW_CreatePFD( &pfd, colorbits, depthbits, 0, !!r_stereo->integer );
			if ( GLW_MakeContext( &pfd ) != TRY_PFD_SUCCESS ) {
				if ( maindc ) {
					ReleaseDC( GMainWindow, maindc );
					maindc = NULL;
				}

				common->Printf( "...failed to find an appropriate PIXELFORMAT\n" );

				return false;
			}
		}

		//
		//	Report if stereo is desired but unavailable.
		//
		if ( !( pfd.dwFlags & PFD_STEREO ) && ( r_stereo->integer != 0 ) ) {
			common->Printf( "...failed to select stereo pixel format\n" );
			glConfig.stereoEnabled = false;
		}
	}

	//
	//	Store PFD specifics.
	//
	glConfig.colorBits = ( int )pfd.cColorBits;
	glConfig.depthBits = ( int )pfd.cDepthBits;
	glConfig.stencilBits = ( int )pfd.cStencilBits;

	return true;
}