diff options
Diffstat (limited to 'code/unix')
-rw-r--r-- | code/unix/Makefile | 192 | ||||
-rw-r--r-- | code/unix/linux_glimp.c | 4 | ||||
-rw-r--r-- | code/unix/linux_qgl.c | 79 | ||||
-rw-r--r-- | code/unix/sdl_glimp.c | 70 | ||||
-rw-r--r-- | code/unix/sdl_snd.c | 4 | ||||
-rw-r--r-- | code/unix/unix_glw.h | 2 | ||||
-rw-r--r-- | code/unix/unix_main.c | 94 |
7 files changed, 371 insertions, 74 deletions
diff --git a/code/unix/Makefile b/code/unix/Makefile index 461c47b..b4bfd15 100644 --- a/code/unix/Makefile +++ b/code/unix/Makefile @@ -13,7 +13,17 @@ 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 ############################################################################# # @@ -43,6 +53,11 @@ ifndef DXSDK_DIR DXSDK_DIR=C:/DXSDK endif +ifndef USE_CCACHE +USE_CCACHE=1 +endif +export USE_CCACHE + ifndef USE_SDL USE_SDL=1 endif @@ -121,7 +136,10 @@ ifeq ($(PLATFORM),linux) 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 @@ -153,6 +171,7 @@ ifeq ($(PLATFORM),linux) HAVE_VM_COMPILED=true else ifeq ($(ARCH),ppc) + BASE_CFLAGS += -maltivec ifneq ($(VM_PPC),) HAVE_VM_COMPILED=true endif @@ -181,8 +200,10 @@ ifeq ($(PLATFORM),linux) 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 @@ ifeq ($(PLATFORM),linux) 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 @@ else # ifeq SunOS ############################################################################# # SETUP AND BUILD -- GENERIC ############################################################################# - CC=cc BASE_CFLAGS=-DNO_VM_COMPILED DEBUG_CFLAGS=$(BASE_CFLAGS) -g @@ -508,11 +628,17 @@ else # ifeq SunOS $(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 @@ ifeq ($(GENERATE_DEPENDENCIES),1) 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,6 +990,33 @@ else 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=\ @@ -895,16 +1048,25 @@ ifeq ($(PLATFORM),SunOS) 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) diff --git a/code/unix/linux_glimp.c b/code/unix/linux_glimp.c index 3c35c74..a72c50a 100644 --- a/code/unix/linux_glimp.c +++ b/code/unix/linux_glimp.c @@ -1265,7 +1265,9 @@ static void GLW_InitExtensions( void ) 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 ) { diff --git a/code/unix/linux_qgl.c b/code/unix/linux_qgl.c index efb54db..3a21e58 100644 --- a/code/unix/linux_qgl.c +++ b/code/unix/linux_qgl.c @@ -45,8 +45,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA //#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__) @@ -60,12 +64,14 @@ void (*qfxMesaSwapBuffers)(void); #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 * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t 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 logAccum(GLenum op, GLfloat value) 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 logArrayElement(GLint i) 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 logBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLf 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 logDepthRange(GLclampd zNear, GLclampd zFar) 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 logEdgeFlagv(const GLboolean *flag) 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 logGetTexParameteriv(GLenum target, GLenum pname, GLint *pa 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 logPointSize(GLfloat size) 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 logTexCoordPointer(GLint size, GLenum type, GLsizei stride, 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 logTexEnvfv(GLenum target, GLenum pname, const GLfloat *par 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 logTexImage2D(GLenum target, GLint level, GLint internalfor 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 logTexParameterfv(GLenum target, GLenum pname, const GLfloa } 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 @@ void QGL_Shutdown( void ) 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 @@ void QGL_Shutdown( void ) 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 @@ void *qwglGetProcAddress(char *symbol) return NULL; } +char *do_dlerror(void); + /* ** QGL_Init ** @@ -3052,23 +3069,39 @@ void *qwglGetProcAddress(char *symbol) 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 @@ qboolean QGL_Init( const char *dllname ) 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; diff --git a/code/unix/sdl_glimp.c b/code/unix/sdl_glimp.c index 595fdeb..339dd79 100644 --- a/code/unix/sdl_glimp.c +++ b/code/unix/sdl_glimp.c @@ -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@icculus.org). Please refer to @@ -107,6 +107,23 @@ cvar_t *joy_threshold = NULL; 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 @@ static const char *XLateKey(SDL_keysym *keysym, int *key) 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 @@ static const char *XLateKey(SDL_keysym *keysym, int *key) // ch = ch - 'A' + 'a'; buf[0] = ch; - } - else if(keysym->unicode == 8) // ctrl-h + } + else if(keysym->unicode == 8) // ctrl-h buf[0] = 8; + } return buf; } static void install_grabs(void) { - SDL_ShowCursor(0); SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_ShowCursor(0); + + // 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_SetGamma( unsigned char red[256], unsigned char green[256], unsigned void GLimp_Shutdown( void ) { IN_Shutdown(); - SDL_QuitSubSystem(SDL_INIT_VIDEO); screen = NULL; memset( &glConfig, 0, sizeof( glConfig ) ); @@ -448,16 +476,8 @@ static qboolean GLW_StartDriverAndSetMode( const char *drivername, { 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 @@ static void GLW_InitExtensions( void ) 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 @@ static void GLW_InitExtensions( void ) 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 @@ static qboolean GLW_LoadOpenGL( const char *name ) { 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 diff --git a/code/unix/sdl_snd.c b/code/unix/sdl_snd.c index ac4a614..20d4bfd 100644 --- a/code/unix/sdl_snd.c +++ b/code/unix/sdl_snd.c @@ -81,6 +81,10 @@ https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=371 <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; diff --git a/code/unix/unix_glw.h b/code/unix/unix_glw.h index 1e88c13..1d81588 100644 --- a/code/unix/unix_glw.h +++ b/code/unix/unix_glw.h @@ -19,7 +19,7 @@ along with Quake III Arena source code; if not, write to the Free Software 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 diff --git a/code/unix/unix_main.c b/code/unix/unix_main.c index 050029e..82c9a42 100644 --- a/code/unix/unix_main.c +++ b/code/unix/unix_main.c @@ -41,7 +41,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #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 @@ void Sys_Quit (void) { 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 *Sys_ConsoleInput(void) /*****************************************************************************/ +char *do_dlerror(void) +{ +#if USE_SDL_VIDEO + return SDL_GetError(); +#else + return dlerror(); +#endif +} + + /* ================= Sys_UnloadDll @@ -651,16 +699,23 @@ Sys_UnloadDll */ 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 @@ static void* try_dlopen(const char* base, const char* gamedir, const char* fname 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 @@ void *Sys_LoadDll( const char *name, char *fqpath , 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 @@ int main ( int argc, char* argv[] ) #endif Com_Frame (); } + + return 0; } + |