r373 - in trunk/code: . SDL12 botlib client libs libs/macosx qcommon renderer tools/asm tools/lcc unix

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Nov 26 02:46:40 EST 2005


Author: icculus
Date: 2005-11-26 02:46:21 -0500 (Sat, 26 Nov 2005)
New Revision: 373

Added:
   trunk/code/SDL12/
   trunk/code/SDL12/include/
   trunk/code/libs/
   trunk/code/libs/macosx/
   trunk/code/libs/macosx/libSDL-1.2.0.dylib
   trunk/code/libs/macosx/libSDLmain.a
Removed:
   trunk/code/macosx/
Modified:
   trunk/code/botlib/l_script.c
   trunk/code/botlib/l_script.h
   trunk/code/client/qal.c
   trunk/code/client/qal.h
   trunk/code/client/snd_codec_wav.c
   trunk/code/client/snd_mix.c
   trunk/code/qcommon/common.c
   trunk/code/qcommon/q_platform.h
   trunk/code/qcommon/vm_ppc_new.c
   trunk/code/renderer/qgl.h
   trunk/code/renderer/tr_curve.c
   trunk/code/renderer/tr_init.c
   trunk/code/renderer/tr_shade.c
   trunk/code/renderer/tr_shade_calc.c
   trunk/code/renderer/tr_surface.c
   trunk/code/renderer/tr_types.h
   trunk/code/tools/asm/Makefile
   trunk/code/tools/lcc/Makefile
   trunk/code/unix/Makefile
   trunk/code/unix/linux_glimp.c
   trunk/code/unix/linux_qgl.c
   trunk/code/unix/sdl_glimp.c
   trunk/code/unix/sdl_snd.c
   trunk/code/unix/unix_glw.h
   trunk/code/unix/unix_main.c
Log:

Mac OS X work...lots of little changes that touch a lot of random places.
 Still work to be done, but this at least matches the PowerPC Linux status
 now.

MacOS-specific directory (and XCode project) is gone...this now uses SDL,
 OpenAL, and the Unix Makefiles.

--ryan.




Modified: trunk/code/botlib/l_script.c
===================================================================
--- trunk/code/botlib/l_script.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/botlib/l_script.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -554,7 +554,7 @@
 // Changes Globals:		-
 //============================================================================
 void NumberValue(char *string, int subtype, unsigned long int *intvalue,
-															long double *floatvalue)
+															double *floatvalue)
 {
 	unsigned long int dotfound = 0;
 
@@ -573,13 +573,13 @@
 			} //end if
 			if (dotfound)
 			{
-				*floatvalue = *floatvalue + (long double) (*string - '0') /
-																	(long double) dotfound;
+				*floatvalue = *floatvalue + (double) (*string - '0') /
+																	(double) dotfound;
 				dotfound *= 10;
 			} //end if
 			else
 			{
-				*floatvalue = *floatvalue * 10.0 + (long double) (*string - '0');
+				*floatvalue = *floatvalue * 10.0 + (double) (*string - '0');
 			} //end else
 			string++;
 		} //end while
@@ -631,7 +631,7 @@
 	int octal, dot;
 	char c;
 //	unsigned long int intvalue = 0;
-//	long double floatvalue = 0;
+//	double floatvalue = 0;
 
 	token->type = TT_NUMBER;
 	//check for a hexadecimal number
@@ -1148,15 +1148,15 @@
 // Returns:					-
 // Changes Globals:		-
 //============================================================================
-long double ReadSignedFloat(script_t *script)
+double ReadSignedFloat(script_t *script)
 {
 	token_t token;
-	long double sign = 1;
+	double sign = 1.0;
 
 	PS_ExpectAnyToken(script, &token);
 	if (!strcmp(token.string, "-"))
 	{
-		sign = -1;
+		sign = -1.0;
 		PS_ExpectTokenType(script, TT_NUMBER, 0, &token);
 	} //end if
 	else if (token.type != TT_NUMBER)

Modified: trunk/code/botlib/l_script.h
===================================================================
--- trunk/code/botlib/l_script.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/botlib/l_script.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -161,7 +161,7 @@
 	int subtype;					//last read token sub type
 #ifdef NUMBERVALUE
 	unsigned long int intvalue;	//integer value
-	long double floatvalue;			//floating point value
+	double floatvalue;			//floating point value
 #endif //NUMBERVALUE
 	char *whitespace_p;				//start of white space before token
 	char *endwhitespace_p;			//start of white space before token
@@ -218,7 +218,7 @@
 //read a possible signed integer
 signed long int ReadSignedInt(script_t *script);
 //read a possible signed floating point number
-long double ReadSignedFloat(script_t *script);
+double ReadSignedFloat(script_t *script);
 //set an array with punctuations, NULL restores default C/C++ set
 void SetScriptPunctuations(script_t *script, punctuation_t *p);
 //set script flags

Modified: trunk/code/client/qal.c
===================================================================
--- trunk/code/client/qal.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/client/qal.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -28,14 +28,23 @@
 #include "qal.h"
 
 #if USE_OPENAL_DLOPEN
-#if defined _WIN32
+
+#if USE_SDL_VIDEO
+#include "SDL.h"
+#include "SDL_loadso.h"
+#define OBJTYPE void *
+#define OBJLOAD(x) SDL_LoadObject(x)
+#define SYMLOAD(x,y) SDL_LoadFunction(x,y)
+#define OBJFREE(x) SDL_UnloadObject(x)
+
+#elif defined _WIN32
 #include <windows.h>
 #define OBJTYPE HMODULE
 #define OBJLOAD(x) LoadLibrary(x)
 #define SYMLOAD(x,y) GetProcAddress(x,y)
 #define OBJFREE(x) FreeLibrary(x)
 
-#elif defined __linux__ || defined __FreeBSD__
+#elif defined __linux__ || defined __FreeBSD__ || defined MACOS_X
 #include <unistd.h>
 #include <sys/types.h>
 #include <dlfcn.h>

Modified: trunk/code/client/qal.h
===================================================================
--- trunk/code/client/qal.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/client/qal.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -32,8 +32,8 @@
 #define AL_NO_PROTOTYPES
 #define ALC_NO_PROTOTYPES
 #endif
-#include <AL/al.h>
-#include <AL/alc.h>
+#include "../AL/al.h"
+#include "../AL/alc.h"
 
 #if USE_OPENAL_DLOPEN
 extern LPALENABLE qalEnable;

Modified: trunk/code/client/snd_codec_wav.c
===================================================================
--- trunk/code/client/snd_codec_wav.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/client/snd_codec_wav.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -42,7 +42,7 @@
 FGetLittleShort
 =================
 */
-static int FGetLittleShort( fileHandle_t f ) {
+static short FGetLittleShort( fileHandle_t f ) {
 	short	v;
 
 	FS_Read( &v, sizeof(v), f );

Modified: trunk/code/client/snd_mix.c
===================================================================
--- trunk/code/client/snd_mix.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/client/snd_mix.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -224,7 +224,8 @@
 ===============================================================================
 */
 
-static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset ) {
+#if idppc_altivec
+static void S_PaintChannelFrom16_altivec( channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset ) {
 	int						data, aoff, boff;
 	int						leftvol, rightvol;
 	int						i, j;
@@ -249,15 +250,12 @@
 	}
 
 	if (!ch->doppler || ch->dopplerScale==1.0f) {
-#if idppc_altivec
 		vector signed short volume_vec;
 		vector unsigned int volume_shift;
 		int vectorCount, samplesLeft, chunkSamplesLeft;
-#endif
 		leftvol = ch->leftvol*snd_vol;
 		rightvol = ch->rightvol*snd_vol;
 		samples = chunk->sndChunk;
-#if idppc_altivec
 		((short *)&volume_vec)[0] = leftvol;
 		((short *)&volume_vec)[1] = leftvol;
 		((short *)&volume_vec)[4] = leftvol;
@@ -297,14 +295,12 @@
 			{
 				vector unsigned char tmp;
 				vector short s0, s1, sampleData0, sampleData1;
-				vector short samples0, samples1;
-				vector signed int left0, right0;
 				vector signed int merge0, merge1;
 				vector signed int d0, d1, d2, d3;				
-				vector unsigned char samplePermute0 = 
-					(vector unsigned char){0, 1, 4, 5, 0, 1, 4, 5, 2, 3, 6, 7, 2, 3, 6, 7};
+				vector unsigned char samplePermute0 =
+					VECCONST_UINT8(0, 1, 4, 5, 0, 1, 4, 5, 2, 3, 6, 7, 2, 3, 6, 7);
 				vector unsigned char samplePermute1 = 
-					(vector unsigned char){8, 9, 12, 13, 8, 9, 12, 13, 10, 11, 14, 15, 10, 11, 14, 15};
+					VECCONST_UINT8(8, 9, 12, 13, 8, 9, 12, 13, 10, 11, 14, 15, 10, 11, 14, 15);
 				vector unsigned char loadPermute0, loadPermute1;
 				
 				// Rather than permute the vectors after we load them to do the sample
@@ -365,8 +361,67 @@
 				}
 			}
 		}
-#else			
+	} else {
+		fleftvol = ch->leftvol*snd_vol;
+		frightvol = ch->rightvol*snd_vol;
+
+		ooff = sampleOffset;
+		samples = chunk->sndChunk;
+		
 		for ( i=0 ; i<count ; i++ ) {
+
+			aoff = ooff;
+			ooff = ooff + ch->dopplerScale;
+			boff = ooff;
+			fdata = 0;
+			for (j=aoff; j<boff; j++) {
+				if (j == SND_CHUNK_SIZE) {
+					chunk = chunk->next;
+					if (!chunk) {
+						chunk = sc->soundData;
+					}
+					samples = chunk->sndChunk;
+					ooff -= SND_CHUNK_SIZE;
+				}
+				fdata  += samples[j&(SND_CHUNK_SIZE-1)];
+			}
+			fdiv = 256 * (boff-aoff);
+			samp[i].left += (fdata * fleftvol)/fdiv;
+			samp[i].right += (fdata * frightvol)/fdiv;
+		}
+	}
+}
+#endif
+
+static void S_PaintChannelFrom16_scalar( channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset ) {
+	int						data, aoff, boff;
+	int						leftvol, rightvol;
+	int						i, j;
+	portable_samplepair_t	*samp;
+	sndBuffer				*chunk;
+	short					*samples;
+	float					ooff, fdata, fdiv, fleftvol, frightvol;
+
+	samp = &paintbuffer[ bufferOffset ];
+
+	if (ch->doppler) {
+		sampleOffset = sampleOffset*ch->oldDopplerScale;
+	}
+
+	chunk = sc->soundData;
+	while (sampleOffset>=SND_CHUNK_SIZE) {
+		chunk = chunk->next;
+		sampleOffset -= SND_CHUNK_SIZE;
+		if (!chunk) {
+			chunk = sc->soundData;
+		}
+	}
+
+	if (!ch->doppler || ch->dopplerScale==1.0f) {
+		leftvol = ch->leftvol*snd_vol;
+		rightvol = ch->rightvol*snd_vol;
+		samples = chunk->sndChunk;
+		for ( i=0 ; i<count ; i++ ) {
 			data  = samples[sampleOffset++];
 			samp[i].left += (data * leftvol)>>8;
 			samp[i].right += (data * rightvol)>>8;
@@ -377,7 +432,6 @@
 				sampleOffset = 0;
 			}
 		}
-#endif
 	} else {
 		fleftvol = ch->leftvol*snd_vol;
 		frightvol = ch->rightvol*snd_vol;
@@ -412,6 +466,18 @@
 	}
 }
 
