]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
attempted fix for VC compile errors
[xonotic/darkplaces.git] / vid_sdl.c
index a9dd5c45db006ee9c36e75928aafa6a4c9d4fce5..e1210a64ab9a4b9cc27fcd8e7518e5d184e59bff 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "image.h"
 #include "dpsoftrast.h"
 
+#ifndef __IPHONEOS__
 #ifdef MACOSX
 #include <Carbon/Carbon.h>
 #include <IOKit/hidsystem/IOHIDLib.h>
@@ -54,6 +55,7 @@ io_connect_t IN_GetIOHandle(void)
        return iohandle;
 }
 #endif
+#endif
 
 #ifdef WIN32
 #define SDL_R_RESTART
@@ -65,6 +67,7 @@ int cl_available = true;
 qboolean vid_supportrefreshrate = false;
 
 cvar_t vid_soft = {CVAR_SAVE, "vid_soft", "0", "enables use of the DarkPlaces Software Rasterizer rather than OpenGL or Direct3D"};
+cvar_t vid_soft_threads = {CVAR_SAVE, "vid_soft_threads", "2", "the number of threads the DarkPlaces Software Rasterizer should use"}; 
 cvar_t joy_detected = {CVAR_READONLY, "joy_detected", "0", "number of joysticks detected by engine"};
 cvar_t joy_enable = {CVAR_SAVE, "joy_enable", "0", "enables joystick support"};
 cvar_t joy_index = {0, "joy_index", "0", "selects which joystick to use if you have multiple"};
@@ -91,6 +94,9 @@ cvar_t joy_axiskeyevents = {CVAR_SAVE, "joy_axiskeyevents", "0", "generate uparr
 static qboolean vid_usingmouse = false;
 static qboolean vid_usinghidecursor = false;
 static qboolean vid_isfullscreen;
+#if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
+static qboolean vid_usingvsync = false;
+#endif
 static int vid_numjoysticks = 0;
 #define MAX_JOYSTICKS 8
 static SDL_Joystick *vid_joysticks[MAX_JOYSTICKS];
@@ -285,16 +291,19 @@ static int MapKey( unsigned int sdlkey )
 
 void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
+#ifndef __IPHONEOS__
 #ifdef MACOSX
        if(relative)
                if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer))
                        VID_SetMouse(false, false, false); // ungrab first!
+#endif
 #endif
        if (vid_usingmouse != relative)
        {
                vid_usingmouse = relative;
                cl_ignoremousemoves = 2;
                SDL_WM_GrabInput( relative ? SDL_GRAB_ON : SDL_GRAB_OFF );
+#ifndef __IPHONEOS__
 #ifdef MACOSX
                if(relative)
                {
@@ -346,6 +355,7 @@ void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecurso
                                        Con_Print("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
                        }
                }
+#endif
 #endif
        }
        if (vid_usinghidecursor != hidecursor)
@@ -516,6 +526,7 @@ void IN_Move( void )
 // Message Handling
 ////
 
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
 static int Sys_EventFilter( SDL_Event *event )
 {
        //TODO: Add a quit query in linux, too - though linux user are more likely to know what they do
@@ -528,6 +539,7 @@ static int Sys_EventFilter( SDL_Event *event )
        }
        return 1;
 }
+#endif
 
 #ifdef SDL_R_RESTART
 static qboolean sdl_needs_restart;
@@ -574,6 +586,12 @@ void Sys_SendKeyEvents( void )
        while( SDL_PollEvent( &event ) )
                switch( event.type ) {
                        case SDL_QUIT:
+#if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
+#ifdef WIN32
+                               if (MessageBox( NULL, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION ) == IDNO)
+                                       return 0;
+#endif
+#endif
                                Sys_Quit(0);
                                break;
                        case SDL_KEYDOWN:
@@ -613,11 +631,11 @@ void Sys_SendKeyEvents( void )
                                        {
                                                SDL_FreeSurface(vid_softsurface);
                                                vid_softsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, vid.width, vid.height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
-                                               vid.softpixels = vid_softsurface->pixels;
+                                               vid.softpixels = (unsigned int *)vid_softsurface->pixels;
                                                SDL_SetAlpha(vid_softsurface, 0, 255);
                                                if (vid.softdepthpixels)
                                                        free(vid.softdepthpixels);
-                                               vid.softdepthpixels = calloc(1, vid.width * vid.height * 4);
+                                               vid.softdepthpixels = (unsigned int*)calloc(1, vid.width * vid.height * 4);
                                        }
 #ifdef SDL_R_RESTART
                                        // better not call R_Modules_Restart from here directly, as this may wreak havoc...
@@ -662,15 +680,20 @@ void *GL_GetProcAddress(const char *name)
        return p;
 }
 
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
 static int Sys_EventFilter( SDL_Event *event );
