]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
disabled glBegin, glEnd, glPolygonMode wrapper functions in GLES2 init
[xonotic/darkplaces.git] / vid_sdl.c
index 73448881fdb4f52576cb61aaa61ade413e790b71..1ae3fc0391300e7de0b166a8bfc6df4a923f69f7 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -66,9 +66,6 @@ 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 vid_soft_interlace = {CVAR_SAVE, "vid_soft_interlace", "1", "whether the DarkPlaces Software Rasterizer should interlace the screen bands occupied by each thread"};
 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,8 +88,9 @@ cvar_t joy_sensitivitypitch = {0, "joy_sensitivitypitch", "1", "movement multipl
 cvar_t joy_sensitivityyaw = {0, "joy_sensitivityyaw", "-1", "movement multiplier"};
 cvar_t joy_sensitivityroll = {0, "joy_sensitivityroll", "1", "movement multiplier"};
 cvar_t joy_axiskeyevents = {CVAR_SAVE, "joy_axiskeyevents", "0", "generate uparrow/leftarrow etc. keyevents for joystick axes, use if your joystick driver is not generating them"};
+cvar_t joy_axiskeyevents_deadzone = {CVAR_SAVE, "joy_axiskeyevents_deadzone", "0.5", "deadzone value for axes"};
 
-#ifdef __IPHONEOS__
+#ifdef USE_GLES2
 # define SETVIDEOMODE 0
 #else
 # if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
@@ -584,10 +582,10 @@ static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode)
                SDL_Joystick *joy = vid_joysticks[joy_index.integer];
 
                if (keycode == K_UPARROW || keycode == K_DOWNARROW)
-                       if (IN_JoystickGetAxis(joy, joy_axisforward.integer, 1, 0.01) || joy_axescache[joy_axisforward.integer].move || joy_axescache[joy_axisforward.integer].oldmove)
+                       if (IN_JoystickGetAxis(joy, joy_axisforward.integer, 1, joy_axiskeyevents_deadzone.value) || joy_axescache[joy_axisforward.integer].move || joy_axescache[joy_axisforward.integer].oldmove)
                                return true;
                if (keycode == K_RIGHTARROW || keycode == K_LEFTARROW)
-                       if (IN_JoystickGetAxis(joy, joy_axisside.integer, 1, 0.01) || joy_axescache[joy_axisside.integer].move || joy_axescache[joy_axisside.integer].oldmove)
+                       if (IN_JoystickGetAxis(joy, joy_axisside.integer, 1, joy_axiskeyevents_deadzone.value) || joy_axescache[joy_axisside.integer].move || joy_axescache[joy_axisside.integer].oldmove)
                                return true;
        }
 
@@ -599,28 +597,33 @@ static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode)
 #define MAXFINGERS 11
 int multitouch[MAXFINGERS][3];
 