+static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sc, int count, int sampleOffset, int bufferOffset ) {
+    #if idppc_altivec
+    extern cvar_t *com_altivec;
+    if (com_altivec->integer) {
+        // must be in a seperate function or G3 systems will crash.
+        S_PaintChannelFrom16_altivec( ch, sc, count, sampleOffset, bufferOffset );
+        return;
+    }
+    #endif
+    S_PaintChannelFrom16_scalar( ch, sc, count, sampleOffset, bufferOffset );
+}
+
 void S_PaintChannelFromWavelet( channel_t *ch, sfx_t *sc, int count, int sampleOffset, int bufferOffset ) {
 	int						data;
 	int						leftvol, rightvol;

Added: trunk/code/libs/macosx/libSDL-1.2.0.dylib
===================================================================
(Binary files differ)


Property changes on: trunk/code/libs/macosx/libSDL-1.2.0.dylib
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: trunk/code/libs/macosx/libSDLmain.a
===================================================================
(Binary files differ)


Property changes on: trunk/code/libs/macosx/libSDLmain.a
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/qcommon/common.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -66,6 +66,7 @@
 cvar_t	*com_dropsim;		// 0.0 to 1.0, simulated packet drops
 cvar_t	*com_journal;
 cvar_t	*com_maxfps;
+cvar_t	*com_altivec;
 cvar_t	*com_timedemo;
 cvar_t	*com_sv_running;
 cvar_t	*com_cl_running;
@@ -2425,6 +2426,7 @@
 	//
 	// init commands and vars
 	//
+	com_altivec = Cvar_Get ("com_altivec", "1", CVAR_ARCHIVE);
 	com_maxfps = Cvar_Get ("com_maxfps", "85", CVAR_ARCHIVE);
 	com_blood = Cvar_Get ("com_blood", "1", CVAR_ARCHIVE);
 
@@ -2507,7 +2509,12 @@
 	Cvar_Set("ui_singlePlayerActive", "0");
 
 	com_fullyInitialized = qtrue;
-	Com_Printf ("--- Common Initialization Complete ---\n");	
+
+    #if idppc_altivec
+	Com_Printf ("Altivec support is %s\n", com_altivec->integer ? "enabled" : "disabled");
+    #endif
+
+	Com_Printf ("--- Common Initialization Complete ---\n");
 }
 
 //==================================================================

Modified: trunk/code/qcommon/q_platform.h
===================================================================
--- trunk/code/qcommon/q_platform.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/qcommon/q_platform.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -51,8 +51,14 @@
 #define idppc_altivec 0
 #endif
 
+#if (MACOS_X)  // Apple's GCC does this differently than the FSF.
+  #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) (vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
+#else
+  #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) (vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}
 #endif
 
+#endif
+
 #ifndef __ASM_I386__ // don't include the C bits if included from qasm.h
 
 // for windows fastcall option

Modified: trunk/code/qcommon/vm_ppc_new.c
===================================================================
--- trunk/code/qcommon/vm_ppc_new.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/qcommon/vm_ppc_new.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -1820,7 +1820,7 @@
 
 #if defined(MACOS_X) && defined(__OPTIMIZE__)
     // On Mac OS X, gcc doesn't push a frame when we are optimized, so trying to tear it down results in grave disorder.
