]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_models.c
fixed models getting dark in the distance when fogged bug (thanks to Elric for report...
[xonotic/darkplaces.git] / gl_models.c
index 893d9a0b822f9406e6644bc99ced54cb999292b0..7edf394ecb7e80c20d99d5ad6ed945503ab2de78 100644 (file)
@@ -203,10 +203,13 @@ void R_AliasLerpVerts(int vertcount,
 skinframe_t *R_FetchSkinFrame(const entity_render_t *ent)
 {
        model_t *model = ent->model;
-       if (model->skinscenes[ent->skinnum].framecount > 1)
-               return &model->skinframes[model->skinscenes[ent->skinnum].firstframe + (int) (cl.time * 10) % model->skinscenes[ent->skinnum].framecount];
+       unsigned int s = (unsigned int) ent->skinnum;
+       if (s >= model->numskins)
+               s = 0;
+       if (model->skinscenes[s].framecount > 1)
+               return &model->skinframes[model->skinscenes[s].firstframe + (int) (cl.time * 10) % model->skinscenes[s].framecount];
        else
-               return &model->skinframes[model->skinscenes[ent->skinnum].firstframe];
+               return &model->skinframes[model->skinscenes[s].firstframe];
 }
 
 void R_SetupMDLMD2Frames(const entity_render_t *ent, float colorr, float colorg, float colorb)
@@ -236,7 +239,7 @@ void R_SetupMDLMD2Frames(const entity_render_t *ent, float colorr, float colorg,
 
 void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
 {
-       int c, pantsfullbright, shirtfullbright, colormapped;
+       int i, c, pantsfullbright, shirtfullbright, colormapped;
        float pantscolor[3], shirtcolor[3];
        float fog;
        vec3_t diff;
@@ -245,6 +248,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
        model_t *model;
        skinframe_t *skinframe;
        const entity_render_t *ent = calldata1;
+       int blendfunc1, blendfunc2;
 
 //     softwaretransformforentity(ent);
 
@@ -269,26 +273,59 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
 
        skinframe = R_FetchSkinFrame(ent);
 
+       if (ent->effects & EF_ADDITIVE)
+       {
+               blendfunc1 = GL_SRC_ALPHA;
+               blendfunc2 = GL_ONE;
+       }
+       else if (ent->alpha != 1.0 || skinframe->fog != NULL)
+       {
+               blendfunc1 = GL_SRC_ALPHA;
+               blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
+       }
+       else
+       {
+               blendfunc1 = GL_ONE;
+               blendfunc2 = GL_ZERO;
+       }
+
+       if (!skinframe->base && !skinframe->pants && !skinframe->shirt && !skinframe->glow)
+       {
+               // untextured
+               memset(&m, 0, sizeof(m));
+               m.blendfunc1 = blendfunc1;
+               m.blendfunc2 = blendfunc2;
+               m.numtriangles = model->numtris;
+               m.numverts = model->numverts;
+               m.tex[0] = R_GetTexture(r_notexture);
+               m.matrix = ent->matrix;
+
+               c_alias_polys += m.numtriangles;
+               if (R_Mesh_Draw_GetBuffer(&m, true))
+               {
+                       memcpy(m.index, model->mdlmd2data_indices, m.numtriangles * sizeof(int[3]));
+                       for (i = 0;i < m.numverts * 2;i++)
+                               m.texcoords[0][i] = model->mdlmd2data_texcoords[i] * 8.0f;
+
+                       aliasvert = m.vertex;
+                       aliasvertcolor = m.color;
+                       R_SetupMDLMD2Frames(ent, m.colorscale, m.colorscale, m.colorscale);
+                       aliasvert = aliasvertbuf;
+                       aliasvertcolor = aliasvertcolorbuf;
+
+                       R_Mesh_Render();
+               }
+               return;
+       }
+
+
        colormapped = !skinframe->merged || (ent->colormap >= 0 && skinframe->base && (skinframe->pants || skinframe->shirt));
        if (!colormapped && !fog && !skinframe->glow && !skinframe->fog)
        {
                // fastpath for the normal situation (one texture)
                memset(&m, 0, sizeof(m));
-               if (ent->effects & EF_ADDITIVE)
-               {
-                       m.blendfunc1 = GL_SRC_ALPHA;
-                       m.blendfunc2 = GL_ONE;
-               }
-               else if (ent->alpha != 1.0 || skinframe->fog != NULL)
-               {
-                       m.blendfunc1 = GL_SRC_ALPHA;
-                       m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-               }
-               else
-               {
-                       m.blendfunc1 = GL_ONE;
-                       m.blendfunc2 = GL_ZERO;
-               }
+               m.blendfunc1 = blendfunc1;
+               m.blendfunc2 = blendfunc2;
                m.numtriangles = model->numtris;
                m.numverts = model->numverts;
                m.tex[0] = R_GetTexture(skinframe->merged);
@@ -302,7 +339,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
 
                        aliasvert = m.vertex;
                        aliasvertcolor = m.color;
-                       R_SetupMDLMD2Frames(ent, m.colorscale * (1 - fog), m.colorscale * (1 - fog), m.colorscale * (1 - fog));
+                       R_SetupMDLMD2Frames(ent, m.colorscale, m.colorscale, m.colorscale);
                        aliasvert = aliasvertbuf;
                        aliasvertcolor = aliasvertcolorbuf;
 
@@ -332,27 +369,16 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
        }
 
        memset(&m, 0, sizeof(m));
-       if (ent->effects & EF_ADDITIVE)
-       {
-               m.blendfunc1 = GL_SRC_ALPHA;
-               m.blendfunc2 = GL_ONE;
-       }
-       else if (ent->alpha != 1.0 || skinframe->fog != NULL)
-       {
-               m.blendfunc1 = GL_SRC_ALPHA;
-               m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       }
-       else
-       {
-               m.blendfunc1 = GL_ONE;
-               m.blendfunc2 = GL_ZERO;
-       }
+       m.blendfunc1 = blendfunc1;
+       m.blendfunc2 = blendfunc2;
        m.numtriangles = model->numtris;
        m.numverts = model->numverts;
-       m.tex[0] = colormapped ? R_GetTexture(skinframe->base) : R_GetTexture(skinframe->merged);
        m.matrix = ent->matrix;
-       if (R_Mesh_Draw_GetBuffer(&m, true))
+       m.tex[0] = colormapped ? R_GetTexture(skinframe->base) : R_GetTexture(skinframe->merged);
+       if (m.tex[0] && R_Mesh_Draw_GetBuffer(&m, true))
        {
+               blendfunc1 = GL_SRC_ALPHA;
+               blendfunc2 = GL_ONE;
                c_alias_polys += m.numtriangles;
                R_ModulateColors(aliasvertcolor, m.color, m.numverts, m.colorscale, m.colorscale, m.colorscale);
                memcpy(m.index, model->mdlmd2data_indices, m.numtriangles * sizeof(int[3]));
@@ -366,14 +392,16 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                if (skinframe->pants)
                {
                        memset(&m, 0, sizeof(m));
-                       m.blendfunc1 = GL_SRC_ALPHA;
-                       m.blendfunc2 = GL_ONE;
+                       m.blendfunc1 = blendfunc1;
+                       m.blendfunc2 = blendfunc2;
                        m.numtriangles = model->numtris;
                        m.numverts = model->numverts;
-                       m.tex[0] = R_GetTexture(skinframe->pants);
                        m.matrix = ent->matrix;
-                       if (R_Mesh_Draw_GetBuffer(&m, true))
+                       m.tex[0] = R_GetTexture(skinframe->pants);
+                       if (m.tex[0] && R_Mesh_Draw_GetBuffer(&m, true))
                        {
+                               blendfunc1 = GL_SRC_ALPHA;
+                               blendfunc2 = GL_ONE;
                                c_alias_polys += m.numtriangles;
                                if (pantsfullbright)
                                        R_FillColors(m.color, m.numverts, pantscolor[0] * m.colorscale, pantscolor[1] * m.colorscale, pantscolor[2] * m.colorscale, ent->alpha);
@@ -388,14 +416,16 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                if (skinframe->shirt)
                {
                        memset(&m, 0, sizeof(m));
-                       m.blendfunc1 = GL_SRC_ALPHA;
-                       m.blendfunc2 = GL_ONE;
+                       m.blendfunc1 = blendfunc1;
+                       m.blendfunc2 = blendfunc2;
                        m.numtriangles = model->numtris;
                        m.numverts = model->numverts;
-                       m.tex[0] = R_GetTexture(skinframe->shirt);
                        m.matrix = ent->matrix;
-                       if (R_Mesh_Draw_GetBuffer(&m, true))
+                       m.tex[0] = R_GetTexture(skinframe->shirt);
+                       if (m.tex[0] && R_Mesh_Draw_GetBuffer(&m, true))
                        {
+                               blendfunc1 = GL_SRC_ALPHA;
+                               blendfunc2 = GL_ONE;
                                c_alias_polys += m.numtriangles;
                                if (shirtfullbright)
                                        R_FillColors(m.color, m.numverts, shirtcolor[0] * m.colorscale, shirtcolor[1] * m.colorscale, shirtcolor[2] * m.colorscale, ent->alpha);
@@ -411,14 +441,16 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
        if (skinframe->glow)
        {
                memset(&m, 0, sizeof(m));
-               m.blendfunc1 = GL_SRC_ALPHA;
-               m.blendfunc2 = GL_ONE;
+               m.blendfunc1 = blendfunc1;
+               m.blendfunc2 = blendfunc2;
                m.numtriangles = model->numtris;
                m.numverts = model->numverts;
-               m.tex[0] = R_GetTexture(skinframe->glow);
                m.matrix = ent->matrix;
-               if (R_Mesh_Draw_GetBuffer(&m, true))
+               m.tex[0] = R_GetTexture(skinframe->glow);
+               if (m.tex[0] && R_Mesh_Draw_GetBuffer(&m, true))
                {
+                       blendfunc1 = GL_SRC_ALPHA;
+                       blendfunc2 = GL_ONE;
                        c_alias_polys += m.numtriangles;
                        R_FillColors(m.color, m.numverts, (1 - fog) * m.colorscale, (1 - fog) * m.colorscale, (1 - fog) * m.colorscale, ent->alpha);
                        memcpy(m.index, model->mdlmd2data_indices, m.numtriangles * sizeof(int[3]));
@@ -434,12 +466,12 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                m.blendfunc2 = GL_ONE;
                m.numtriangles = model->numtris;
                m.numverts = model->numverts;
-               m.tex[0] = R_GetTexture(skinframe->fog);
                m.matrix = ent->matrix;
-               if (R_Mesh_Draw_GetBuffer(&m, false))
+               m.tex[0] = R_GetTexture(skinframe->fog);
+               if (R_Mesh_Draw_GetBuffer(&m, true))
                {
                        c_alias_polys += m.numtriangles;
-                       R_FillColors(m.color, m.numverts, fog * m.colorscale, fog * m.colorscale, fog * m.colorscale, ent->alpha);
+                       R_FillColors(m.color, m.numverts, fogcolor[0] * fog * m.colorscale, fogcolor[1] * fog * m.colorscale, fogcolor[2] * fog * m.colorscale, ent->alpha);
                        memcpy(m.index, model->mdlmd2data_indices, m.numtriangles * sizeof(int[3]));
                        memcpy(m.vertex, aliasvert, m.numverts * sizeof(float[4]));
                        memcpy(m.texcoords[0], model->mdlmd2data_texcoords, m.numverts * sizeof(float[2]));