示例#1
0
/*
=================
GL_CheckExtension
=================
*/
void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext )
{
	const dllfunc_t	*func;
	convar_t		*parm;

	MsgDev( D_NOTE, "GL_CheckExtension: %s ", name );

	if( cvarname )
	{
		// system config disable extensions
		parm = Cvar_Get( cvarname, "1", CVAR_GLCONFIG, va( "enable or disable %s", name ));

		if( parm->integer == 0 || ( gl_extensions->integer == 0 && r_ext != GL_OPENGL_110 ))
		{
			MsgDev( D_NOTE, "- disabled\n" );
			GL_SetExtension( r_ext, 0 );
			return; // nothing to process at
		}
		GL_SetExtension( r_ext, 1 );
	}

	if(( name[2] == '_' || name[3] == '_' ) && !Q_strstr( glConfig.extensions_string, name ))
	{
		GL_SetExtension( r_ext, false );	// update render info
		MsgDev( D_NOTE, "- ^1failed\n" );
		return;
	}

	// clear exports
	for( func = funcs; func && func->name; func++ )
		*func->func = NULL;


	GL_SetExtension( r_ext, true ); // predict extension state
	for( func = funcs; func && func->name != NULL; func++ )
	{
		// functions are cleared before all the extensions are evaluated
		if(!(*func->func = (void *)GL_GetProcAddress( func->name )))
			GL_SetExtension( r_ext, false ); // one or more functions are invalid, extension will be disabled
	}

	if( GL_Support( r_ext ))
		MsgDev( D_NOTE, "- ^2enabled\n" );
	else MsgDev( D_NOTE, "- ^1failed\n" );
}
示例#2
0
qboolean VID_InitMode(viddef_mode_t *mode)
{
	const EventTypeSpec winEvents[] =
	{
		{ kEventClassWindow, kEventWindowClosed },
		{ kEventClassWindow, kEventWindowCollapsing },
		{ kEventClassWindow, kEventWindowExpanded },
	};
	OSStatus carbonError;
	Rect windowBounds;
	CFStringRef windowTitle;
	AGLPixelFormat pixelFormat;
	GLint attributes [32];
	GLenum error;

	if (!GL_OpenLibrary())
	{
		Con_Printf("Unable to load GL driver\n");
		return false;
	}

	if ((qaglChoosePixelFormat = (AGLPixelFormat (*) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList))GL_GetProcAddress("aglChoosePixelFormat")) == NULL
	 || (qaglCreateContext = (AGLContext (*) (AGLPixelFormat pix, AGLContext share))GL_GetProcAddress("aglCreateContext")) == NULL
	 || (qaglDestroyContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglDestroyContext")) == NULL
	 || (qaglDestroyPixelFormat = (void (*) (AGLPixelFormat pix))GL_GetProcAddress("aglDestroyPixelFormat")) == NULL
	 || (qaglErrorString = (const GLubyte* (*) (GLenum code))GL_GetProcAddress("aglErrorString")) == NULL
	 || (qaglGetError = (GLenum (*) (void))GL_GetProcAddress("aglGetError")) == NULL
	 || (qaglSetCurrentContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglSetCurrentContext")) == NULL
	 || (qaglSetDrawable = (GLboolean (*) (AGLContext ctx, AGLDrawable draw))GL_GetProcAddress("aglSetDrawable")) == NULL
	 || (qaglSetFullScreen = (GLboolean (*) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device))GL_GetProcAddress("aglSetFullScreen")) == NULL
	 || (qaglSetInteger = (GLboolean (*) (AGLContext ctx, GLenum pname, const GLint *params))GL_GetProcAddress("aglSetInteger")) == NULL
	 || (qaglSwapBuffers = (void (*) (AGLContext ctx))GL_GetProcAddress("aglSwapBuffers")) == NULL
	)
	{
		Con_Printf("AGL functions not found\n");
		ReleaseWindow(window);
		return false;
	}

	qCGLEnable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLEnable");
	qCGLDisable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLDisable");
	qCGLGetCurrentContext = (CGLContextObj (*) (void)) CGL_GetProcAddress("CGLGetCurrentContext");
	if(!qCGLEnable || !qCGLDisable || !qCGLGetCurrentContext)
		Con_Printf("CGL functions not found; disabling multithreaded OpenGL\n");

	// Ignore the events from the previous window
	AsyncEvent_Quitting = false;
	AsyncEvent_Collapsed = false;

	// Create the window, a bit towards the center of the screen
	windowBounds.left = 100;
	windowBounds.top = 100;
	windowBounds.right = mode->width + 100;
	windowBounds.bottom = mode->height + 100;
	carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window);
	if (carbonError != noErr || window == NULL)
	{
		Con_Printf("Unable to create window (error %u)\n", (unsigned)carbonError);
		return false;
	}

	// Set the window title
	windowTitle = CFSTR("DarkPlaces AGL");
	SetWindowTitleWithCFString(window, windowTitle);

	// Install the callback function for the window events we can't get
	// through ReceiveNextEvent (i.e. close, collapse, and expand)
	InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler),
							   GetEventTypeCount(winEvents), winEvents, window, NULL);

	// Create the desired attribute list
	VID_BuildAGLAttrib(attributes, mode->bitsperpixel == 32, mode->fullscreen, mode->stereobuffer, mode->samples);

	if (!mode->fullscreen)
	{
		// Output to Window
		pixelFormat = qaglChoosePixelFormat(NULL, 0, attributes);
		error = qaglGetError();
		if (error != AGL_NO_ERROR)
		{
			Con_Printf("qaglChoosePixelFormat FAILED: %s\n",
					(char *)qaglErrorString(error));
			ReleaseWindow(window);
			return false;
		}
	}
	else  // Output is fullScreen
	{
		CGDirectDisplayID mainDisplay;
		CFDictionaryRef refDisplayMode;
		GDHandle gdhDisplay;

		// Get the mainDisplay and set resolution to current
		mainDisplay = CGMainDisplayID();
		CGDisplayCapture(mainDisplay);

		// TOCHECK: not sure whether or not it's necessary to change the resolution
		// "by hand", or if aglSetFullscreen does the job anyway
		refDisplayMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty(mainDisplay, mode->bitsperpixel, mode->width, mode->height, mode->refreshrate, kCGDisplayModeIsSafeForHardware, NULL);
		CGDisplaySwitchToMode(mainDisplay, refDisplayMode);
		DMGetGDeviceByDisplayID((DisplayIDType)mainDisplay, &gdhDisplay, false);

		// Set pixel format with built attribs
		// Note: specifying a device is *required* for AGL_FullScreen
		pixelFormat = qaglChoosePixelFormat(&gdhDisplay, 1, attributes);
		error = qaglGetError();
		if (error != AGL_NO_ERROR)
		{
			Con_Printf("qaglChoosePixelFormat FAILED: %s\n",
						(char *)qaglErrorString(error));
			ReleaseWindow(window);
			return false;
		}
	}

	// Create a context using the pform
	context = qaglCreateContext(pixelFormat, NULL);
	error = qaglGetError();
	if (error != AGL_NO_ERROR)
	{
		Con_Printf("qaglCreateContext FAILED: %s\n",
					(char *)qaglErrorString(error));
	}

	// Make the context the current one ('enable' it)
	qaglSetCurrentContext(context);
	error = qaglGetError();
	if (error != AGL_NO_ERROR)
	{
		Con_Printf("qaglSetCurrentContext FAILED: %s\n",
					(char *)qaglErrorString(error));
		ReleaseWindow(window);
		return false;
	}

	// Discard pform
	qaglDestroyPixelFormat(pixelFormat);

	// Attempt fullscreen if requested
	if (mode->fullscreen)
	{
		qaglSetFullScreen (context, mode->width, mode->height, mode->refreshrate, 0);
		error = qaglGetError();
		if (error != AGL_NO_ERROR)
		{
			Con_Printf("qaglSetFullScreen FAILED: %s\n",
						(char *)qaglErrorString(error));
			return false;
		}
	}
	else
	{
		// Set Window as Drawable
		qaglSetDrawable(context, GetWindowPort(window));
		error = qaglGetError();
		if (error != AGL_NO_ERROR)
		{
			Con_Printf("qaglSetDrawable FAILED: %s\n",
						(char *)qaglErrorString(error));
			ReleaseWindow(window);
			return false;
		}
	}

	if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
		Sys_Error("glGetString not found in %s", gl_driver);

	gl_platformextensions = "";
	gl_platform = "AGL";

	multithreadedgl = false;
	vid_isfullscreen = mode->fullscreen;
	vid_usingmouse = false;
	vid_usinghidecursor = false;
	vid_hidden = false;
	vid_activewindow = true;
	sound_active = true;
	GL_Init();

	SelectWindow(window);
	ShowWindow(window);

	return true;
}