-#warning Mac OS X optimization on, not popping GCC AsmCall frame
+//#warning Mac OS X optimization on, not popping GCC AsmCall frame
 #else
     // Mac OS X Server and unoptimized compiles include a GCC AsmCall frame
     asm (

Modified: trunk/code/renderer/qgl.h
===================================================================
--- trunk/code/renderer/qgl.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/qgl.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -46,8 +46,23 @@
 
 #elif defined(MACOS_X)
 
-#include "macosx_glimp.h"
+#include <OpenGL/OpenGL.h>
+#include <OpenGL/gl.h>
+#include <OpenGL/glu.h>
+#ifndef GL_EXT_abgr
+#include <OpenGL/glext.h>
+#endif
 
+// This can be defined to use the CGLMacro.h support which avoids looking up
+// the current context.
+//#define USE_CGLMACROS
+
+#ifdef USE_CGLMACROS
+#include "macosx_local.h"
+#define cgl_ctx glw_state._cgl_ctx
+#include <OpenGL/CGLMacro.h>
+#endif
+
 #elif defined( __linux__ ) || defined(__FreeBSD__)
 
 #include <GL/gl.h>
@@ -164,7 +179,7 @@
 
 #include "qgl_linked.h"
 
-#elif defined(MACOS_X)
+#elif (defined(MACOS_X) && !defined(USE_SDL_VIDEO))
 // This includes #ifdefs for optional logging and GL error checking after every GL call as well as #defines to prevent incorrect usage of the non-'qgl' versions of the GL API.
 #include "macosx_qgl.h"
 

Modified: trunk/code/renderer/tr_curve.c
===================================================================
--- trunk/code/renderer/tr_curve.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_curve.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -113,7 +113,7 @@
 	int		i, j, k, dist;
 	vec3_t	normal;
 	vec3_t	sum;
-	int		count;
+	int		count = 0;
 	vec3_t	base;
 	vec3_t	delta;
 	int		x, y;

Modified: trunk/code/renderer/tr_init.c
===================================================================
--- trunk/code/renderer/tr_init.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_init.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -150,12 +150,15 @@
 cvar_t	*r_maxpolyverts;
 int		max_polyverts;
 
+/* !!! FIXME: Why are these here?! */
+#if 0
 void ( APIENTRY * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t );
 void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
 void ( APIENTRY * qglClientActiveTextureARB )( GLenum texture );
 
 void ( APIENTRY * qglLockArraysEXT)( GLint, GLint);
 void ( APIENTRY * qglUnlockArraysEXT) ( void );
+#endif
 
 static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral )
 {

Modified: trunk/code/renderer/tr_shade.c
===================================================================
--- trunk/code/renderer/tr_shade.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_shade.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -402,9 +402,9 @@
 Perform dynamic lighting with another rendering pass
 ===================
 */
-static void ProjectDlightTexture( void ) {
+#if idppc_altivec
+static void ProjectDlightTexture_altivec( void ) {
 	int		i, l;
-#if idppc_altivec
 	vec_t	origin0, origin1, origin2;
 	float   texCoords0, texCoords1;
 	vector float floatColorVec0, floatColorVec1;
@@ -412,13 +412,10 @@
 	vector short colorShort;
 	vector signed int colorInt;
 	vector unsigned char floatColorVecPerm, modulatePerm, colorChar;
-	vector unsigned char vSel = (vector unsigned char){0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff};
-#else
-	vec3_t	origin;
-#endif
+	vector unsigned char vSel = VECCONST_UINT8(0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff);
 	float	*texCoords;
 	byte	*colors;
 	byte	clipBits[SHADER_MAX_VERTEXES];
@@ -429,20 +426,18 @@
 	float	scale;
 	float	radius;
 	vec3_t	floatColor;
-	float	modulate;
+	float	modulate = 0.0f;
 
 	if ( !backEnd.refdef.num_dlights ) {
 		return;
 	}
 
-#if idppc_altivec
-	// There has to be a better way to do this so that floatColor 
+	// There has to be a better way to do this so that floatColor
 	// and/or modulate are already 16-byte aligned.
 	floatColorVecPerm = vec_lvsl(0,(float *)floatColor);
 	modulatePerm = vec_lvsl(0,(float *)&modulate);
 	modulatePerm = (vector unsigned char)vec_splat((vector unsigned int)modulatePerm,0);
 	zero = (vector float)vec_splat_s8(0);
-#endif
 
 	for ( l = 0 ; l < backEnd.refdef.num_dlights ; l++ ) {
 		dlight_t	*dl;
@@ -454,27 +449,20 @@
 		colors = colorArray[0];
 
 		dl = &backEnd.refdef.dlights[l];
-#if idppc_altivec
 		origin0 = dl->transformed[0];
 		origin1 = dl->transformed[1];
 		origin2 = dl->transformed[2];
-#else
-		VectorCopy( dl->transformed, origin );
-#endif
 		radius = dl->radius;
 		scale = 1.0f / radius;
 
 		floatColor[0] = dl->color[0] * 255.0f;
 		floatColor[1] = dl->color[1] * 255.0f;
 		floatColor[2] = dl->color[2] * 255.0f;
-#if idppc_altivec
 		floatColorVec0 = vec_ld(0, floatColor);
 		floatColorVec1 = vec_ld(11, floatColor);
 		floatColorVec0 = vec_perm(floatColorVec0,floatColorVec0,floatColorVecPerm);
-#endif
 		for ( i = 0 ; i < tess.numVertexes ; i++, texCoords += 2, colors += 4 ) {
 			int		clip = 0;
-#if idppc_altivec
 #define DIST0 dist0
 #define DIST1 dist1
 #define DIST2 dist2
@@ -485,16 +473,6 @@
 			dist0 = origin0 - tess.xyz[i][0];
 			dist1 = origin1 - tess.xyz[i][1];
 			dist2 = origin2 - tess.xyz[i][2];
-#else
-#define DIST0 dist[0]
-#define DIST1 dist[1]
-#define DIST2 dist[2]
-#define TEXCOORDS0 texCoords[0]
-#define TEXCOORDS1 texCoords[1]
-			vec3_t	dist;
-			
-			VectorSubtract( origin, tess.xyz[i], dist );
-#endif
 
 			backEnd.pc.c_dlightVertexes++;
 
@@ -539,7 +517,6 @@
 			}
 			clipBits[i] = clip;
 
-#if idppc_altivec
 			modulateVec = vec_ld(0,(float *)&modulate);
 			modulateVec = vec_perm(modulateVec,modulateVec,modulatePerm);
 			colorVec = vec_madd(floatColorVec0,modulateVec,zero);
@@ -548,12 +525,150 @@
 			colorChar = vec_packsu(colorShort,colorShort);	// RGBxRGBxRGBxRGBx
 			colorChar = vec_sel(colorChar,vSel,vSel);		// RGBARGBARGBARGBA replace alpha with 255
 			vec_ste((vector unsigned int)colorChar,0,(unsigned int *)colors);	// store color
-#else
+		}
+#undef DIST0
+#undef DIST1
+#undef DIST2
+#undef TEXCOORDS0
+#undef TEXCOORDS1
+
+		// build a list of triangles that need light
+		numIndexes = 0;
+		for ( i = 0 ; i < tess.numIndexes ; i += 3 ) {
+			int		a, b, c;
+
+			a = tess.indexes[i];
+			b = tess.indexes[i+1];
+			c = tess.indexes[i+2];
+			if ( clipBits[a] & clipBits[b] & clipBits[c] ) {
+				continue;	// not lighted
+			}
+			hitIndexes[numIndexes] = a;
+			hitIndexes[numIndexes+1] = b;
+			hitIndexes[numIndexes+2] = c;
+			numIndexes += 3;
+		}
+
+		if ( !numIndexes ) {
+			continue;
+		}
+
+		qglEnableClientState( GL_TEXTURE_COORD_ARRAY );
+		qglTexCoordPointer( 2, GL_FLOAT, 0, texCoordsArray[0] );
+
+		qglEnableClientState( GL_COLOR_ARRAY );
+		qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArray );
+
+		GL_Bind( tr.dlightImage );
+		// include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light
+		// where they aren't rendered
+		if ( dl->additive ) {
+			GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
+		}
+		else {
+			GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
+		}
+		R_DrawElements( numIndexes, hitIndexes );
+		backEnd.pc.c_totalIndexes += numIndexes;
+		backEnd.pc.c_dlightIndexes += numIndexes;
+	}
+}
+#endif
+
+
+static void ProjectDlightTexture_scalar( void ) {
+	int		i, l;
+	vec3_t	origin;
+	float	*texCoords;
+	byte	*colors;
+	byte	clipBits[SHADER_MAX_VERTEXES];
+	float	texCoordsArray[SHADER_MAX_VERTEXES][2];
+	byte	colorArray[SHADER_MAX_VERTEXES][4];
+	unsigned	hitIndexes[SHADER_MAX_INDEXES];
+	int		numIndexes;
+	float	scale;
+	float	radius;
+	vec3_t	floatColor;
+	float	modulate = 0.0f;
+
+	if ( !backEnd.refdef.num_dlights ) {
+		return;
+	}
+
+	for ( l = 0 ; l < backEnd.refdef.num_dlights ; l++ ) {
+		dlight_t	*dl;
+
+		if ( !( tess.dlightBits & ( 1 << l ) ) ) {
+			continue;	// this surface definately doesn't have any of this light
+		}
+		texCoords = texCoordsArray[0];
+		colors = colorArray[0];
+
+		dl = &backEnd.refdef.dlights[l];
+		VectorCopy( dl->transformed, origin );
+		radius = dl->radius;
+		scale = 1.0f / radius;
+
+		floatColor[0] = dl->color[0] * 255.0f;
+		floatColor[1] = dl->color[1] * 255.0f;
+		floatColor[2] = dl->color[2] * 255.0f;
+		for ( i = 0 ; i < tess.numVertexes ; i++, texCoords += 2, colors += 4 ) {
+			int		clip = 0;
+#define DIST0 dist[0]
+#define DIST1 dist[1]
+#define DIST2 dist[2]
+#define TEXCOORDS0 texCoords[0]
+#define TEXCOORDS1 texCoords[1]
+			vec3_t	dist;
+			
+			VectorSubtract( origin, tess.xyz[i], dist );
+
+			backEnd.pc.c_dlightVertexes++;
+
+			TEXCOORDS0 = 0.5f + DIST0 * scale;
+			TEXCOORDS1 = 0.5f + DIST1 * scale;
+
+			if( !r_dlightBacks->integer &&
+					// dist . tess.normal[i]
+					( DIST0 * tess.normal[i][0] +
+					DIST1 * tess.normal[i][1] +
+					DIST2 * tess.normal[i][2] ) < 0.0f ) {
+				clip = 63;
+			} else {
+				if ( TEXCOORDS0 < 0.0f ) {
+					clip |= 1;
+				} else if ( TEXCOORDS0 > 1.0f ) {
+					clip |= 2;
+				}
+				if ( TEXCOORDS1 < 0.0f ) {
+					clip |= 4;
+				} else if ( TEXCOORDS1 > 1.0f ) {
+					clip |= 8;
+				}
+				texCoords[0] = TEXCOORDS0;
+				texCoords[1] = TEXCOORDS1;
+
+				// modulate the strength based on the height and color
+				if ( DIST2 > radius ) {
+					clip |= 16;
+					modulate = 0.0f;
+				} else if ( DIST2 < -radius ) {
+					clip |= 32;
+					modulate = 0.0f;
+				} else {
+					DIST2 = Q_fabs(DIST2);
+					if ( DIST2 < radius * 0.5f ) {
+						modulate = 1.0f;
+					} else {
+						modulate = 2.0f * (radius - DIST2) * scale;
+					}
+				}
+			}
+			clipBits[i] = clip;
 			colors[0] = myftol(floatColor[0] * modulate);
 			colors[1] = myftol(floatColor[1] * modulate);
 			colors[2] = myftol(floatColor[2] * modulate);
 			colors[3] = 255;
-#endif
 		}
 #undef DIST0
 #undef DIST1
@@ -603,7 +718,19 @@
 	}
 }
 
+static void ProjectDlightTexture( void ) {
+    #if idppc_altivec
+    extern cvar_t *com_altivec;
+    if (com_altivec->integer) {
+        // must be in a seperate function or G3 systems will crash.
+        ProjectDlightTexture_altivec();
+        return;
+    }
+    #endif
+    ProjectDlightTexture_scalar();
+}
 
+
 /*
 ===================
 RB_FogPass

Modified: trunk/code/renderer/tr_shade_calc.c
===================================================================
--- trunk/code/renderer/tr_shade_calc.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_shade_calc.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -1097,22 +1097,19 @@
 **
 ** The basic vertex lighting calc
 */
