]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
added RENDERPATH_GLES2
[xonotic/darkplaces.git] / gl_draw.c
index 16eb6069ae1d2a080f8beaa21c3d3c41034446a8..1de605a25bed32977129cfd54f390f32fc946be9 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -318,6 +318,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        unsigned char *lmpdata;
        char lmpname[MAX_QPATH];
        int texflags;
+       int j;
 
        texflags = TEXF_ALPHA;
        if (!(cachepicflags & CACHEPICFLAG_NOCLAMP))
@@ -330,10 +331,15 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
        for (pic = cachepichash[hashkey];pic;pic = pic->chain)
                if (!strcmp (path, pic->name))
-                       if(pic->texflags == texflags)
+                       if(!((pic->texflags ^ texflags) & ~(TEXF_COMPRESS))) // ignore TEXF_COMPRESS when comparing, because fallback pics remove the flag
                        {
                                if(!(cachepicflags & CACHEPICFLAG_NOTPERSISTENT))
-                                       pic->autoload = false; // persist it
+                               {
+                                       if(pic->tex)
+                                               pic->autoload = false; // persist it
+                                       else
+                                               goto reload; // load it below, and then persist
+                               }
                                return pic;
                        }
 
@@ -349,6 +355,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        pic->chain = cachepichash[hashkey];
        cachepichash[hashkey] = pic;
 
+reload:
        // check whether it is an dynamic texture (if so, we can directly use its texture handler)
        pic->tex = CL_GetDynTexture( path );
        // if so, set the width/height, too
@@ -359,6 +366,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                return pic;
        }
 
+       pic->hasalpha = true; // assume alpha unless we know it has none
        pic->texflags = texflags;
        pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
 
@@ -368,10 +376,23 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer != 0, NULL);
        if (pixels)
        {
+               pic->hasalpha = false;
+               if (pic->texflags & TEXF_ALPHA)
+               {
+                       for (j = 3;j < image_width * image_height * 4;j += 4)
+                       {
+                               if (pixels[j] < 255)
+                               {
+                                       pic->hasalpha = true;
+                                       break;
+                               }
+                       }
+               }
+
                pic->width = image_width;
                pic->height = image_height;
                if (!pic->autoload)
-                       pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags, -1, NULL);
+                       pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags & (pic->hasalpha ? ~0 : ~TEXF_ALPHA), -1, NULL);
        }
        else
        {
@@ -521,7 +542,7 @@ cachepic_t *Draw_NewPic(const char *picname, int width, int height, int alpha, u
        pic->height = height;
        if (pic->tex)
                R_FreeTexture(pic->tex);
-       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0) | TEXF_ALLOWUPDATES, -1, NULL);
+       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0), -1, NULL);
        return pic;
 }
 
@@ -700,7 +721,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
 extern cvar_t developer_font;
 dp_font_t *FindFont(const char *title, qboolean allocate_new)
 {
-       int i;
+       int i, oldsize;
 
        // find font
        for(i = 0; i < dp_fonts.maxsize; ++i)
@@ -719,14 +740,18 @@ dp_font_t *FindFont(const char *title, qboolean allocate_new)
                        }
                }
                // if no any 'free' fonts - expand buffer
-               i = dp_fonts.maxsize;
+               oldsize = dp_fonts.maxsize;
                dp_fonts.maxsize = dp_fonts.maxsize + FONTS_EXPAND;
                if (developer_font.integer)
-                       Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", i, dp_fonts.maxsize);
+                       Con_Printf("FindFont: enlarging fonts buffer (%i -> %i)\n", oldsize, dp_fonts.maxsize);
                dp_fonts.f = (dp_font_t *)Mem_Realloc(fonts_mempool, dp_fonts.f, sizeof(dp_font_t) * dp_fonts.maxsize);
+               // relink ft2 structures
+               for(i = 0; i < oldsize; ++i)
+                       if (dp_fonts.f[i].ft2)
+                               dp_fonts.f[i].ft2->settings = &dp_fonts.f[i].settings;
                // register a font in first expanded slot
-               strlcpy(dp_fonts.f[i].title, title, sizeof(dp_fonts.f[i].title));
-               return &dp_fonts.f[i];
+               strlcpy(dp_fonts.f[oldsize].title, title, sizeof(dp_fonts.f[oldsize].title));
+               return &dp_fonts.f[oldsize];
        }
        return NULL;
 }
@@ -873,10 +898,28 @@ static void LoadFont_f(void)
                                        voffset = atof(Cmd_Argv(i));
                                continue;
                        }
