]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
don't crash on NULL texture upload in dpsoftrast
[xonotic/darkplaces.git] / gl_draw.c
index 55bb59d9f14a9f9a85946d84e93e88023072d3fe..50fcb81e35adfd2608e77379e85e270ec7746cbf 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -516,7 +516,7 @@ cachepic_t *Draw_NewPic(const char *picname, int width, int height, int alpha, u
        {
                if (pic->tex && pic->width == width && pic->height == height)
                {
-                       R_UpdateTexture(pic->tex, pixels_bgra, 0, 0, width, height);
+                       R_UpdateTexture(pic->tex, pixels_bgra, 0, 0, 0, width, height, 1);
                        return pic;
                }
        }
@@ -1015,6 +1015,7 @@ static void _DrawQ_Setup(void)
        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_Mesh_ResetRenderTargets();
        R_SetViewport(&viewport);
        GL_ColorMask(r_refdef.view.colormask[0], r_refdef.view.colormask[1], r_refdef.view.colormask[2], 1);
        GL_DepthFunc(GL_LEQUAL);
@@ -1026,7 +1027,6 @@ static void _DrawQ_Setup(void)
        GL_PolygonOffset(0, 0);
        GL_DepthTest(false);
        GL_Color(1,1,1,1);
-       GL_AlphaTest(false);
 }
 
 qboolean r_draw2d_force = false;
@@ -1080,7 +1080,7 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
        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;
@@ -1137,7 +1137,7 @@ void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height,
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        if (pic)
        {
                if (width == 0)
@@ -1188,7 +1188,7 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
        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;
@@ -1448,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];
@@ -1513,7 +1513,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
        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);
@@ -1549,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;
@@ -1577,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;
@@ -1607,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;
@@ -1665,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  ;
@@ -1736,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;
@@ -1785,7 +1785,7 @@ out:
 
        if (outcolor)
                *outcolor = colorindex;
-
+       
        // note: this relies on the proper text (not shadow) being drawn last
        return x;
 }
@@ -1858,7 +1858,7 @@ void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        if (pic)
        {
                if (width == 0)
@@ -1896,7 +1896,7 @@ void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags, qboolean hasalpha)
                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);
@@ -1917,7 +1917,6 @@ void DrawQ_LineLoop (drawqueuemesh_t *mesh, int flags)
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
        case RENDERPATH_GL20:
-       case RENDERPATH_CGGL:
                CHECKGLERROR
                qglBegin(GL_LINE_LOOP);
                for (num = 0;num < mesh->num_vertices;num++)
@@ -1938,6 +1937,12 @@ 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;
        }
 }
 
@@ -1955,7 +1960,6 @@ void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, f
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
        case RENDERPATH_GL20:
-       case RENDERPATH_CGGL:
                CHECKGLERROR
 
                //qglLineWidth(width);CHECKGLERROR
@@ -1977,6 +1981,12 @@ 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;
        }
 }
 
@@ -1989,6 +1999,7 @@ void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float
                        hasalpha = true;
 
        _DrawQ_SetupAndProcessDrawFlag(flags, NULL, hasalpha ? 0.5f : 1.0f);
+
        if(!r_draw2d.integer && !r_draw2d_force)
                return;
 
@@ -1997,7 +2008,6 @@ void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float
        case RENDERPATH_GL11:
        case RENDERPATH_GL13:
        case RENDERPATH_GL20:
-       case RENDERPATH_CGGL:
                CHECKGLERROR
 
                R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
@@ -2018,6 +2028,12 @@ void DrawQ_Lines (float width, int numlines, const float *vertex3f, const float
        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;
        }
 }
 
@@ -2032,7 +2048,25 @@ void DrawQ_SetClipArea(float x, float y, float width, float height)
        iy = (int)(0.5 + y * ((float) vid.height / vid_conheight.integer));
        iw = (int)(0.5 + (x+width) * ((float)vid.width / vid_conwidth.integer)) - ix;
        ih = (int)(0.5 + (y+height) * ((float) vid.height / vid_conheight.integer)) - iy;
-       GL_Scissor(ix, vid.height - iy - ih, iw, ih);
+       switch(vid.renderpath)
+       {
+       case RENDERPATH_GL11:
+       case RENDERPATH_GL13:
+       case RENDERPATH_GL20:
+       case RENDERPATH_GLES2:
+       case RENDERPATH_SOFT:
+               GL_Scissor(ix, vid.height - iy - ih, iw, ih);
+               break;
+       case RENDERPATH_D3D9:
+               GL_Scissor(ix, iy, iw, ih);
+               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;
+       }
 
        GL_ScissorTest(true);
 }
@@ -2061,10 +2095,10 @@ void R_DrawGamma(void)
        switch(vid.renderpath)
        {
        case RENDERPATH_GL20:
-       case RENDERPATH_CGGL:
        case RENDERPATH_D3D9:
        case RENDERPATH_D3D10:
        case RENDERPATH_D3D11:
+       case RENDERPATH_GLES2:
                if (vid_usinghwgamma || v_glslgamma.integer)
                        return;
                break;
@@ -2073,9 +2107,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);