-void RB_CalcDiffuseColor( unsigned char *colors )
+#if idppc_altivec
+static void RB_CalcDiffuseColor_altivec( unsigned char *colors )
 {
-	int				i, j;
+	int				i;
 	float			*v, *normal;
-	float			incoming;
 	trRefEntity_t	*ent;
 	int				ambientLightInt;
-	vec3_t			ambientLight;
 	vec3_t			lightDir;
-	vec3_t			directedLight;
 	int				numVertexes;
-#if idppc_altivec
-	vector unsigned char vSel = (vector unsigned char){0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff,
-							   0x00, 0x00, 0x00, 0xff};
+	vector unsigned char vSel = VECCONST_UINT8(0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff,
+                                               0x00, 0x00, 0x00, 0xff);
 	vector float ambientLightVec;
 	vector float directedLightVec;
 	vector float lightDirVec;
@@ -1122,10 +1119,8 @@
 	vector signed int jVecInt;
 	vector signed short jVecShort;
 	vector unsigned char jVecChar, normalPerm;
-#endif
 	ent = backEnd.currentEntity;
 	ambientLightInt = ent->ambientLightInt;
-#if idppc_altivec
 	// A lot of this could be simplified if we made sure
 	// entities light info was 16-byte aligned.
 	jVecChar = vec_lvsl(0, ent->ambientLight);
@@ -1145,21 +1140,13 @@
 
 	zero = (vector float)vec_splat_s8(0);
 	VectorCopy( ent->lightDir, lightDir );
-#else
-	VectorCopy( ent->ambientLight, ambientLight );
-	VectorCopy( ent->directedLight, directedLight );
-	VectorCopy( ent->lightDir, lightDir );
-#endif
 
 	v = tess.xyz[0];
 	normal = tess.normal[0];
 
-#if idppc_altivec
 	normalPerm = vec_lvsl(0,normal);
-#endif
 	numVertexes = tess.numVertexes;
 	for (i = 0 ; i < numVertexes ; i++, v += 4, normal += 4) {
-#if idppc_altivec
 		normalVec0 = vec_ld(0,(vector float *)normal);
 		normalVec1 = vec_ld(11,(vector float *)normal);
 		normalVec0 = vec_perm(normalVec0,normalVec1,normalPerm);
@@ -1177,7 +1164,32 @@
 		jVecChar = vec_packsu(jVecShort,jVecShort);	// RGBxRGBxRGBxRGBx
 		jVecChar = vec_sel(jVecChar,vSel,vSel);		// RGBARGBARGBARGBA replace alpha with 255
 		vec_ste((vector unsigned int)jVecChar,0,(unsigned int *)&colors[i*4]);	// store color
-#else
+	}
+}
+#endif
+
+static void RB_CalcDiffuseColor_scalar( unsigned char *colors )
+{
+	int				i, j;
+	float			*v, *normal;
+	float			incoming;
+	trRefEntity_t	*ent;
+	int				ambientLightInt;
+	vec3_t			ambientLight;
+	vec3_t			lightDir;
+	vec3_t			directedLight;
+	int				numVertexes;
+	ent = backEnd.currentEntity;
+	ambientLightInt = ent->ambientLightInt;
+	VectorCopy( ent->ambientLight, ambientLight );
+	VectorCopy( ent->directedLight, directedLight );
+	VectorCopy( ent->lightDir, lightDir );
+
+	v = tess.xyz[0];
+	normal = tess.normal[0];
+
+	numVertexes = tess.numVertexes;
+	for (i = 0 ; i < numVertexes ; i++, v += 4, normal += 4) {
 		incoming = DotProduct (normal, lightDir);
 		if ( incoming <= 0 ) {
 			*(int *)&colors[i*4] = ambientLightInt;
@@ -1202,7 +1214,19 @@
 		colors[i*4+2] = j;
 
 		colors[i*4+3] = 255;
-#endif
 	}
 }
 
+void RB_CalcDiffuseColor( unsigned char *colors )
+{
+    #if idppc_altivec
+    extern cvar_t *com_altivec;
+    if (com_altivec->integer) {
+        // must be in a seperate function or G3 systems will crash.
+        RB_CalcDiffuseColor_altivec( colors );
+        return;
+    }
+    #endif
+    RB_CalcDiffuseColor_scalar( colors );
+}
+

Modified: trunk/code/renderer/tr_surface.c
===================================================================
--- trunk/code/renderer/tr_surface.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_surface.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -610,7 +610,8 @@
 /*
 ** LerpMeshVertexes
 */
-static void LerpMeshVertexes (md3Surface_t *surf, float backlerp) 
+#if idppc_altivec
+static void LerpMeshVertexes_altivec(md3Surface_t *surf, float backlerp)
 {
 	short	*oldXyz, *newXyz, *oldNormals, *newNormals;
 	float	*outXyz, *outNormal;
@@ -633,7 +634,6 @@
 	numVerts = surf->numVerts;
 
 	if ( backlerp == 0 ) {
-#if idppc_altivec
 		vector signed short newNormalsVec0;
 		vector signed short newNormalsVec1;
 		vector signed int newNormalsIntVec;
@@ -687,9 +687,81 @@
 			vec_ste(newNormalsFloatVec,4,outXyz);
 			vec_ste(newNormalsFloatVec,8,outXyz);
 		}
-		
-#else
+	} else {
 		//
+		// interpolate and copy the vertex and normal
+		//
+		oldXyz = (short *)((byte *)surf + surf->ofsXyzNormals)
+			+ (backEnd.currentEntity->e.oldframe * surf->numVerts * 4);
+		oldNormals = oldXyz + 3;
+
+		oldXyzScale = MD3_XYZ_SCALE * backlerp;
+		oldNormalScale = backlerp;
+
+		for (vertNum=0 ; vertNum < numVerts ; vertNum++,
+			oldXyz += 4, newXyz += 4, oldNormals += 4, newNormals += 4,
+			outXyz += 4, outNormal += 4) 
+		{
+			vec3_t uncompressedOldNormal, uncompressedNewNormal;
+
+			// interpolate the xyz
+			outXyz[0] = oldXyz[0] * oldXyzScale + newXyz[0] * newXyzScale;
+			outXyz[1] = oldXyz[1] * oldXyzScale + newXyz[1] * newXyzScale;
+			outXyz[2] = oldXyz[2] * oldXyzScale + newXyz[2] * newXyzScale;
+
+			// FIXME: interpolate lat/long instead?
+			lat = ( newNormals[0] >> 8 ) & 0xff;
+			lng = ( newNormals[0] & 0xff );
+			lat *= 4;
+			lng *= 4;
+			uncompressedNewNormal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
+			uncompressedNewNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
+			uncompressedNewNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
+
+			lat = ( oldNormals[0] >> 8 ) & 0xff;
+			lng = ( oldNormals[0] & 0xff );
+			lat *= 4;
+			lng *= 4;
+
+			uncompressedOldNormal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
+			uncompressedOldNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
+			uncompressedOldNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
+
+			outNormal[0] = uncompressedOldNormal[0] * oldNormalScale + uncompressedNewNormal[0] * newNormalScale;
+			outNormal[1] = uncompressedOldNormal[1] * oldNormalScale + uncompressedNewNormal[1] * newNormalScale;
+			outNormal[2] = uncompressedOldNormal[2] * oldNormalScale + uncompressedNewNormal[2] * newNormalScale;
+
+//			VectorNormalize (outNormal);
+		}
+    	VectorArrayNormalize((vec4_t *)tess.normal[tess.numVertexes], numVerts);
+   	}
+}
+#endif
+
+static void LerpMeshVertexes_scalar(md3Surface_t *surf, float backlerp)
+{
+	short	*oldXyz, *newXyz, *oldNormals, *newNormals;
+	float	*outXyz, *outNormal;
+	float	oldXyzScale, newXyzScale;
+	float	oldNormalScale, newNormalScale;
+	int		vertNum;
+	unsigned lat, lng;
+	int		numVerts;
+
+	outXyz = tess.xyz[tess.numVertexes];
+	outNormal = tess.normal[tess.numVertexes];
+
+	newXyz = (short *)((byte *)surf + surf->ofsXyzNormals)
+		+ (backEnd.currentEntity->e.frame * surf->numVerts * 4);
+	newNormals = newXyz + 3;
+
+	newXyzScale = MD3_XYZ_SCALE * (1.0 - backlerp);
+	newNormalScale = 1.0 - backlerp;
+
+	numVerts = surf->numVerts;
+
+	if ( backlerp == 0 ) {
+		//
 		// just copy the vertexes
 		//
 		for (vertNum=0 ; vertNum < numVerts ; vertNum++,
@@ -714,7 +786,6 @@
 			outNormal[1] = tr.sinTable[lat] * tr.sinTable[lng];
 			outNormal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
 		}
-#endif
 	} else {
 		//
 		// interpolate and copy the vertex and normal
@@ -765,6 +836,33 @@
    	}
 }
 
+static void LerpMeshVertexes(md3Surface_t *surf, float backlerp)
+{
+    #if idppc_altivec
+
+    // !!! FIXME: figure out what's broken and remove this.
+    #ifndef NDEBUG
+    static int already_complained = 0;
+    if (!already_complained)
+    {
+        already_complained = 1;
+        Com_Printf("WARNING! FIXME! Altivec mesh lerping broken in debug builds!\n");
+    }
+    #else
+    extern cvar_t *com_altivec;
+    if (com_altivec->integer) {
+        // must be in a seperate function or G3 systems will crash.
+        LerpMeshVertexes_altivec( surf, backlerp );
+        return;
+    }
+    #endif
+
+    #endif // idppc_altivec
+
+    LerpMeshVertexes_scalar( surf, backlerp );
+}
+
+
 /*
 =============
 RB_SurfaceMesh

Modified: trunk/code/renderer/tr_types.h
===================================================================
--- trunk/code/renderer/tr_types.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/renderer/tr_types.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -218,6 +218,11 @@
 #define _3DFX_DRIVER_NAME	"3dfxvgl"
 #define OPENGL_DRIVER_NAME	"opengl32"
 
+#elif defined(MACOS_X)
+
+#define _3DFX_DRIVER_NAME	"libMesaVoodooGL.dylib"
+#define OPENGL_DRIVER_NAME	"/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
+
 #else
 
 #define _3DFX_DRIVER_NAME	"libMesaVoodooGL.so"

Modified: trunk/code/tools/asm/Makefile
===================================================================
--- trunk/code/tools/asm/Makefile	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/tools/asm/Makefile	2005-11-26 07:46:21 UTC (rev 373)
@@ -16,6 +16,19 @@
 CC=gcc
 Q3ASM_CFLAGS=-O2 -Wall -Werror -fno-strict-aliasing
 
+ifeq ($(PLATFORM),darwin)
+  LCC_CFLAGS += -DMACOS_X=1
+endif
+
+ifndef USE_CCACHE
+  USE_CCACHE=0
+endif
+
+ifeq ($(USE_CCACHE),1)
+  CC := ccache $(CC)
+  CXX := ccache $(CXX)
+endif
+
 default:	q3asm
 
 q3asm:	q3asm.c cmdlib.c

Modified: trunk/code/tools/lcc/Makefile
===================================================================
--- trunk/code/tools/lcc/Makefile	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/tools/lcc/Makefile	2005-11-26 07:46:21 UTC (rev 373)
@@ -22,6 +22,19 @@
 BUILDDIR=build
 BD=$(BUILDDIR)/
 
+ifeq ($(PLATFORM),darwin)
+  LCC_CFLAGS += -DMACOS_X=1
+endif
+
+ifndef USE_CCACHE
+  USE_CCACHE=0
+endif
+
+ifeq ($(USE_CCACHE),1)
+  CC := ccache $(CC)
+  CXX := ccache $(CXX)
+endif
+
 ifeq ($(PLATFORM),SunOS)
   INSTALL=ginstall
 else

Modified: trunk/code/unix/Makefile
===================================================================
--- trunk/code/unix/Makefile	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/Makefile	2005-11-26 07:46:21 UTC (rev 373)
@@ -13,8 +13,18 @@
 
 PLATFORM=$(shell uname|sed -e s/_.*//|tr A-Z a-z)
 PLATFORM_RELEASE=$(shell uname -r)