+
+                       if (sizes == -1)
+                               continue; // no slot for other sizes
+
                        // parse one of sizes
                        sz = atof(Cmd_Argv(i));
                        if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
                        {
+                               // search for duplicated sizes
+                               int j;
+                               for (j=0; j<sizes; j++)
+                                       if (f->req_sizes[j] == sz)
+                                               break;
+                               if (j != sizes)
+                                       continue; // sz already in req_sizes, don't add it again
+
+                               if (sizes == MAX_FONT_SIZES)
+                               {
+                                       Con_Printf("Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES);
+                                       sizes = -1;
+                                       continue;
+                               }
                                f->req_sizes[sizes] = sz;
                                sizes++;
                        }
@@ -964,12 +1007,12 @@ void GL_Draw_Init (void)
        R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap, NULL, NULL);
 }
 
-void _DrawQ_Setup(void)
+static void _DrawQ_Setup(void)
 {
        r_viewport_t viewport;
-       if (r_refdef.draw2dstage)
+       if (r_refdef.draw2dstage == 1)
                return;
-       r_refdef.draw2dstage = true;
+       r_refdef.draw2dstage = 1;
        CHECKGLERROR
        R_Viewport_InitOrtho(&viewport, &identitymatrix, r_refdef.view.x, vid.height - r_refdef.view.y - r_refdef.view.height, r_refdef.view.width, r_refdef.view.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
        R_SetViewport(&viewport);
@@ -979,43 +1022,65 @@ void _DrawQ_Setup(void)
        GL_CullFace(GL_NONE);
        R_EntityMatrix(&identitymatrix);
 
-       GL_DepthMask(true);
        GL_DepthRange(0, 1);
        GL_PolygonOffset(0, 0);
        GL_DepthTest(false);
        GL_Color(1,1,1,1);
        GL_AlphaTest(false);
-       GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 }
 
 qboolean r_draw2d_force = false;
-static void _DrawQ_ProcessDrawFlag(int flags)
+void _DrawQ_SetupAndProcessDrawFlag(int flags, cachepic_t *pic, float alpha)
 {
        _DrawQ_Setup();
        CHECKGLERROR
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
+       DrawQ_ProcessDrawFlag(flags, (alpha < 1) || (pic && pic->hasalpha));
+}
+void DrawQ_ProcessDrawFlag(int flags, qboolean alpha)
+{
        if(flags == DRAWFLAG_ADDITIVE)
-               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
+       {
+               GL_DepthMask(false);
+               GL_BlendFunc(alpha ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
+       }
        else if(flags == DRAWFLAG_MODULATE)
+       {
+               GL_DepthMask(false);
                GL_BlendFunc(GL_DST_COLOR, GL_ZERO);
+       }
        else if(flags == DRAWFLAG_2XMODULATE)
-               GL_BlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
+       {
+               GL_DepthMask(false);
+               GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
+       }
        else if(flags == DRAWFLAG_SCREEN)
-               GL_BlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
-       else
+       {
+               GL_DepthMask(false);
+               GL_BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
+       }
+       else if(alpha)
+       {
+               GL_DepthMask(false);
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
+       else
+       {
+               GL_DepthMask(true);
+               GL_BlendFunc(GL_ONE, GL_ZERO);
+       }
 }
 
 void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, float red, float green, float blue, float alpha, int flags)
 {
        float floats[36];
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        floats[12] = 0.0f;floats[13] = 0.0f;
        floats[14] = 1.0f;floats[15] = 0.0f;
        floats[16] = 1.0f;floats[17] = 1.0f;
@@ -1068,11 +1133,11 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
        float sinar = sin(ar);
        float cosar = cos(ar);
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        if (pic)
        {
                if (width == 0)
@@ -1119,11 +1184,11 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
 {
        float floats[36];
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, NULL, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
 
        floats[2] = floats[5] = floats[8] = floats[11] = 0;
@@ -1383,13 +1448,13 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
        return x;
 }
 
+float DrawQ_Color[4];
 float DrawQ_String_Scale(float startx, float starty, const char *text, size_t maxlen, float w, float h, float sw, float sh, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt)
 {
        int shadow, colorindex = STRING_COLOR_DEFAULT;
        size_t i;
        float x = startx, y, s, t, u, v, thisw;
        float *av, *at, *ac;
-       float color[4];
        int batchcount;
        static float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
        static float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
@@ -1444,11 +1509,11 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
        if (maxlen < 1)
                maxlen = 1<<30;
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, NULL, 0);
        if(!r_draw2d.integer && !r_draw2d_force)
                return startx + DrawQ_TextWidth_UntilWidth_TrackColors_Scale(text, &maxlen, w, h, sw, sh, NULL, ignorecolorcodes, fnt, 1000000000);
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        if (!fontmap)
                R_Mesh_TexBind(0, fnt->tex);
        R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1);
@@ -1484,7 +1549,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                else
                        colorindex = *outcolor;
 
-               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
 
                x = startx;
                y = starty;
@@ -1512,7 +1577,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                if (ch <= '9' && ch >= '0') // ^[0-9] found
                                {
                                        colorindex = ch - '0';
-                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+                                       DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                        ++text;
                                        ++i;
                                        continue;
@@ -1542,7 +1607,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                                                colorindex = tempcolorindex | 0xf;
                                                                // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
                                                                //Con_Printf("^1colorindex:^7 %x\n", colorindex);
-                                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+                                                               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                                                i+=4;
                                                                text+=4;
                                                                continue;
@@ -1569,10 +1634,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                        }
                        if (!fontmap || (ch <= 0xFF && fontmap->glyphs[ch].image) || (ch >= 0xE000 && ch <= 0xE0FF))
                        {
-                               if (ch > 0xE000)
+                               if (ch >= 0xE000)
                                        ch -= 0xE000;
                                if (ch > 0xFF)
-                                       continue;
+                                       goto out;
                                if (fontmap)
                                {
                                        if (map != ft2_oldstyle_map)
@@ -1600,10 +1665,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                t = (ch >> 4)*0.0625f + (0.5f / th);
                                u = 0.0625f * thisw - (1.0f / tw);
                                v = 0.0625f - (1.0f / th);
-                               ac[ 0] = color[0];ac[ 1] = color[1];ac[ 2] = color[2];ac[ 3] = color[3];
-                               ac[ 4] = color[0];ac[ 5] = color[1];ac[ 6] = color[2];ac[ 7] = color[3];
-                               ac[ 8] = color[0];ac[ 9] = color[1];ac[10] = color[2];ac[11] = color[3];
-                               ac[12] = color[0];ac[13] = color[1];ac[14] = color[2];ac[15] = color[3];
+                               ac[ 0] = DrawQ_Color[0];ac[ 1] = DrawQ_Color[1];ac[ 2] = DrawQ_Color[2];ac[ 3] = DrawQ_Color[3];
+                               ac[ 4] = DrawQ_Color[0];ac[ 5] = DrawQ_Color[1];ac[ 6] = DrawQ_Color[2];ac[ 7] = DrawQ_Color[3];
+                               ac[ 8] = DrawQ_Color[0];ac[ 9] = DrawQ_Color[1];ac[10] = DrawQ_Color[2];ac[11] = DrawQ_Color[3];
+                               ac[12] = DrawQ_Color[0];ac[13] = DrawQ_Color[1];ac[14] = DrawQ_Color[2];ac[15] = DrawQ_Color[3];
                                at[ 0] = s              ; at[ 1] = t    ;
                                at[ 2] = s+u    ; at[ 3] = t    ;
                                at[ 4] = s+u    ; at[ 5] = t+v  ;
@@ -1671,10 +1736,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                }
                                else
                                        kx = ky = 0;
-                               ac[ 0] = color[0]; ac[ 1] = color[1]; ac[ 2] = color[2]; ac[ 3] = color[3];
-                               ac[ 4] = color[0]; ac[ 5] = color[1]; ac[ 6] = color[2]; ac[ 7] = color[3];
-                               ac[ 8] = color[0]; ac[ 9] = color[1]; ac[10] = color[2]; ac[11] = color[3];
-                               ac[12] = color[0]; ac[13] = color[1]; ac[14] = color[2]; ac[15] = color[3];
+                               ac[ 0] = DrawQ_Color[0]; ac[ 1] = DrawQ_Color[1]; ac[ 2] = DrawQ_Color[2]; ac[ 3] = DrawQ_Color[3];
+                               ac[ 4] = DrawQ_Color[0]; ac[ 5] = DrawQ_Color[1]; ac[ 6] = DrawQ_Color[2]; ac[ 7] = DrawQ_Color[3];
+                               ac[ 8] = DrawQ_Color[0]; ac[ 9] = DrawQ_Color[1]; ac[10] = DrawQ_Color[2]; ac[11] = DrawQ_Color[3];
+                               ac[12] = DrawQ_Color[0]; ac[13] = DrawQ_Color[1]; ac[14] = DrawQ_Color[2]; ac[15] = DrawQ_Color[3];
                                at[0] = map->glyphs[mapch].txmin; at[1] = map->glyphs[mapch].tymin;
                                at[2] = map->glyphs[mapch].txmax; at[3] = map->glyphs[mapch].tymin;
                                at[4] = map->glyphs[mapch].txmax; at[5] = map->glyphs[mapch].tymax;
@@ -1704,6 +1769,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                //prevmap = map;
                                prevch = ch;
                        }
+out:
                        if (shadow)
                        {
                                x -= 1.0/pix_x * r_textshadow.value;
@@ -1719,7 +1785,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
 
        if (outcolor)
                *outcolor = colorindex;
-
+       
        // note: this relies on the proper text (not shadow) being drawn last
        return x;
 }
@@ -1788,11 +1854,11 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
 {
        float floats[36];
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, pic, a1*a2*a3*a4);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        if (pic)
        {
                if (width == 0)
@@ -1822,13 +1888,15 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
 }
 
-void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
+void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags, qboolean hasalpha)
 {
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_Setup();
+       CHECKGLERROR
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
+       DrawQ_ProcessDrawFlag(flags, hasalpha);
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1);
 
        R_Mesh_PrepareVertices_Generic_Arrays(mesh->num_vertices, mesh->data_vertex3f, mesh->data_color4f, mesh->data_texcoord2f);
@@ -1839,7 +1907,7 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
 {
        int num;
 
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, NULL, 1);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
@@ -1870,13 +1938,19 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
        case RENDERPATH_D3D11:
                Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
                break;
+       case RENDERPATH_SOFT:
+               //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_GLES2:
+               //Con_DPrintf("FIXME GLES2 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               return;
        }
 }
 
 //[515]: this is old, delete
 void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, float g, float b, float alpha, int flags)
 {
-       _DrawQ_ProcessDrawFlag(flags);
+       _DrawQ_SetupAndProcessDrawFlag(flags, NULL, alpha);
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
@@ -1909,6 +1983,60 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
        case RENDERPATH_D3D11:
                Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
                break;
+       case RENDERPATH_SOFT:
+               //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_GLES2:
+               //Con_DPrintf("FIXME GLES2 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               return;
+       }
+}
+
+void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float *color4f, int flags)
+{
+       int i;
+       qboolean hasalpha = false;
+       for (i = 0;i < numlines*2;i++)
+               if (color4f[i*4+3] < 1.0f)
+                       hasalpha = true;
+
+       _DrawQ_SetupAndProcessDrawFlag(flags, NULL, hasalpha ? 0.5f : 1.0f);
+
+       if(!r_draw2d.integer && !r_draw2d_force)
+               return;
+
+       switch(vid.renderpath)
+       {
+       case RENDERPATH_GL11:
+       case RENDERPATH_GL13:
+       case RENDERPATH_GL20:
+       case RENDERPATH_CGGL:
+               CHECKGLERROR
+
+               R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
+
+               //qglLineWidth(width);CHECKGLERROR
+
+               CHECKGLERROR
+               R_Mesh_PrepareVertices_Generic_Arrays(numlines*2, vertex3f, color4f, NULL);
+               qglDrawArrays(GL_LINES, 0, numlines*2);
+               CHECKGLERROR
+               break;
+       case RENDERPATH_D3D9:
+               //Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_D3D10:
+               Con_DPrintf("FIXME D3D10 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_D3D11:
+               Con_DPrintf("FIXME D3D11 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_SOFT:
+               //Con_DPrintf("FIXME SOFT %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               break;
+       case RENDERPATH_GLES2:
+               //Con_DPrintf("FIXME GLES2 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
+               return;
        }
 }
 
@@ -1936,7 +2064,13 @@ void DrawQ_ResetClipArea(void)
 
 void DrawQ_Finish(void)
 {
-       r_refdef.draw2dstage = false;
+       r_refdef.draw2dstage = 0;
+}
+
+void DrawQ_RecalcView(void)
+{
+       if(r_refdef.draw2dstage)
+               r_refdef.draw2dstage = -1; // next draw call will set viewport etc. again
 }
 
 static float blendvertex3f[9] = {-5000, -5000, 10, 10000, -5000, 10, -5000, 10000, 10};
@@ -1950,6 +2084,7 @@ void R_DrawGamma(void)
        case RENDERPATH_D3D9:
        case RENDERPATH_D3D10:
        case RENDERPATH_D3D11:
+       case RENDERPATH_GLES2:
                if (vid_usinghwgamma || v_glslgamma.integer)
                        return;
                break;
@@ -1958,9 +2093,11 @@ void R_DrawGamma(void)
                if (vid_usinghwgamma)
                        return;
                break;
+       case RENDERPATH_SOFT:
+               return;
        }
        // all the blends ignore depth
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
        GL_DepthMask(true);
        GL_DepthRange(0, 1);