+#endif
 static qboolean vid_sdl_initjoysticksystem = false;
 
 void VID_Init (void)
 {
+#ifndef __IPHONEOS__
 #ifdef MACOSX
        Cvar_RegisterVariable(&apple_mouse_noaccel);
+#endif
 #endif
        Cvar_RegisterVariable(&vid_soft);
+       Cvar_RegisterVariable(&vid_soft_threads);
        Cvar_RegisterVariable(&joy_detected);
        Cvar_RegisterVariable(&joy_enable);
        Cvar_RegisterVariable(&joy_index);
@@ -903,6 +926,8 @@ static void VID_SetIcon_Pre(void)
 }
 static void VID_SetIcon_Post(void)
 {
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
+// LordHavoc: info.info.x11.lock_func and accompanying code do not seem to compile with SDL 1.3
 #if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
        int j;
        char *data;
@@ -956,6 +981,7 @@ static void VID_SetIcon_Post(void)
                }
        }
 #endif
+#endif
 }
 
 
@@ -978,6 +1004,7 @@ static void VID_OutputVersion(void)
 qboolean VID_InitModeGL(viddef_mode_t *mode)
 {
        int i;
+// FIXME SDL_SetVideoMode
        static int notfirstvideomode = false;
        int flags = SDL_OPENGL;
        const char *drivername;
@@ -1047,15 +1074,19 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        }
        if (mode->stereobuffer)
                SDL_GL_SetAttribute (SDL_GL_STEREO, 1);
-       if (vid_vsync.integer)
-               SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
-       else
-               SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
        if (mode->samples > 1)
        {
                SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1);
                SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, mode->samples);
        }
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
+       if (vid_vsync.integer)
+               SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
+       else
+               SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
+#else
+       // TODO: SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION
+#endif
 
        video_bpp = mode->bitsperpixel;
        video_flags = flags;
@@ -1075,13 +1106,20 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
 
        // set window title
        VID_SetCaption();
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
        // set up an event filter to ask confirmation on close button in WIN32
        SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter );
+#endif
        // init keyboard
        SDL_EnableUNICODE( SDL_ENABLE );
        // enable key repeat since everyone expects it
        SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
+#if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
+       SDL_GL_SetSwapInterval(vid_vsync.integer != 0);
+       vid_usingvsync = (vid_vsync.integer != 0);
+#endif
+
        gl_platform = "SDL";
        gl_platformextensions = "";
 
@@ -1122,6 +1160,7 @@ extern cvar_t gl_info_driver;
 
 qboolean VID_InitModeSoft(viddef_mode_t *mode)
 {
+// FIXME SDL_SetVideoMode
        int i;
        int flags = SDL_HWSURFACE;
 
@@ -1162,14 +1201,16 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        }
        SDL_SetAlpha(vid_softsurface, 0, 255);
 
-       vid.softpixels = vid_softsurface->pixels;
-       vid.softdepthpixels = calloc(1, mode->width * mode->height * 4);
-       DPSOFTRAST_Init(mode->width, mode->height, vid_softsurface->pixels, vid.softdepthpixels);
+       vid.softpixels = (unsigned int *)vid_softsurface->pixels;
+       vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
+       DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, (unsigned int *)vid_softsurface->pixels, (unsigned int *)vid.softdepthpixels);
 
        // set window title
        VID_SetCaption();
        // set up an event filter to ask confirmation on close button in WIN32
+#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
        SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter );
+#endif
        // init keyboard
        SDL_EnableUNICODE( SDL_ENABLE );
        // enable key repeat since everyone expects it
@@ -1192,7 +1233,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        vid.support.arb_draw_buffers = true;
        vid.support.arb_occlusion_query = true;
        vid.support.arb_shadow = true;
-       vid.support.arb_texture_compression = true;
+       //vid.support.arb_texture_compression = true;
        vid.support.arb_texture_cube_map = true;
        vid.support.arb_texture_non_power_of_two = false;
        vid.support.arb_vertex_buffer_object = true;
@@ -1200,7 +1241,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        vid.support.ext_draw_range_elements = true;
        vid.support.ext_framebuffer_object = true;
        vid.support.ext_texture_3d = true;
-       vid.support.ext_texture_compression_s3tc = true;
+       //vid.support.ext_texture_compression_s3tc = true;
        vid.support.ext_texture_filter_anisotropic = true;
        vid.support.ati_separate_stencil = true;
 
@@ -1262,9 +1303,11 @@ qboolean VID_InitMode(viddef_mode_t *mode)
 {
        if (!SDL_WasInit(SDL_INIT_VIDEO) && SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
                Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError());
+#ifdef SSE2_PRESENT
        if (vid_soft.integer)
                return VID_InitModeSoft(mode);
        else
+#endif
                return VID_InitModeGL(mode);
 }
 
@@ -1334,9 +1377,23 @@ void VID_Finish (void)
                        {
                                qglFinish();CHECKGLERROR
                        }
+#if !(SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2)
+{
+       qboolean vid_usevsync;
+       vid_usevsync = (vid_vsync.integer && !cls.timedemo);
+       if (vid_usingvsync != vid_usevsync)
+       {
+               if (SDL_GL_SetSwapInterval(vid_usevsync != 0) >= 0)
+                       Con_DPrintf("Vsync %s\n", vid_usevsync ? "activated" : "deactivated");
+               else
+                       Con_DPrintf("ERROR: can't %s vsync\n", vid_usevsync ? "activate" : "deactivate");
+       }
+}
+#endif
                        SDL_GL_SwapBuffers();
                        break;
                case RENDERPATH_SOFT:
+                       DPSOFTRAST_Finish();
                        SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
                        SDL_Flip(screen);
                        break;