-ARCH:=$(shell uname -m | sed -e s/i.86/i386/)
 
+# Apple does some things a little differently...
+ifeq ($(PLATFORM),darwin)
+  ARCH:= $(shell uname -p | sed -e s/i.86/i386/)
+else
+  ARCH:=$(shell uname -m | sed -e s/i.86/i386/)
+endif
+
+ifeq ($(ARCH),powerpc)
+  ARCH:=ppc
+endif
+
 #############################################################################
 #
 # If you require a different configuration from the defaults below, create a
@@ -43,6 +53,11 @@
 DXSDK_DIR=C:/DXSDK
 endif
 
+ifndef USE_CCACHE
+USE_CCACHE=1
+endif
+export USE_CCACHE
+
 ifndef USE_SDL
 USE_SDL=1
 endif
@@ -121,8 +136,11 @@
   endif
   endif
 
-  BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes
+  BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes -pipe
 
+  # Always include debug symbols...you can strip the binary later...
+  BASE_CFLAGS += -gfull
+
   ifeq ($(USE_OPENAL),1)
     BASE_CFLAGS += -DUSE_OPENAL=1
     ifeq ($(USE_OPENAL_DLOPEN),1)
@@ -153,6 +171,7 @@
     HAVE_VM_COMPILED=true
   else
   ifeq ($(ARCH),ppc)
+    BASE_CFLAGS += -maltivec
     ifneq ($(VM_PPC),)
       HAVE_VM_COMPILED=true
     endif
@@ -181,8 +200,10 @@
     CLIENT_LDFLAGS=-L/usr/X11R6/$(LIB) -lX11 -lXext -lXxf86dga -lXxf86vm
   endif
 
-  ifneq ($(USE_OPENAL_DLOPEN),1)
-    CLIENT_LDFLAGS += -lopenal
+  ifeq ($(USE_OPENAL),1)
+    ifneq ($(USE_OPENAL_DLOPEN),1)
+      CLIENT_LDFLAGS += -lopenal
+    endif
   endif
 
   ifeq ($(ARCH),i386)
@@ -217,6 +238,106 @@
 else # ifeq Linux
 
 #############################################################################
+# SETUP AND BUILD -- MAC OS X
+#############################################################################
+
+ifeq ($(PLATFORM),darwin)
+  GLIBC=
+  CC=gcc
+  CXX=g++
+
+  VM_PPC=vm_ppc_new
+
+  BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes
+  BASE_CFLAGS += -DMACOS_X=1 -fno-common -pipe
+
+  # Always include debug symbols...you can strip the binary later...
+  BASE_CFLAGS += -gfull
+
+  ifeq ($(USE_OPENAL),1)
+    BASE_CFLAGS += -DUSE_OPENAL=1
+    ifeq ($(USE_OPENAL_DLOPEN),1)
+      BASE_CFLAGS += -DUSE_OPENAL_DLOPEN=1
+    endif
+  endif
+
+  ifeq ($(USE_SDL),1)
+    BASE_CFLAGS += -DUSE_SDL_VIDEO=1 -DUSE_SDL_SOUND=1 -D_THREAD_SAFE=1 -I../SDL12/include
+    GL_CFLAGS =
+  endif
+
+  OPTIMIZE = -O3 -ffast-math -fomit-frame-pointer -falign-loops=16
+
+  ifeq ($(ARCH),ppc)
+	BASE_CFLAGS += -faltivec
+    ifneq ($(VM_PPC),)
+      HAVE_VM_COMPILED=true
+    endif
+  endif
+
+  ifeq ($(ARCH),i386)
+    # !!! FIXME: x86-specific flags here...
+  endif
+
+  ifneq ($(HAVE_VM_COMPILED),true)
+    BASE_CFLAGS += -DNO_VM_COMPILED
+  endif
+
+  DEBUG_CFLAGS = $(BASE_CFLAGS) -g -O0
+
+  RELEASE_CFLAGS=$(BASE_CFLAGS) -DNDEBUG $(OPTIMIZE)
+
+  SHLIBEXT=dylib
+  SHLIBCFLAGS=-fPIC -fno-common
+  SHLIBLDFLAGS=-dynamiclib $(LDFLAGS)
+
+  NOTSHLIBCFLAGS=-mdynamic-no-pic
+
+  #THREAD_LDFLAGS=-lpthread
+  #LDFLAGS=-ldl -lm
+  LDFLAGS += -framework Carbon
+
+  ifeq ($(USE_SDL),1)
+    # We copy sdlmain before ranlib'ing it so that subversion doesn't think
+    #  the file has been modified by each build.
+	LIBSDLMAIN=$(B)/libSDLmain.a
+    LIBSDLMAINSRC=../libs/macosx/libSDLmain.a
+    CLIENT_LDFLAGS=-framework Cocoa -framework OpenGL ../libs/macosx/libSDL-1.2.0.dylib
+  else
+    # !!! FIXME: frameworks: OpenGL, Carbon, etc...
+    #CLIENT_LDFLAGS=-L/usr/X11R6/$(LIB) -lX11 -lXext -lXxf86dga -lXxf86vm
+  endif
+
+  # -framework OpenAL requires 10.4 or later...for builds shipping to the
+  #  public, you'll want to use USE_OPENAL_DLOPEN and ship your own OpenAL
+  #  library (http://openal.org/ or http://icculus.org/al_osx/)
+  ifeq ($(USE_OPENAL),1)
+    ifneq ($(USE_OPENAL_DLOPEN),1)
+      CLIENT_LDFLAGS += -framework OpenAL
+    endif
+  endif
+
+  TARGETS=\
+      $(B)/$(PLATFORM)quake3 \
+      $(B)/$(PLATFORM)q3ded \
+      $(B)/baseq3/cgame$(ARCH).$(SHLIBEXT) \
+      $(B)/baseq3/qagame$(ARCH).$(SHLIBEXT) \
+      $(B)/baseq3/ui$(ARCH).$(SHLIBEXT)     \
+      $(B)/missionpack/cgame$(ARCH).$(SHLIBEXT) \
+      $(B)/missionpack/qagame$(ARCH).$(SHLIBEXT) \
+      $(B)/missionpack/ui$(ARCH).$(SHLIBEXT) \
+      $(B)/baseq3/vm/cgame.qvm \
+      $(B)/baseq3/vm/qagame.qvm \
+      $(B)/baseq3/vm/ui.qvm \
+      $(B)/missionpack/vm/qagame.qvm \
+      $(B)/missionpack/vm/cgame.qvm \
+      $(B)/missionpack/vm/ui.qvm
+#      $(B)/$(PLATFORM)quake3-smp \
+
+else # ifeq darwin
+
+
+#############################################################################
 # SETUP AND BUILD -- MINGW32
 #############################################################################
 
@@ -494,7 +615,6 @@
 #############################################################################
 # SETUP AND BUILD -- GENERIC
 #############################################################################
-
   CC=cc
   BASE_CFLAGS=-DNO_VM_COMPILED
   DEBUG_CFLAGS=$(BASE_CFLAGS) -g
@@ -508,11 +628,17 @@
     $(B)/$(PLATFORM)q3ded
 
 endif #Linux
+endif #darwin
 endif #mingw32
 endif #FreeBSD
 endif #IRIX
 endif #SunOS
 
+ifeq ($(USE_CCACHE),1)
+  CC := ccache $(CC)
+  CXX := ccache $(CXX)
+endif
+
 ifneq ($(BUILD_SERVER),1)
   TARGETS := $(subst $(B)/$(PLATFORM)q3ded,,$(TARGETS))
 endif
@@ -541,15 +667,15 @@
   endif
 endif
 
