]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - dpsoftrast.c
Add an in_releaseall command for debugging/working around stuck keys.
[xonotic/darkplaces.git] / dpsoftrast.c
index b57129c1c9d1fac110198bc5d5e48444e9baa475..d9c72720449bd3a245da6397b5b873cb0c0da729 100644 (file)
@@ -257,7 +257,7 @@ typedef ALIGN(struct DPSOFTRAST_State_Thread_s
        ALIGN(float fb_clipplane[4]);
 
        int shader_mode;
-       int shader_permutation;
+       dpuint64 shader_permutation;
        int shader_exactspecularmath;
 
        DPSOFTRAST_Texture *texbound[DPSOFTRAST_MAXTEXTUREUNITS];
@@ -336,7 +336,7 @@ typedef ALIGN(struct DPSOFTRAST_State_s
        int drawclipped;
        
        int shader_mode;
-       int shader_permutation;
+       dpuint64 shader_permutation;
        int shader_exactspecularmath;
 
        int texture_max;
@@ -617,9 +617,6 @@ int DPSOFTRAST_Texture_New(int flags, int width, int height, int depth)
        d = depth;
        size = 0;
        mipmaps = 0;
-       w = width;
-       h = height;
-       d = depth;
        for (;;)
        {
                s = w * h * d * sides * 4;
@@ -1321,35 +1318,35 @@ void DPSOFTRAST_SetTexture(int unitnum, int index)
 void DPSOFTRAST_SetVertexPointer(const float *vertex3f, size_t stride)
 {
        dpsoftrast.pointer_vertex3f = vertex3f;
-       dpsoftrast.stride_vertex = stride;
+       dpsoftrast.stride_vertex = (int)stride;
 }
 void DPSOFTRAST_SetColorPointer(const float *color4f, size_t stride)
 {
        dpsoftrast.pointer_color4f = color4f;
        dpsoftrast.pointer_color4ub = NULL;
-       dpsoftrast.stride_color = stride;
+       dpsoftrast.stride_color = (int)stride;
 }
 void DPSOFTRAST_SetColorPointer4ub(const unsigned char *color4ub, size_t stride)
 {
        dpsoftrast.pointer_color4f = NULL;
        dpsoftrast.pointer_color4ub = color4ub;
-       dpsoftrast.stride_color = stride;
+       dpsoftrast.stride_color = (int)stride;
 }
 void DPSOFTRAST_SetTexCoordPointer(int unitnum, int numcomponents, size_t stride, const float *texcoordf)
 {
        dpsoftrast.pointer_texcoordf[unitnum] = texcoordf;
        dpsoftrast.components_texcoord[unitnum] = numcomponents;
-       dpsoftrast.stride_texcoord[unitnum] = stride;
+       dpsoftrast.stride_texcoord[unitnum] = (int)stride;
 }
 
-DEFCOMMAND(18, SetShader, int mode; int permutation; int exactspecularmath;)
+DEFCOMMAND(18, SetShader, int mode; dpuint64 permutation; int exactspecularmath;)
 static void DPSOFTRAST_Interpret_SetShader(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_Command_SetShader *command)
 {
        thread->shader_mode = command->mode;
        thread->shader_permutation = command->permutation;
        thread->shader_exactspecularmath = command->exactspecularmath;
 }
-void DPSOFTRAST_SetShader(int mode, int permutation, int exactspecularmath)
+void DPSOFTRAST_SetShader(int mode, dpuint64 permutation, int exactspecularmath)
 {
        DPSOFTRAST_Command_SetShader *command = DPSOFTRAST_ALLOCATECOMMAND(SetShader);
        command->mode = mode;
@@ -1667,10 +1664,10 @@ static void DPSOFTRAST_Fill4f(float *dst, const float *src, int size)
 static void DPSOFTRAST_Vertex_Transform(float *out4f, const float *in4f, int numitems, const float *inmatrix16f)
 {
 #ifdef SSE_POSSIBLE
-       static const float identitymatrix[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
+       static const float identitymatrix16f[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
        __m128 m0, m1, m2, m3;
        float *end;
-       if (!memcmp(identitymatrix, inmatrix16f, sizeof(float[16])))
+       if (!memcmp(identitymatrix16f, inmatrix16f, sizeof(float[16])))
        {
                // fast case for identity matrix
                if (out4f != in4f) memcpy(out4f, in4f, numitems * sizeof(float[4]));
@@ -1728,14 +1725,6 @@ static void DPSOFTRAST_Vertex_Copy(float *out4f, const float *in4f, int numitems
        out = _mm_shuffle_ps(p, p, _MM_SHUFFLE(0, 3, 2, 1)); \
 }
 
-#define DPSOFTRAST_PROJECTY(out, in, viewportcenter, viewportscale) \
-{ \
-       __m128 p = (in), w = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3, 3, 3, 3)); \
-       p = _mm_move_ss(_mm_shuffle_ps(p, p, _MM_SHUFFLE(2, 1, 0, 3)), _mm_set_ss(1.0f)); \
-       p = _mm_add_ps(viewportcenter, _mm_div_ps(_mm_mul_ps(viewportscale, p), w)); \
-       out = _mm_shuffle_ps(p, p, _MM_SHUFFLE(0, 3, 2, 1)); \
-}
-
 #define DPSOFTRAST_TRANSFORMVERTEX(out, in, m0, m1, m2, m3) \
 { \
        __m128 p = (in); \
@@ -1821,7 +1810,7 @@ static int DPSOFTRAST_Vertex_BoundY(int *starty, int *endy, const float *minposf
        
 static int DPSOFTRAST_Vertex_Project(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems)
 {
-       static const float identitymatrix[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
+       static const float identitymatrix16f[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
        float *end = out4f + numitems*4;
        __m128 viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter), viewportscale = _mm_load_ps(dpsoftrast.fb_viewportscale);
        __m128 minpos, maxpos;
@@ -1863,17 +1852,17 @@ static int DPSOFTRAST_Vertex_Project(float *out4f, float *screen4f, int *starty,
                ALIGN(float maxposf[4]);
                _mm_store_ps(minposf, minpos);
                _mm_store_ps(maxposf, maxpos);
-               return DPSOFTRAST_Vertex_BoundY(starty, endy, minposf, maxposf, identitymatrix);
+               return DPSOFTRAST_Vertex_BoundY(starty, endy, minposf, maxposf, identitymatrix16f);
        }
        return 0;
 }
 
 static int DPSOFTRAST_Vertex_TransformProject(float *out4f, float *screen4f, int *starty, int *endy, const float *in4f, int numitems, const float *inmatrix16f)
 {
-       static const float identitymatrix[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
+       static const float identitymatrix16f[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
        __m128 m0, m1, m2, m3, viewportcenter, viewportscale, minpos, maxpos;
        float *end;
-       if (!memcmp(identitymatrix, inmatrix16f, sizeof(float[16])))
+       if (!memcmp(identitymatrix16f, inmatrix16f, sizeof(float[16])))
                return DPSOFTRAST_Vertex_Project(out4f, screen4f, starty, endy, in4f, numitems);
        end = out4f + numitems*4;
        viewportcenter = _mm_load_ps(dpsoftrast.fb_viewportcenter);
@@ -2055,11 +2044,9 @@ static void DPSOFTRAST_Draw_Span_FinishBGRA8(DPSOFTRAST_State_Thread *thread, co
        int subx;
        const unsigned int * RESTRICT ini = (const unsigned int *)in4ub;
        unsigned char * RESTRICT pixelmask = span->pixelmask;
-       unsigned char * RESTRICT pixel = (unsigned char *)dpsoftrast.fb_colorpixels[0];
        unsigned int * RESTRICT pixeli = (unsigned int *)dpsoftrast.fb_colorpixels[0];
-       if (!pixel)
+       if (!pixeli)
                return;
-       pixel += (span->y * dpsoftrast.fb_width + span->x) * 4;
        pixeli += span->y * dpsoftrast.fb_width + span->x;
        // handle alphatest now (this affects depth writes too)
        if (thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL)
@@ -2307,12 +2294,12 @@ static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, floa
        pixelbase = (unsigned char *)texture->bytes + texture->mipmap[mip][0] + texture->mipmap[mip][1] - 4*width;
        if(texture->filter & DPSOFTRAST_TEXTURE_FILTER_LINEAR)
        {
-               unsigned int tc[2] = { x * (width<<12) - 2048, y * (height<<12) - 2048};
+               unsigned int tc[2] = { (unsigned int)floor(x) * (width<<12) - 2048, (unsigned int)floor(y) * (height<<12) - 2048};
                unsigned int frac[2] = { tc[0]&0xFFF, tc[1]&0xFFF };
                unsigned int ifrac[2] = { 0x1000 - frac[0], 0x1000 - frac[1] };
                unsigned int lerp[4] = { ifrac[0]*ifrac[1], frac[0]*ifrac[1], ifrac[0]*frac[1], frac[0]*frac[1] };
-               int tci[2] = { tc[0]>>12, tc[1]>>12 };
-               int tci1[2] = { tci[0] + 1, tci[1] + 1 };
+               int tci[2] = { (int)tc[0]>>12, (int)tc[1]>>12 };
+               int tci1[2] = { (int)tci[0] + 1, (int)tci[1] + 1 };
                if (texture->flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
                {
                        tci[0] = tci[0] >= 0 ? (tci[0] <= wrapmask[0] ? tci[0] : wrapmask[0]) : 0;
@@ -2338,7 +2325,7 @@ static void DPSOFTRAST_Texture2DBGRA8(DPSOFTRAST_Texture *texture, int mip, floa
        }
        else
        {
-               int tci[2] = { x * width, y * height };
+               int tci[2] = { (int)floor(x) * width, (int)floor(y) * height };
                if (texture->flags & DPSOFTRAST_TEXTURE_FLAG_CLAMPTOEDGE)
                {
                        tci[0] = tci[0] >= 0 ? (tci[0] <= wrapmask[0] ? tci[0] : wrapmask[0]) : 0;
@@ -3263,6 +3250,12 @@ static void DPSOFTRAST_PixelShader_Generic(DPSOFTRAST_State_Thread *thread, cons
        }
        else
                DPSOFTRAST_Draw_Span_VaryingBGRA8(triangle, span, buffer_FragColorbgra8, 1, buffer_z);
+       if(thread->shader_permutation & SHADERPERMUTATION_ALPHAKILL)
+       {
+               int x;
+               for (x = span->startx;x < span->endx;x++)
+                       buffer_FragColorbgra8[x*4+3] = buffer_FragColorbgra8[x*4+3] * thread->uniform4f[DPSOFTRAST_UNIFORM_Alpha*4+0];
+       }
        DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
 }
 
@@ -4046,7 +4039,7 @@ void DPSOFTRAST_PixelShader_LightDirection(DPSOFTRAST_State_Thread *thread, cons
        {
                for (x = startx;x < endx;x++)
                {
-                       z = buffer_z[x];
+                       // z = buffer_z[x];
                        diffusetex[0] = buffer_texture_colorbgra8[x*4+0];
                        diffusetex[1] = buffer_texture_colorbgra8[x*4+1];
                        diffusetex[2] = buffer_texture_colorbgra8[x*4+2];
@@ -4156,7 +4149,7 @@ static void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread,
        unsigned char buffer_texture_shirtbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
        unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
        int x, startx = span->startx, endx = span->endx;
-       float Color_Ambient[4], Color_Diffuse[4], Color_Specular[4], Color_Glow[4], Color_Pants[4], Color_Shirt[4], LightColor[4];
+       float Color_Ambient[4], Color_Diffuse[4], Color_Specular[4], /*Color_Glow[4],*/ Color_Pants[4], Color_Shirt[4], LightColor[4];
        float CubeVectordata[4];
        float CubeVectorslope[4];
        float LightVectordata[4];
@@ -4176,10 +4169,12 @@ static void DPSOFTRAST_PixelShader_LightSource(DPSOFTRAST_State_Thread *thread,
        float CubeVector[4];
        float attenuation;
        int d[4];
+#if 0
        Color_Glow[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+0];
        Color_Glow[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+1];
        Color_Glow[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Glow*4+2];
        Color_Glow[3] = 0.0f;
+#endif
        Color_Ambient[2] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+0];
        Color_Ambient[1] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+1];
        Color_Ambient[0] = thread->uniform4f[DPSOFTRAST_UNIFORM_Color_Ambient*4+2];
@@ -4451,7 +4446,7 @@ static void DPSOFTRAST_VertexShader_Refraction(void)
 static void DPSOFTRAST_PixelShader_Refraction(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
 {
        float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
-       float z;
+       //float z;
        int x, startx = span->startx, endx = span->endx;
 
        // texture reads
@@ -4499,7 +4494,7 @@ static void DPSOFTRAST_PixelShader_Refraction(DPSOFTRAST_State_Thread *thread, c
                float iw;
                unsigned char c[4];
 
-               z = buffer_z[x];
+               //z = buffer_z[x];
 
                // "    vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
                iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z
@@ -4583,7 +4578,7 @@ static void DPSOFTRAST_VertexShader_Water(void)
 static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
 {
        float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
-       float z;
+       // float z;
        int x, startx = span->startx, endx = span->endx;
 
        // texture reads
@@ -4652,7 +4647,7 @@ static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const
                unsigned char c2[4];
                float Fresnel;
 
-               z = buffer_z[x];
+               // z = buffer_z[x];
 
                // "    vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
                iw = 1.0f / (ModelViewProjectionPositiondata[3] + ModelViewProjectionPositionslope[3]*x); // / z
@@ -4698,23 +4693,6 @@ static void DPSOFTRAST_PixelShader_Water(DPSOFTRAST_State_Thread *thread, const
 
 
 
-static void DPSOFTRAST_VertexShader_ShowDepth(void)
-{
-       DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
-}
-
-static void DPSOFTRAST_PixelShader_ShowDepth(DPSOFTRAST_State_Thread *thread, const DPSOFTRAST_State_Triangle * RESTRICT triangle, const DPSOFTRAST_State_Span * RESTRICT span)
-{
-       // TODO: IMPLEMENT
-       float buffer_z[DPSOFTRAST_DRAW_MAXSPANLENGTH];
-       unsigned char buffer_FragColorbgra8[DPSOFTRAST_DRAW_MAXSPANLENGTH*4];
-       DPSOFTRAST_Draw_Span_Begin(thread, triangle, span, buffer_z);
-       memset(buffer_FragColorbgra8 + span->startx*4, 0, (span->endx - span->startx)*4);
-       DPSOFTRAST_Draw_Span_FinishBGRA8(thread, triangle, span, buffer_FragColorbgra8);
-}
-
-
-
 static void DPSOFTRAST_VertexShader_DeferredGeometry(void)
 {
        DPSOFTRAST_Array_TransformProject(DPSOFTRAST_ARRAY_POSITION, DPSOFTRAST_ARRAY_POSITION, dpsoftrast.uniform4f + 4*DPSOFTRAST_UNIFORM_ModelViewProjectionMatrixM1);
@@ -4761,24 +4739,23 @@ DPSOFTRAST_ShaderModeInfo;
 
 static const DPSOFTRAST_ShaderModeInfo DPSOFTRAST_ShaderModeTable[SHADERMODE_COUNT] =
 {
-       {2, DPSOFTRAST_VertexShader_Generic,                        DPSOFTRAST_PixelShader_Generic,                        {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, ~0}, {GL20TU_FIRST, GL20TU_SECOND, ~0}},
-       {2, DPSOFTRAST_VertexShader_PostProcess,                    DPSOFTRAST_PixelShader_PostProcess,                    {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, ~0}, {GL20TU_FIRST, GL20TU_SECOND, ~0}},
-       {2, DPSOFTRAST_VertexShader_Depth_Or_Shadow,                DPSOFTRAST_PixelShader_Depth_Or_Shadow,                {~0}, {~0}},
-       {2, DPSOFTRAST_VertexShader_FlatColor,                      DPSOFTRAST_PixelShader_FlatColor,                      {DPSOFTRAST_ARRAY_TEXCOORD0, ~0}, {GL20TU_COLOR, ~0}},
-       {2, DPSOFTRAST_VertexShader_VertexColor,                    DPSOFTRAST_PixelShader_VertexColor,                    {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, ~0}, {GL20TU_COLOR, ~0}},
-       {2, DPSOFTRAST_VertexShader_Lightmap,                       DPSOFTRAST_PixelShader_Lightmap,                       {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, ~0}},
-       {2, DPSOFTRAST_VertexShader_FakeLight,                      DPSOFTRAST_PixelShader_FakeLight,                      {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, ~0}},
-       {2, DPSOFTRAST_VertexShader_LightDirectionMap_ModelSpace,   DPSOFTRAST_PixelShader_LightDirectionMap_ModelSpace,   {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, ~0}},
-       {2, DPSOFTRAST_VertexShader_LightDirectionMap_TangentSpace, DPSOFTRAST_PixelShader_LightDirectionMap_TangentSpace, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, ~0}},
-       {2, DPSOFTRAST_VertexShader_Lightmap,                       DPSOFTRAST_PixelShader_Lightmap,                       {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, ~0}},
-       {2, DPSOFTRAST_VertexShader_VertexColor,                        DPSOFTRAST_PixelShader_VertexColor,                    {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, ~0}, {GL20TU_COLOR, ~0}},
-       {2, DPSOFTRAST_VertexShader_LightDirection,                 DPSOFTRAST_PixelShader_LightDirection,                 {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, ~0}},
-       {2, DPSOFTRAST_VertexShader_LightSource,                    DPSOFTRAST_PixelShader_LightSource,                    {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_CUBE, ~0}},
-       {2, DPSOFTRAST_VertexShader_Refraction,                     DPSOFTRAST_PixelShader_Refraction,                     {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, ~0}, {GL20TU_NORMAL, GL20TU_REFRACTION, ~0}},
-       {2, DPSOFTRAST_VertexShader_Water,                          DPSOFTRAST_PixelShader_Water,                          {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD6, ~0}, {GL20TU_NORMAL, GL20TU_REFLECTION, GL20TU_REFRACTION, ~0}},
-       {2, DPSOFTRAST_VertexShader_ShowDepth,                      DPSOFTRAST_PixelShader_ShowDepth,                      {~0}},
-       {2, DPSOFTRAST_VertexShader_DeferredGeometry,               DPSOFTRAST_PixelShader_DeferredGeometry,               {~0}},
-       {2, DPSOFTRAST_VertexShader_DeferredLightSource,            DPSOFTRAST_PixelShader_DeferredLightSource,            {~0}},
+       {2, DPSOFTRAST_VertexShader_Generic,                        DPSOFTRAST_PixelShader_Generic,                        {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, 0xFF}, {GL20TU_FIRST, GL20TU_SECOND, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_PostProcess,                    DPSOFTRAST_PixelShader_PostProcess,                    {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, 0xFF}, {GL20TU_FIRST, GL20TU_SECOND, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_Depth_Or_Shadow,                DPSOFTRAST_PixelShader_Depth_Or_Shadow,                {0xFF}, {0xFF}},
+       {2, DPSOFTRAST_VertexShader_FlatColor,                      DPSOFTRAST_PixelShader_FlatColor,                      {DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_VertexColor,                    DPSOFTRAST_PixelShader_VertexColor,                    {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_Lightmap,                       DPSOFTRAST_PixelShader_Lightmap,                       {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_FakeLight,                      DPSOFTRAST_PixelShader_FakeLight,                      {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_LightDirectionMap_ModelSpace,   DPSOFTRAST_PixelShader_LightDirectionMap_ModelSpace,   {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_LightDirectionMap_TangentSpace, DPSOFTRAST_PixelShader_LightDirectionMap_TangentSpace, {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_LIGHTMAP, GL20TU_DELUXEMAP, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_Lightmap,                       DPSOFTRAST_PixelShader_Lightmap,                       {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_LIGHTMAP, GL20TU_GLOW, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_VertexColor,                        DPSOFTRAST_PixelShader_VertexColor,                    {DPSOFTRAST_ARRAY_COLOR, DPSOFTRAST_ARRAY_TEXCOORD0, 0xFF}, {GL20TU_COLOR, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_LightDirection,                 DPSOFTRAST_PixelShader_LightDirection,                 {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD5, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_LightSource,                    DPSOFTRAST_PixelShader_LightSource,                    {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_COLOR, GL20TU_PANTS, GL20TU_SHIRT, GL20TU_GLOW, GL20TU_NORMAL, GL20TU_GLOSS, GL20TU_CUBE, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_Refraction,                     DPSOFTRAST_PixelShader_Refraction,                     {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD4, 0xFF}, {GL20TU_NORMAL, GL20TU_REFRACTION, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_Water,                          DPSOFTRAST_PixelShader_Water,                          {DPSOFTRAST_ARRAY_TEXCOORD0, DPSOFTRAST_ARRAY_TEXCOORD1, DPSOFTRAST_ARRAY_TEXCOORD2, DPSOFTRAST_ARRAY_TEXCOORD3, DPSOFTRAST_ARRAY_TEXCOORD4, DPSOFTRAST_ARRAY_TEXCOORD6, 0xFF}, {GL20TU_NORMAL, GL20TU_REFLECTION, GL20TU_REFRACTION, 0xFF}},
+       {2, DPSOFTRAST_VertexShader_DeferredGeometry,               DPSOFTRAST_PixelShader_DeferredGeometry,               {0xFF}},
+       {2, DPSOFTRAST_VertexShader_DeferredLightSource,            DPSOFTRAST_PixelShader_DeferredLightSource,            {0xFF}},
 };
 
 static void DPSOFTRAST_Draw_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAST_State_Span *span)
@@ -4791,8 +4768,6 @@ static void DPSOFTRAST_Draw_DepthTest(DPSOFTRAST_State_Thread *thread, DPSOFTRAS
        int depthslope;
        unsigned int d;
        unsigned char *pixelmask;
-       DPSOFTRAST_State_Triangle *triangle;
-       triangle = &thread->triangles[span->triangle];
        depthpixel = dpsoftrast.fb_depthpixels + span->y * dpsoftrast.fb_width + span->x;
        startx = span->startx;
        endx = span->endx;