-qboolean VID_TouchscreenArea(float x, float y, float width, float height, const char *icon, float *resultmove, qboolean *resultbutton, keynum_t key)
+qboolean VID_TouchscreenArea(int corner, float px, float py, float pwidth, float pheight, const char *icon, float *resultmove, qboolean *resultbutton, keynum_t key)
 {
        int finger;
+       float fx, fy, fwidth, fheight;
        float rel[3];
        qboolean button = false;
        VectorClear(rel);
+       if (pwidth > 0 && pheight > 0)
 #ifdef __IPHONEOS__
-       if (width > 0 && height > 0 && (key == '`' || key == K_ESCAPE || !VID_ShowingKeyboard()))
-#else
-       if (width > 0 && height > 0 && (key == '`' || key == K_ESCAPE))
+       if (!VID_ShowingKeyboard())
 #endif
        {
-               x *= 32768.0f / 320.0f;
-               y *= 32768.0f / 480.0f;
-               width *= 32768.0f / 320.0f;
-               height *= 32768.0f / 480.0f;
+               if (corner & 1) px += vid_conwidth.value;
+               if (corner & 2) py += vid_conheight.value;
+               if (corner & 4) px += vid_conwidth.value * 0.5f;
+               if (corner & 8) py += vid_conheight.value * 0.5f;
+               if (corner & 16) {px *= vid_conwidth.value * (1.0f / 640.0f);py *= vid_conheight.value * (1.0f / 480.0f);pwidth *= vid_conwidth.value * (1.0f / 640.0f);pheight *= vid_conheight.value * (1.0f / 480.0f);}
+               fx = px * 32768.0f / vid_conwidth.value;
+               fy = py * 32768.0f / vid_conheight.value;
+               fwidth = pwidth * 32768.0f / vid_conwidth.value;
+               fheight = pheight * 32768.0f / vid_conheight.value;
                for (finger = 0;finger < MAXFINGERS;finger++)
                {
-                       if (multitouch[finger][0] && multitouch[finger][1] >= x && multitouch[finger][2] >= y && multitouch[finger][1] < x + width && multitouch[finger][2] < y + height)
+                       if (multitouch[finger][0] && multitouch[finger][1] >= fx && multitouch[finger][2] >= fy && multitouch[finger][1] < fx + fwidth && multitouch[finger][2] < fy + fheight)
                        {
-                               rel[0] = (multitouch[finger][1] - (x + 0.5f * width)) * (2.0f / width);
-                               rel[1] = (multitouch[finger][2] - (y + 0.5f * height)) * (2.0f / height);
+                               rel[0] = (multitouch[finger][1] - (fx + 0.5f * fwidth)) * (2.0f / fwidth);
+                               rel[1] = (multitouch[finger][2] - (fy + 0.5f * fheight)) * (2.0f / fheight);
                                rel[2] = 0;
                                button = true;
                                break;
@@ -629,10 +632,10 @@ qboolean VID_TouchscreenArea(float x, float y, float width, float height, const
                if (scr_numtouchscreenareas < 16)
                {
                        scr_touchscreenareas[scr_numtouchscreenareas].pic = icon;
-                       scr_touchscreenareas[scr_numtouchscreenareas].rect[0] = x * vid_conwidth.value / 32768.0f;
-                       scr_touchscreenareas[scr_numtouchscreenareas].rect[1] = y * vid_conheight.value / 32768.0f;
-                       scr_touchscreenareas[scr_numtouchscreenareas].rect[2] = width * vid_conwidth.value / 32768.0f;
-                       scr_touchscreenareas[scr_numtouchscreenareas].rect[3] = height * vid_conheight.value / 32768.0f;
+                       scr_touchscreenareas[scr_numtouchscreenareas].rect[0] = px;
+                       scr_touchscreenareas[scr_numtouchscreenareas].rect[1] = py;
+                       scr_touchscreenareas[scr_numtouchscreenareas].rect[2] = pwidth;
+                       scr_touchscreenareas[scr_numtouchscreenareas].rect[3] = pheight;
                        scr_touchscreenareas[scr_numtouchscreenareas].active = button;
                        scr_numtouchscreenareas++;
                }
@@ -686,42 +689,63 @@ void IN_Move( void )
                }
                oldkeydest = keydest;
                // top of screen is toggleconsole and K_ESCAPE
-                       VID_TouchscreenArea(  0,   0,  50,  50, NULL                         , NULL, &buttons[13], (keynum_t)'`');
-                       VID_TouchscreenArea( 50,   0, 270,  50, "gfx/touch_menu.tga"         , NULL, &buttons[14], K_ESCAPE);
                switch(keydest)
                {
                case key_console:
 #ifdef __IPHONEOS__
+                       VID_TouchscreenArea( 0,   0,   0,  64,  64, NULL                         , NULL, &buttons[13], (keynum_t)'`');
+                       VID_TouchscreenArea( 0,  64,   0,  64,  64, "gfx/touch_menu.tga"         , NULL, &buttons[14], K_ESCAPE);
                        if (!VID_ShowingKeyboard())
                        {
                                // user entered a command, close the console now
                                Con_ToggleConsole_f();
                        }
 #endif
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[15], (keynum_t)0);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , move, &buttons[0], K_MOUSE4);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , aim,  &buttons[1], K_MOUSE5);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , click,&buttons[2], K_MOUSE1);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[3], K_SPACE);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[4], K_MOUSE2);
                        break;
                case key_game:
-                       VID_TouchscreenArea(  0, 380, 100, 100, "gfx/touch_movebutton.tga"   , move, &buttons[0], K_MOUSE4);
-                       VID_TouchscreenArea(220, 380, 100, 100, "gfx/touch_aimbutton.tga"    , aim,  &buttons[1], K_MOUSE5);
-                       VID_TouchscreenArea(110, 380, 100, 100, "gfx/touch_attackbutton.tga" , NULL, &buttons[2], K_MOUSE1);
-                       VID_TouchscreenArea(  0, 330, 100,  50, "gfx/touch_jumpbutton.tga"   , NULL, &buttons[3], K_SPACE);
-                       VID_TouchscreenArea(220, 330, 100,  50, "gfx/touch_attack2button.tga", NULL, &buttons[4], K_MOUSE2);
+#ifdef __IPHONEOS__
+                       VID_TouchscreenArea( 0,   0,   0,  64,  64, NULL                         , NULL, &buttons[13], (keynum_t)'`');
+                       VID_TouchscreenArea( 0,  64,   0,  64,  64, "gfx/touch_menu.tga"         , NULL, &buttons[14], K_ESCAPE);
+#endif
+                       VID_TouchscreenArea( 2,   0,-128, 128, 128, "gfx/touch_movebutton.tga"   , move, &buttons[0], K_MOUSE4);
+                       VID_TouchscreenArea( 3,-128,-128, 128, 128, "gfx/touch_aimbutton.tga"    , aim,  &buttons[1], K_MOUSE5);
+                       VID_TouchscreenArea( 2,   0,-160,  64,  32, "gfx/touch_jumpbutton.tga"   , NULL, &buttons[3], K_SPACE);
+                       VID_TouchscreenArea( 3,-128,-160,  64,  32, "gfx/touch_attackbutton.tga" , NULL, &buttons[2], K_MOUSE1);
+                       VID_TouchscreenArea( 3, -64,-160,  64,  32, "gfx/touch_attack2button.tga", NULL, &buttons[4], K_MOUSE2);
                        buttons[15] = false;
                        break;
                default:
+#ifdef __IPHONEOS__
+                       VID_TouchscreenArea( 0,   0,   0,  64,  64, NULL                         , NULL, &buttons[13], (keynum_t)'`');
+                       VID_TouchscreenArea( 0,  64,   0,  64,  64, "gfx/touch_menu.tga"         , NULL, &buttons[14], K_ESCAPE);
                        // in menus, an icon in the corner activates keyboard
-                       VID_TouchscreenArea(  0, 430,  50,  50, "gfx/touch_keyboard.tga"     , NULL, &buttons[15], (keynum_t)0);
+                       VID_TouchscreenArea( 2,   0, -32,  32,  32, "gfx/touch_keyboard.tga"     , NULL, &buttons[15], (keynum_t)0);
                        if (buttons[15])
                                VID_ShowKeyboard(true);
-                       VID_TouchscreenArea(  0,   0,   0,   0, NULL                         , move, &buttons[0], K_MOUSE4);
-                       VID_TouchscreenArea(  0,   0,   0,   0, NULL                         , aim,  &buttons[1], K_MOUSE5);
-                       VID_TouchscreenArea(-320,-480,640, 960, NULL                         , click,&buttons[2], K_MOUSE1);
-                       VID_TouchscreenArea(  0,   0,   0,   0, NULL                         , NULL, &buttons[3], K_SPACE);
-                       VID_TouchscreenArea(  0,   0,   0,   0, NULL                         , NULL, &buttons[4], K_MOUSE2);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , move, &buttons[0], K_MOUSE4);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , aim,  &buttons[1], K_MOUSE5);
+                       VID_TouchscreenArea(16, -320,-480,640, 960, NULL                         , click,&buttons[2], K_MOUSE1);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[3], K_SPACE);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[4], K_MOUSE2);
                        if (buttons[2])
                        {
                                in_windowmouse_x = x;
                                in_windowmouse_y = y;
                        }