-DO_CC=$(CC) $(CFLAGS) -o $@ -c $<
-DO_CXX=$(CXX) $(CFLAGS) -o $@ -c $<
-DO_SMP_CC=$(CC) $(CFLAGS) -DSMP -o $@ -c $<
-DO_BOT_CC=$(CC) $(CFLAGS) -DBOTLIB -o $@ -c $<   # $(SHLIBCFLAGS) # bk001212
-DO_DEBUG_CC=$(CC) $(DEBUG_CFLAGS) -o $@ -c $<
+DO_CC=$(CC) $(NOTSHLIBCFLAGS) $(CFLAGS) -o $@ -c $<
+DO_CXX=$(CXX) $(NOTSHLIBCFLAGS) $(CFLAGS) -o $@ -c $<
+DO_SMP_CC=$(CC) $(NOTSHLIBCFLAGS) $(CFLAGS) -DSMP -o $@ -c $<
+DO_BOT_CC=$(CC) $(NOTSHLIBCFLAGS) $(CFLAGS) -DBOTLIB -o $@ -c $<   # $(SHLIBCFLAGS) # bk001212
+DO_DEBUG_CC=$(CC) $(NOTSHLIBCFLAGS) $(DEBUG_CFLAGS) -o $@ -c $<
 DO_SHLIB_CC=$(CC) $(CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
 DO_SHLIB_DEBUG_CC=$(CC) $(DEBUG_CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
 DO_AS=$(CC) $(CFLAGS) -DELF -x assembler-with-cpp -o $@ -c $<
-DO_DED_CC=$(CC) -DDEDICATED $(CFLAGS) -o $@ -c $<
+DO_DED_CC=$(CC) $(NOTSHLIBCFLAGS) -DDEDICATED $(CFLAGS) -o $@ -c $<
 DO_WINDRES=$(WINDRES) -i $< -o $@
 
 #############################################################################
@@ -864,7 +990,34 @@
     Q3POBJ_SMP += $(B)/client/ftola.o $(B)/client/snapvectora.o
   endif
 endif #Linux-axp
+
 else
+ifeq ($(PLATFORM),darwin)
+  Q3POBJ=\
+    $(B)/client/unix_main.o \
+    $(B)/client/unix_net.o \
+    $(B)/client/unix_shared.o \
+    $(B)/client/linux_signals.o \
+    $(B)/client/linux_common.o \
+    $(B)/client/linux_qgl.o \
+    $(B)/client/linux_glimp.o \
+    $(B)/client/sdl_glimp.o \
+    $(B)/client/linux_joystick.o \
+    $(B)/client/linux_snd.o \
+    $(B)/client/sdl_snd.o \
+
+  ifeq ($(ARCH),i386)
+	I386OBJS := \
+		$(B)/client/ftola.o \
+		$(B)/client/snapvectora.o \
+		$(B)/client/snd_mixa.o \
+        $(B)/client/matha.o \
+
+    Q3POBJ += $(I386OBJS)
+    Q3POBJ_SMP += $(I386OBJS)
+  endif
+
+else
 ifeq ($(PLATFORM),SunOS)
   Q3POBJ=\
     $(B)/client/unix_main.o \
@@ -895,17 +1048,26 @@
 
 endif #SunOS
 endif #Linux
+endif #darwin
 endif #mingw32
 endif #IRIX
 endif #FreeBSD
 
-$(B)/$(PLATFORM)quake3$(BINEXT): $(Q3OBJ) $(Q3POBJ)
-	$(CC)  -o $@ $(Q3OBJ) $(Q3POBJ) $(CLIENT_LDFLAGS) $(LDFLAGS)
+$(B)/$(PLATFORM)quake3$(BINEXT): $(Q3OBJ) $(Q3POBJ) $(LIBSDLMAIN)
+	$(CC)  -o $@ $(Q3OBJ) $(Q3POBJ) $(CLIENT_LDFLAGS) $(LDFLAGS) $(LIBSDLMAIN)
 
-$(B)/$(PLATFORM)quake3-smp$(BINEXT): $(Q3OBJ) $(Q3POBJ_SMP)
+$(B)/$(PLATFORM)quake3-smp$(BINEXT): $(Q3OBJ) $(Q3POBJ_SMP) $(LIBSDLMAIN)
 	$(CC)  -o $@ $(Q3OBJ) $(Q3POBJ_SMP) $(CLIENT_LDFLAGS) \
-		$(THREAD_LDFLAGS) $(LDFLAGS)
+		$(THREAD_LDFLAGS) $(LDFLAGS) $(LIBSDLMAIN)
 
+ifneq ($(strip $(LIBSDLMAIN)),)
+ifneq ($(strip $(LIBSDLMAINSRC)),)
+$(LIBSDLMAIN) : $(LIBSDLMAINSRC)
+	cp $< $@
+	ranlib $@
+endif
+endif
+
 $(B)/client/cl_cgame.o : $(CDIR)/cl_cgame.c; $(DO_CC)
 $(B)/client/cl_cin.o : $(CDIR)/cl_cin.c; $(DO_CC)
 $(B)/client/cl_console.o : $(CDIR)/cl_console.c; $(DO_CC)

Modified: trunk/code/unix/linux_glimp.c
===================================================================
--- trunk/code/unix/linux_glimp.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/linux_glimp.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -1265,7 +1265,9 @@
 
       if ( qglActiveTextureARB )
       {
-        qglGetIntegerv( GL_MAX_ACTIVE_TEXTURES_ARB, &glConfig.maxActiveTextures );
+        GLint glint = 0;
+        qglGetIntegerv( GL_MAX_ACTIVE_TEXTURES_ARB, &glint );
+        glConfig.maxActiveTextures = (int) glint;
 
         if ( glConfig.maxActiveTextures > 1 )
         {

Modified: trunk/code/unix/linux_qgl.c
===================================================================
--- trunk/code/unix/linux_qgl.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/linux_qgl.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -45,9 +45,13 @@
 //#endif
 //#include <GL/glx.h> // bk010216 - FIXME: all of the above redundant? renderer/qgl.h
 
+#if defined(USE_SDL_VIDEO)
+#include "SDL.h"
+#include "SDL_loadso.h"
+#else
 #include <dlfcn.h>
+#endif
 
-
 // bk001129 - from cvs1.17 (mkv)
 #if defined(__FX__)
 //FX Mesa Functions
@@ -60,12 +64,14 @@
 #endif
 
 //GLX Functions
+#if !defined(USE_SDL_VIDEO)
 XVisualInfo * (*qglXChooseVisual)( Display *dpy, int screen, int *attribList );
 GLXContext (*qglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
 void (*qglXDestroyContext)( Display *dpy, GLXContext ctx );
 Bool (*qglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
 void (*qglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, GLuint mask );
 void (*qglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
+#endif
 
 void ( APIENTRY * qglAccum )(GLenum op, GLfloat value);
 void ( APIENTRY * qglAlphaFunc )(GLenum func, GLclampf ref);
@@ -408,7 +414,7 @@
 void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
 void ( APIENTRY * qglClientActiveTextureARB )( GLenum texture );
 
-void ( APIENTRY * qglLockArraysEXT)( int, int);
+void ( APIENTRY * qglLockArraysEXT)( GLint, GLint);
 void ( APIENTRY * qglUnlockArraysEXT) ( void );
 
 void ( APIENTRY * qglPointParameterfEXT)( GLenum param, GLfloat value );
@@ -763,7 +769,7 @@
 
 static void APIENTRY logAlphaFunc(GLenum func, GLclampf ref)
 {
-	fprintf( glw_state.log_fp, "glAlphaFunc( 0x%x, %f )\n", func, ref );
+	fprintf( glw_state.log_fp, "glAlphaFunc( 0x%x, %f )\n", (unsigned int) func, ref );
 	dllAlphaFunc( func, ref );
 }
 
@@ -781,13 +787,13 @@
 
 static void APIENTRY logBegin(GLenum mode)
 {
-	fprintf( glw_state.log_fp, "glBegin( 0x%x )\n", mode );
+	fprintf( glw_state.log_fp, "glBegin( 0x%x )\n", (unsigned int) mode );
 	dllBegin( mode );
 }
 
 static void APIENTRY logBindTexture(GLenum target, GLuint texture)
 {
-	fprintf( glw_state.log_fp, "glBindTexture( 0x%x, %u )\n", target, texture );
+	fprintf( glw_state.log_fp, "glBindTexture( 0x%x, %u )\n", (unsigned int) target, (unsigned int) texture );
 	dllBindTexture( target, texture );
 }
 
@@ -799,13 +805,13 @@
 
 static void APIENTRY logBlendFunc(GLenum sfactor, GLenum dfactor)
 {
-	fprintf( glw_state.log_fp, "glBlendFunc( 0x%x, 0x%x )\n", sfactor, dfactor );
+	fprintf( glw_state.log_fp, "glBlendFunc( 0x%x, 0x%x )\n", (unsigned int) sfactor, (unsigned int) dfactor );
 	dllBlendFunc( sfactor, dfactor );
 }
 
 static void APIENTRY logCallList(GLuint list)
 {
-	fprintf( glw_state.log_fp, "glCallList( %u )\n", list );
+	fprintf( glw_state.log_fp, "glCallList( %u )\n", (unsigned int) list );
 	dllCallList( list );
 }
 
@@ -1122,7 +1128,7 @@
 
 static void APIENTRY logDisable(GLenum cap)
 {
-	fprintf( glw_state.log_fp, "glDisable( 0x%x )\n", cap );
+	fprintf( glw_state.log_fp, "glDisable( 0x%x )\n", (unsigned int) cap );
 	dllDisable( cap );
 }
 
@@ -1176,7 +1182,7 @@
 
 static void APIENTRY logEnable(GLenum cap)
 {
-	fprintf( glw_state.log_fp, "glEnable( 0x%x )\n", cap );
+	fprintf( glw_state.log_fp, "glEnable( 0x%x )\n", (unsigned int) cap );
 	dllEnable( cap );
 }
 
@@ -1504,7 +1510,7 @@
 
 static void APIENTRY logHint(GLenum target, GLenum mode)
 {
-	fprintf( glw_state.log_fp, "glHint( 0x%x, 0x%x )\n", target, mode );
+	fprintf( glw_state.log_fp, "glHint( 0x%x, 0x%x )\n", (unsigned int) target, (unsigned int) mode );
 	dllHint( target, mode );
 }
 
@@ -1923,7 +1929,7 @@
 
 static void APIENTRY logPolygonMode(GLenum face, GLenum mode)
 {
-	fprintf( glw_state.log_fp, "glPolygonMode( 0x%x, 0x%x )\n", face, mode );
+	fprintf( glw_state.log_fp, "glPolygonMode( 0x%x, 0x%x )\n", (unsigned int) face, (unsigned int) mode );
 	dllPolygonMode( face, mode );
 }
 
@@ -2403,7 +2409,7 @@
 
 static void APIENTRY logTexEnvf(GLenum target, GLenum pname, GLfloat param)
 {
-	fprintf( glw_state.log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", target, pname, param );
+	fprintf( glw_state.log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", (unsigned int) target, (unsigned int) pname, param );
 	dllTexEnvf( target, pname, param );
 }
 
@@ -2415,7 +2421,7 @@
 
 static void APIENTRY logTexEnvi(GLenum target, GLenum pname, GLint param)
 {
-	fprintf( glw_state.log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", target, pname, param );
+	fprintf( glw_state.log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", (unsigned int) target, (unsigned int) pname, (unsigned int) param );
 	dllTexEnvi( target, pname, param );
 }
 static void APIENTRY logTexEnviv(GLenum target, GLenum pname, const GLint *params)
@@ -2469,7 +2475,7 @@
 
 static void APIENTRY logTexParameterf(GLenum target, GLenum pname, GLfloat param)
 {
-	fprintf( glw_state.log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", target, pname, param );
+	fprintf( glw_state.log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", (unsigned int) target, (unsigned int) pname, param );
 	dllTexParameterf( target, pname, param );
 }
 
@@ -2480,7 +2486,7 @@
 }
 static void APIENTRY logTexParameteri(GLenum target, GLenum pname, GLint param)
 {
-	fprintf( glw_state.log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", target, pname, param );
+	fprintf( glw_state.log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", (unsigned int) target, (unsigned int) pname, (unsigned int) param );
 	dllTexParameteri( target, pname, param );
 }
 static void APIENTRY logTexParameteriv(GLenum target, GLenum pname, const GLint *params)
@@ -2669,12 +2675,14 @@
 		if( r_GLlibCoolDownMsec->integer )
 			usleep( r_GLlibCoolDownMsec->integer * 1000 );
 
+		#if USE_SDL_VIDEO
+		SDL_QuitSubSystem(SDL_INIT_VIDEO);
+		#else
 		dlclose ( glw_state.OpenGLLib );
+		#endif
 		glw_state.OpenGLLib = NULL;
 	}
 
-	glw_state.OpenGLLib = NULL;
-
 	qglAccum                     = NULL;
 	qglAlphaFunc                 = NULL;
 	qglAreTexturesResident       = NULL;
@@ -3022,15 +3030,22 @@
 	qfxMesaSwapBuffers           = NULL;
 #endif
 
+#if !defined(USE_SDL_VIDEO)
 	qglXChooseVisual             = NULL;
 	qglXCreateContext            = NULL;
 	qglXDestroyContext           = NULL;
 	qglXMakeCurrent              = NULL;
 	qglXCopyContext              = NULL;
 	qglXSwapBuffers              = NULL;
+#endif
 }
 
+#if USE_SDL_VIDEO
+#define GPA( a ) SDL_GL_GetProcAddress( a )
+qboolean GLimp_sdl_init_video(void);
+#else
 #define GPA( a ) dlsym( glw_state.OpenGLLib, a )
+#endif
 
 void *qwglGetProcAddress(char *symbol)
 {
@@ -3039,6 +3054,8 @@
 	return NULL;
 }
 
+char *do_dlerror(void);
+
 /*
 ** QGL_Init
 **
@@ -3052,23 +3069,39 @@
 
 qboolean QGL_Init( const char *dllname )
 {
-	if ( ( glw_state.OpenGLLib = dlopen( dllname, RTLD_LAZY|RTLD_GLOBAL ) ) == 0 )
+	if (glw_state.OpenGLLib == 0)
 	{
+		#if USE_SDL_VIDEO
+		if (GLimp_sdl_init_video() == qfalse)
+			return qfalse;
+		glw_state.OpenGLLib = (void*) ((SDL_GL_LoadLibrary(dllname) == -1) ? 0 : 1);
+		#else
+		glw_state.OpenGLLib = dlopen( dllname, RTLD_LAZY|RTLD_GLOBAL );
+		#endif
+	}
+
+	if (glw_state.OpenGLLib == 0)
+	{
 		char	fn[1024];
 		// FILE *fp; // bk001204 - unused
 
 		// if we are not setuid, try current directory
-		if (1) {
+		if (dllname != NULL) {
 			getcwd(fn, sizeof(fn));
 			Q_strcat(fn, sizeof(fn), "/");
 			Q_strcat(fn, sizeof(fn), dllname);
 
-			if ( ( glw_state.OpenGLLib = dlopen( fn, RTLD_LAZY ) ) == 0 ) {
-				ri.Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf or current dir: %s\n", dllname, dlerror());
+			#if USE_SDL_VIDEO
+			glw_state.OpenGLLib = (void*) ((SDL_GL_LoadLibrary(fn) == -1) ? 0 : 1);
+			#else
+			glw_state.OpenGLLib = dlopen( fn, RTLD_LAZY );
+			#endif
+			if ( glw_state.OpenGLLib == 0 ) {
+				ri.Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf or current dir: %s\n", dllname, do_dlerror());
 				return qfalse;
 			}
 		} else {
-			ri.Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf: %s\n", dllname, dlerror());
+			ri.Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf: %s\n", dllname, do_dlerror());
 			return qfalse;
 		}
 	}
@@ -3418,12 +3451,14 @@
 	qfxMesaSwapBuffers           =  GPA("fxMesaSwapBuffers");
 #endif
 
+#if !defined(USE_SDL_VIDEO)
 	qglXChooseVisual             =  GPA("glXChooseVisual");
 	qglXCreateContext            =  GPA("glXCreateContext");
 	qglXDestroyContext           =  GPA("glXDestroyContext");
 	qglXMakeCurrent              =  GPA("glXMakeCurrent");
 	qglXCopyContext              =  GPA("glXCopyContext");
 	qglXSwapBuffers              =  GPA("glXSwapBuffers");
+#endif
 
 	qglLockArraysEXT = NULL;
 	qglUnlockArraysEXT = NULL;

Modified: trunk/code/unix/sdl_glimp.c
===================================================================
--- trunk/code/unix/sdl_glimp.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/sdl_glimp.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -6,7 +6,7 @@
  *
  * I wrote such a beast originally for Loki's port of Heavy Metal: FAKK2,
  *  and then wrote it again for the Linux client of Medal of Honor: Allied
- *  Assault. Third times a charm, so I'm rewriting this once more for the
+ *  Assault. Third time's a charm, so I'm rewriting this once more for the
  *  GPL release of Quake 3.
  *
  * Written by Ryan C. Gordon (icculus at icculus.org). Please refer to
@@ -107,6 +107,23 @@
 cvar_t  *r_allowSoftwareGL;   // don't abort out if the pixelformat claims software
 cvar_t  *r_previousglDriver;
 
+qboolean GLimp_sdl_init_video(void)
+{
+  if (!SDL_WasInit(SDL_INIT_VIDEO))
+  {
+    ri.Printf( PRINT_ALL, "Calling SDL_Init(SDL_INIT_VIDEO)...\n");
+    if (SDL_Init(SDL_INIT_VIDEO) == -1)
+    {
+		ri.Printf( PRINT_ALL, "SDL_Init(SDL_INIT_VIDEO) failed: %s\n", SDL_GetError());
+        return qfalse;
+    }
+    ri.Printf( PRINT_ALL, "SDL_Init(SDL_INIT_VIDEO) passed.\n");
+  }
+
+  return qtrue;
+}
+
+
 /*
 * Find the first occurrence of find in s.
 */
@@ -217,8 +234,12 @@
   default: break;
   } 
 
-  if (keysym->unicode <= 255 && keysym->unicode >= 20)  // maps to ASCII?
+  if (*key == K_BACKSPACE)
+    buf[0] = 8;
+  else
   {
+    if (keysym->unicode <= 255 && keysym->unicode >= 20)  // maps to ASCII?
+    {
       char ch = (char) keysym->unicode;
       if (ch == '~')
         *key = '~'; // console HACK
@@ -231,17 +252,25 @@
       //  ch = ch - 'A' + 'a';
 
       buf[0] = ch;
+    }
+    else if(keysym->unicode == 8) // ctrl-h
+      buf[0] = 8;
   }
-  else if(keysym->unicode == 8) // ctrl-h
-      buf[0] = 8;
 
   return buf;
 }
 
 static void install_grabs(void)
 {
+    SDL_WM_GrabInput(SDL_GRAB_ON);
     SDL_ShowCursor(0);
-    SDL_WM_GrabInput(SDL_GRAB_ON);
+
+    // This is a bug in the current SDL/macosx...have to toggle it a few
+    //  times to get the cursor to hide.
+    #if defined(MACOS_X)
+    SDL_ShowCursor(1);
+    SDL_ShowCursor(0);
+    #endif
 }
 
 static void uninstall_grabs(void)
@@ -417,7 +446,6 @@
 void GLimp_Shutdown( void )
 {
   IN_Shutdown();
-  SDL_QuitSubSystem(SDL_INIT_VIDEO);
   screen = NULL;
 
   memset( &glConfig, 0, sizeof( glConfig ) );
@@ -448,16 +476,8 @@
 {
   rserr_t err;
 
-  if (!SDL_WasInit(SDL_INIT_VIDEO))
-  {
-    ri.Printf( PRINT_ALL, "Calling SDL_Init(SDL_INIT_VIDEO)...\n");
-    if (SDL_Init(SDL_INIT_VIDEO) == -1)
-    {
-		ri.Printf( PRINT_ALL, "SDL_Init(SDL_INIT_VIDEO) failed: %s\n", SDL_GetError());
-        return qfalse;
-    }
-    ri.Printf( PRINT_ALL, "SDL_Init(SDL_INIT_VIDEO) passed.\n");
-  }
+  if (GLimp_sdl_init_video() == qfalse)
+    return qfalse;
 
   // don't ever bother going into fullscreen with a voodoo card
 #if 1	// JDC: I reenabled this
@@ -714,17 +734,17 @@
   qglClientActiveTextureARB = NULL;
   if ( Q_stristr( glConfig.extensions_string, "GL_ARB_multitexture" ) )
   {
-    // !!! FIXME: Use SDL_GL_GetProcAddress instead?
     if ( r_ext_multitexture->value )
     {
-      qglMultiTexCoord2fARB = ( PFNGLMULTITEXCOORD2FARBPROC ) dlsym( glw_state.OpenGLLib, "glMultiTexCoord2fARB" );
-      qglActiveTextureARB = ( PFNGLACTIVETEXTUREARBPROC ) dlsym( glw_state.OpenGLLib, "glActiveTextureARB" );
-      qglClientActiveTextureARB = ( PFNGLCLIENTACTIVETEXTUREARBPROC ) dlsym( glw_state.OpenGLLib, "glClientActiveTextureARB" );
+      qglMultiTexCoord2fARB = ( PFNGLMULTITEXCOORD2FARBPROC ) SDL_GL_GetProcAddress( "glMultiTexCoord2fARB" );
+      qglActiveTextureARB = ( PFNGLACTIVETEXTUREARBPROC ) SDL_GL_GetProcAddress( "glActiveTextureARB" );
+      qglClientActiveTextureARB = ( PFNGLCLIENTACTIVETEXTUREARBPROC ) SDL_GL_GetProcAddress( "glClientActiveTextureARB" );
 
       if ( qglActiveTextureARB )
       {
-        qglGetIntegerv( GL_MAX_ACTIVE_TEXTURES_ARB, &glConfig.maxActiveTextures );
-
+        GLint glint = 0;
+        qglGetIntegerv( GL_MAX_ACTIVE_TEXTURES_ARB, &glint );
+        glConfig.maxActiveTextures = (int) glint;
         if ( glConfig.maxActiveTextures > 1 )
         {
           ri.Printf( PRINT_ALL, "...using GL_ARB_multitexture\n" );
@@ -751,8 +771,8 @@
     if ( r_ext_compiled_vertex_array->value )
     {
       ri.Printf( PRINT_ALL, "...using GL_EXT_compiled_vertex_array\n" );
-      qglLockArraysEXT = ( void ( APIENTRY * )( int, int ) ) dlsym( glw_state.OpenGLLib, "glLockArraysEXT" );
-      qglUnlockArraysEXT = ( void ( APIENTRY * )( void ) ) dlsym( glw_state.OpenGLLib, "glUnlockArraysEXT" );
+      qglLockArraysEXT = ( void ( APIENTRY * )( GLint, GLint ) ) SDL_GL_GetProcAddress( "glLockArraysEXT" );
+      qglUnlockArraysEXT = ( void ( APIENTRY * )( void ) ) SDL_GL_GetProcAddress( "glUnlockArraysEXT" );
       if (!qglLockArraysEXT || !qglUnlockArraysEXT)
       {
         ri.Error (ERR_FATAL, "bad getprocaddress");
@@ -783,7 +803,7 @@
 {
   qboolean fullscreen;
 
-  ri.Printf( PRINT_ALL, "...loading %s: ", name );
+  ri.Printf( PRINT_ALL, "...loading %s:\n", name );
 
   // disable the 3Dfx splash screen and set gamma
   // we do this all the time, but it shouldn't hurt anything

Modified: trunk/code/unix/sdl_snd.c
===================================================================
--- trunk/code/unix/sdl_snd.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/sdl_snd.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -81,6 +81,10 @@
 <TTimo> and use my own copy instead of the glibc crap
 ===============
 */
+
+#ifdef Snd_Memset
+#undef Snd_Memset
+#endif
 void Snd_Memset (void* dest, const int val, const size_t count)
 {
 	int *pDest;

Modified: trunk/code/unix/unix_glw.h
===================================================================
--- trunk/code/unix/unix_glw.h	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/unix_glw.h	2005-11-26 07:46:21 UTC (rev 373)
@@ -19,7 +19,7 @@
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 ===========================================================================
 */
-#if !( defined __linux__ || defined __FreeBSD__ || defined __sun)
+#if !( defined __linux__ || defined __FreeBSD__ || defined __sun || defined MACOS_X )
 #error You should include this file only on Linux/FreeBSD/Solaris platforms
 #endif
 

Modified: trunk/code/unix/unix_main.c
===================================================================
--- trunk/code/unix/unix_main.c	2005-11-20 15:35:45 UTC (rev 372)
+++ trunk/code/unix/unix_main.c	2005-11-26 07:46:21 UTC (rev 373)
@@ -41,7 +41,17 @@
 #ifdef __linux__ // rb010123
   #include <mntent.h>
 #endif
+
+#if (defined(DEDICATED) && defined(USE_SDL_VIDEO))
+#undef USE_SDL_VIDEO
+#endif
+
+#if USE_SDL_VIDEO
+#include "SDL.h"
+#include "SDL_loadso.h"
+#else
 #include <dlfcn.h>
+#endif
 
 #ifdef __linux__
   #include <fpu_control.h> // bk001213 - force dumps on divide by zero
@@ -60,8 +70,11 @@
 
 #include "linux_local.h" // bk001204
 
-// Structure containing functions exported from refresh DLL
-refexport_t re;
+#if idppc_altivec
+  #ifdef MACOS_X
+    #include <Carbon/Carbon.h>
+  #endif
+#endif
 
 unsigned  sys_frame_time;
 
@@ -349,8 +362,33 @@
   Sys_Exit(0);
 }
 
+static void Sys_DetectAltivec(void)
+{
+  extern cvar_t	*com_altivec;
+
+  // Only detect if user hasn't forcibly disabled it.
+  if (com_altivec->integer) {
+    #if idppc_altivec
+      #if MACOS_X
+      {
+        long feat = 0;
+        OSErr err = Gestalt(gestaltPowerPCProcessorFeatures, &feat);
+        if ((err==noErr) && ((1 << gestaltPowerPCHasVectorInstructions) & feat))
+          com_altivec->integer = 1;
+      }
+      #else // !!! FIXME: PowerPC Linux, etc: how to detect?
+        com_altivec->integer = 1;
+      #endif
+    #else
+      com_altivec->integer = 0;  // not an Altivec system, so never use it.
+    #endif
+  }
+}
+
 void Sys_Init(void)
 {
+  Sys_DetectAltivec();
+
   Cmd_AddCommand ("in_restart", Sys_In_Restart_f);
 
   Cvar_Set( "arch", OS_STRING " " ARCH_STRING );
@@ -643,6 +681,16 @@
 
 /*****************************************************************************/
 
+char *do_dlerror(void)
+{
+#if USE_SDL_VIDEO
+    return SDL_GetError();
+#else
+    return dlerror();
+#endif
+}
+
+
 /*
 =================
 Sys_UnloadDll
@@ -651,16 +699,23 @@
 */
 void Sys_UnloadDll( void *dllHandle ) {
   // bk001206 - verbose error reporting
-  const char* err; // rb010123 - now const
   if ( !dllHandle )
   {
     Com_Printf("Sys_UnloadDll(NULL)\n");
     return;
   }
+
+  #if USE_SDL_VIDEO
+  SDL_UnloadObject(dllHandle);
+  #else
   dlclose( dllHandle );
-  err = dlerror();
-  if ( err != NULL )
-    Com_Printf ( "Sys_UnloadGame failed on dlclose: \"%s\"!\n", err );
+  {
+    const char* err; // rb010123 - now const
+    err = dlerror();
+    if ( err != NULL )
+      Com_Printf ( "Sys_UnloadGame failed on dlclose: \"%s\"!\n", err );
+  }
+  #endif
 }
 
 
@@ -689,10 +744,15 @@
 
   fn = FS_BuildOSPath( base, gamedir, fname );
   Com_Printf( "Sys_LoadDll(%s)... \n", fn );
+
+  #if USE_SDL_VIDEO
+  libHandle = SDL_LoadObject(fn);
+  #else
   libHandle = dlopen( fn, Q_RTLD );
+  #endif
 
   if(!libHandle) {
-    Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
+    Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, do_dlerror() );
     return NULL;
   }
 
@@ -751,20 +811,31 @@
     return NULL;
   }
 
-  dllEntry = dlsym( libHandle, "dllEntry" ); 
+#if USE_SDL_VIDEO
+  dllEntry = SDL_LoadFunction( libHandle, "dllEntry" );
+  *entryPoint = SDL_LoadFunction( libHandle, "vmMain" );
+#else
+  dllEntry = dlsym( libHandle, "dllEntry" );
   *entryPoint = dlsym( libHandle, "vmMain" );
+#endif
+
   if ( !*entryPoint || !dllEntry )
   {
-    err = dlerror();
+    err = do_dlerror();
 #ifndef NDEBUG // bk001206 - in debug abort on failure
     Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
 #else
     Com_Printf ( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
 #endif
+    #if USE_SDL_VIDEO
+    SDL_UnloadObject(libHandle);
+    #else
     dlclose( libHandle );
-    err = dlerror();
+    err = do_dlerror();
     if ( err != NULL )
       Com_Printf ( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err );
+    #endif
+
     return NULL;
   }
   Com_Printf ( "Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint ); // bk001212
@@ -1322,4 +1393,7 @@
 #endif
     Com_Frame ();
   }
+
+  return 0;
 }
+




More information about the quake3-commits mailing list