+#else
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[15], (keynum_t)0);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , move, &buttons[0], K_MOUSE4);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , aim,  &buttons[1], K_MOUSE5);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , click,&buttons[2], K_MOUSE1);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[3], K_SPACE);
+                       VID_TouchscreenArea( 0,   0,   0,   0,   0, NULL                         , NULL, &buttons[4], K_MOUSE2);
+#endif
                        break;
                }
                cl.cmd.forwardmove -= move[1] * cl_forwardspeed.value;
@@ -800,7 +824,7 @@ void IN_Move( void )
                for (j = 0; j < numaxes; j++)
                {
                        joy_axescache[j].oldmove = joy_axescache[j].move;
-                       joy_axescache[j].move = IN_JoystickGetAxis(joy, j, 1, 0.01);
+                       joy_axescache[j].move = IN_JoystickGetAxis(joy, j, 1, joy_axiskeyevents_deadzone.value);
                }
 
                // run keyevents
@@ -884,6 +908,7 @@ void Sys_SendKeyEvents( void )
                                break;
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
+                               if (!vid_touchscreen.integer)
                                if (event.button.button <= 18)
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
                                break;
@@ -894,6 +919,12 @@ void Sys_SendKeyEvents( void )
                                if (event.jbutton.button < 48)
                                        Key_Event( event.jbutton.button + (event.jbutton.button < 16 ? K_JOY1 : K_AUX1 - 16), 0, (event.jbutton.state == SDL_PRESSED) );
                                break;
+                       case SDL_JOYAXISMOTION:
+                       case SDL_JOYBALLMOTION:
+                       case SDL_JOYHATMOTION:
+                               break;
+                       case SDL_VIDEOEXPOSE:
+                               break;
                        case SDL_VIDEORESIZE:
                                if(vid_resizable.integer < 2)
                                {
@@ -991,10 +1022,9 @@ void Sys_SendKeyEvents( void )
                                break;
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
-#ifndef __IPHONEOS__
+                               if (!vid_touchscreen.integer)
                                if (event.button.button <= 18)
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
-#endif
                                break;
                        case SDL_JOYBUTTONDOWN:
                                if (!joy_enable.integer)
@@ -1003,6 +1033,12 @@ void Sys_SendKeyEvents( void )
                                if (event.jbutton.button < 48)
                                        Key_Event( event.jbutton.button + (event.jbutton.button < 16 ? K_JOY1 : K_AUX1 - 16), 0, (event.jbutton.state == SDL_PRESSED) );
                                break;
+                       case SDL_JOYAXISMOTION:
+                       case SDL_JOYBALLMOTION:
+                       case SDL_JOYHATMOTION:
+                               break;
+                       case SDL_VIDEOEXPOSE:
+                               break;
                        case SDL_WINDOWEVENT:
                                //if (event.window.windowID == window) // how to compare?
                                {
@@ -1184,9 +1220,12 @@ void Sys_SendKeyEvents( void )
 // Video system
 ////
 
+#ifdef USE_GLES2
 #ifdef __IPHONEOS__
-//#include <SDL_opengles.h>
 #include <OpenGLES/ES2/gl.h>
+#else
+#include <SDL_opengles.h>
+#endif
 
 GLboolean wrapglIsBuffer(GLuint buffer) {return glIsBuffer(buffer);}
 GLboolean wrapglIsEnabled(GLenum cap) {return glIsEnabled(cap);}
@@ -1208,9 +1247,10 @@ void wrapglActiveTexture(GLenum e) {glActiveTexture(e);}
 void wrapglAlphaFunc(GLenum func, GLclampf ref) {Con_Printf("glAlphaFunc(func, ref)\n");}
 void wrapglArrayElement(GLint i) {Con_Printf("glArrayElement(i)\n");}
 void wrapglAttachShader(GLuint containerObj, GLuint obj) {glAttachShader(containerObj, obj);}
-void wrapglBegin(GLenum mode) {Con_Printf("glBegin(mode)\n");}
+//void wrapglBegin(GLenum mode) {Con_Printf("glBegin(mode)\n");}
 //void wrapglBeginQuery(GLenum target, GLuint qid) {glBeginQuery(target, qid);}
 void wrapglBindAttribLocation(GLuint programObj, GLuint index, const GLchar *name) {glBindAttribLocation(programObj, index, name);}
+void wrapglBindFragDataLocation(GLuint programObj, GLuint index, const GLchar *name) {glBindFragDataLocation(programObj, index, name);}
 void wrapglBindBuffer(GLenum target, GLuint buffer) {glBindBuffer(target, buffer);}
 void wrapglBindFramebuffer(GLenum target, GLuint framebuffer) {glBindFramebuffer(target, framebuffer);}
 void wrapglBindRenderbuffer(GLenum target, GLuint renderbuffer) {glBindRenderbuffer(target, renderbuffer);}
@@ -1260,7 +1300,7 @@ void wrapglDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *i
 void wrapglEnable(GLenum cap) {glEnable(cap);}
 void wrapglEnableClientState(GLenum cap) {Con_Printf("glEnableClientState(cap)\n");}
 void wrapglEnableVertexAttribArray(GLuint index) {glEnableVertexAttribArray(index);}
-void wrapglEnd(void) {Con_Printf("glEnd()\n");}
+//void wrapglEnd(void) {Con_Printf("glEnd()\n");}
 //void wrapglEndQuery(GLenum target) {glEndQuery(target);}
 void wrapglFinish(void) {glFinish();}
 void wrapglFlush(void) {glFlush();}
@@ -1311,7 +1351,7 @@ void wrapglMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLflo
 void wrapglNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr) {Con_Printf("glNormalPointer(type, stride, ptr)\n");}
 void wrapglPixelStorei(GLenum pname, GLint param) {glPixelStorei(pname, param);}
 void wrapglPointSize(GLfloat size) {Con_Printf("glPointSize(size)\n");}
-void wrapglPolygonMode(GLenum face, GLenum mode) {Con_Printf("glPolygonMode(face, mode)\n");}
+//void wrapglPolygonMode(GLenum face, GLenum mode) {Con_Printf("glPolygonMode(face, mode)\n");}
 void wrapglPolygonOffset(GLfloat factor, GLfloat units) {glPolygonOffset(factor, units);}
 void wrapglPolygonStipple(const GLubyte *mask) {Con_Printf("glPolygonStipple(mask)\n");}
 void wrapglReadBuffer(GLenum mode) {Con_Printf("glReadBuffer(mode)\n");}
@@ -1429,9 +1469,10 @@ void GLES_Init(void)
        qglAlphaFunc = wrapglAlphaFunc;
        qglArrayElement = wrapglArrayElement;
        qglAttachShader = wrapglAttachShader;
-       qglBegin = wrapglBegin;
+//     qglBegin = wrapglBegin;
 //     qglBeginQueryARB = wrapglBeginQuery;
        qglBindAttribLocation = wrapglBindAttribLocation;
+       qglBindFragDataLocation = wrapglBindFragDataLocation;
        qglBindBufferARB = wrapglBindBuffer;
        qglBindFramebufferEXT = wrapglBindFramebuffer;
        qglBindRenderbufferEXT = wrapglBindRenderbuffer;
@@ -1480,7 +1521,7 @@ void GLES_Init(void)
        qglEnable = wrapglEnable;
        qglEnableClientState = wrapglEnableClientState;
        qglEnableVertexAttribArray = wrapglEnableVertexAttribArray;
-       qglEnd = wrapglEnd;
+//     qglEnd = wrapglEnd;
 //     qglEndQueryARB = wrapglEndQuery;
        qglFinish = wrapglFinish;
        qglFlush = wrapglFlush;
@@ -1531,7 +1572,7 @@ void GLES_Init(void)
        qglNormalPointer = wrapglNormalPointer;
        qglPixelStorei = wrapglPixelStorei;
        qglPointSize = wrapglPointSize;
-       qglPolygonMode = wrapglPolygonMode;
+//     qglPolygonMode = wrapglPolygonMode;
        qglPolygonOffset = wrapglPolygonOffset;
 //     qglPolygonStipple = wrapglPolygonStipple;
        qglReadBuffer = wrapglReadBuffer;
@@ -1645,6 +1686,9 @@ void GLES_Init(void)
        
        // LordHavoc: report supported extensions
        Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
+
+       // GLES devices in general do not like GL_BGRA, so use GL_RGBA
+       vid.forcetextype = TEXTYPE_RGBA;
        
        vid.support.gl20shaders = true;
        vid.support.amd_texture_texture4 = false;
@@ -1669,6 +1713,7 @@ void GLES_Init(void)
        vid.support.ext_texture_compression_s3tc = false;
        vid.support.ext_texture_edge_clamp = true;
        vid.support.ext_texture_filter_anisotropic = false; // probably don't want to use it...
+       vid.support.ext_texture_srgb = false;
 
        qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
        if (vid.support.ext_texture_filter_anisotropic)
@@ -1731,9 +1776,6 @@ void VID_Init (void)
        Cvar_RegisterVariable(&apple_mouse_noaccel);
 #endif
 #endif
-       Cvar_RegisterVariable(&vid_soft);
-       Cvar_RegisterVariable(&vid_soft_threads);
-       Cvar_RegisterVariable(&vid_soft_interlace);
        Cvar_RegisterVariable(&joy_detected);
        Cvar_RegisterVariable(&joy_enable);
        Cvar_RegisterVariable(&joy_index);
@@ -1756,6 +1798,7 @@ void VID_Init (void)
        Cvar_RegisterVariable(&joy_sensitivityyaw);
        //Cvar_RegisterVariable(&joy_sensitivityroll);
        Cvar_RegisterVariable(&joy_axiskeyevents);
+       Cvar_RegisterVariable(&joy_axiskeyevents_deadzone);
 #ifdef __IPHONEOS__
        Cvar_SetValueQuick(&vid_touchscreen, 1);
 #endif
@@ -2098,7 +2141,8 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        mode->fullscreen = true;
        // hide the menu with SDL_WINDOW_BORDERLESS
        windowflags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
-#else
+#endif
+#ifndef USE_GLES2
        if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
        {
                VID_Shutdown();
@@ -2150,13 +2194,10 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        else
                SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 0);
 #else
-#ifdef __IPHONEOS__
+#ifdef USE_GLES2
        SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
        SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
        SDL_GL_SetAttribute (SDL_GL_RETAINED_BACKING, 1);
-       // FIXME: get proper resolution from OS somehow (iPad for instance...)
-       mode->width = 320;
-       mode->height = 480;
 #endif
 #endif
 
@@ -2213,7 +2254,7 @@ qboolean VID_InitModeGL(viddef_mode_t *mode)
        gl_platform = "SDL";
        gl_platformextensions = "";
 
-#ifdef __IPHONEOS__
+#ifdef USE_GLES2
        GLES_Init();
 #else
        GL_Init();
@@ -2260,6 +2301,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        int i;
 #if SETVIDEOMODE
        int flags = SDL_HWSURFACE;
+       if(!COM_CheckParm("-noasyncblit")) flags |= SDL_ASYNCBLIT;
 #else
        int windowflags = SDL_WINDOW_SHOWN;
 #endif
@@ -2340,62 +2382,7 @@ qboolean VID_InitModeSoft(viddef_mode_t *mode)
        // enable key repeat since everyone expects it
        SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
-       gl_platform = "SDLSoft";
-       gl_platformextensions = "";
-
-       gl_renderer = "DarkPlaces-Soft";
-       gl_vendor = "Forest Hale";
-       gl_version = "0.0";
-       gl_extensions = "";
-
-       // clear the extension flags
-       memset(&vid.support, 0, sizeof(vid.support));
-       Cvar_SetQuick(&gl_info_extensions, "");
-
-       vid.forcevbo = false;
-       vid.support.arb_depth_texture = true;
-       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_cube_map = true;
-       vid.support.arb_texture_non_power_of_two = false;
-       vid.support.arb_vertex_buffer_object = true;
-       vid.support.ext_blend_subtract = true;
-       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_filter_anisotropic = true;
-       vid.support.ati_separate_stencil = true;
-
-       vid.maxtexturesize_2d = 16384;
-       vid.maxtexturesize_3d = 512;
-       vid.maxtexturesize_cubemap = 16384;
-       vid.texunits = 4;
-       vid.teximageunits = 32;
-       vid.texarrayunits = 8;
-       vid.max_anisotropy = 1;
-       vid.maxdrawbuffers = 4;
-
-       vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
-       vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
-       vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
-       Con_DPrintf("Using DarkPlaces Software Rasterizer rendering path\n");
-       vid.renderpath = RENDERPATH_SOFT;
-       vid.useinterleavedarrays = false;
-
-       Cvar_SetQuick(&gl_info_vendor, gl_vendor);
-       Cvar_SetQuick(&gl_info_renderer, gl_renderer);
-       Cvar_SetQuick(&gl_info_version, gl_version);
-       Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
-       Cvar_SetQuick(&gl_info_driver, gl_driver);
-
-       // LordHavoc: report supported extensions
-       Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
-
-       // clear to black (loading plaque will be seen over this)
-       GL_Clear(GL_COLOR_BUFFER_BIT, NULL, 1.0f, 128);
+       VID_Soft_SharedSetup();
 
        vid_numjoysticks = SDL_NumJoysticks();
        vid_numjoysticks = bound(0, vid_numjoysticks, MAX_JOYSTICKS);
@@ -2430,7 +2417,7 @@ 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
+#ifdef SSE_POSSIBLE
        if (vid_soft.integer)
                return VID_InitModeSoft(mode);
        else
@@ -2505,12 +2492,11 @@ void VID_Finish (void)
                case RENDERPATH_GL11:
                case RENDERPATH_GL13:
                case RENDERPATH_GL20:
+               case RENDERPATH_GLES1:
                case RENDERPATH_GLES2:
                        CHECKGLERROR
                        if (r_speeds.integer == 2 || gl_finish.integer)
-                       {
-                               qglFinish();CHECKGLERROR
-                       }
+                               GL_Finish();
 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2
 #else
 {
@@ -2534,8 +2520,11 @@ void VID_Finish (void)
                case RENDERPATH_SOFT:
                        DPSOFTRAST_Finish();
 #if SETVIDEOMODE
+//             if (!r_test.integer)
+               {
                        SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
                        SDL_Flip(screen);
+               }
 #else
                        {
                                SDL_Surface *screen = SDL_GetWindowSurface(window);
@@ -2547,6 +2536,8 @@ void VID_Finish (void)
                case RENDERPATH_D3D9:
                case RENDERPATH_D3D10:
                case RENDERPATH_D3D11:
+                       if (r_speeds.integer == 2 || gl_finish.integer)
+                               GL_Finish();
                        break;
                }
        }
@@ -2559,7 +2550,7 @@ size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
        int bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
 
        k = 0;
-       for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); *vidmodes; ++vidmodes)
+       for(vidmodes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); vidmodes && *vidmodes; ++vidmodes)
        {
                if(k >= maxcount)
                        break;