]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
merged matrix4x4 and matrix3x4 into matrixlib, updated makefiles and dsp, some cleanu...
[xonotic/darkplaces.git] / gl_rsurf.c
index edfe4cdbcd4e6b7831eafe783cf2439f696512a6..e3429922df8fb731dd812cb674838c570c620009 100644 (file)
@@ -88,26 +88,28 @@ static int R_AddDynamicLights (msurface_t *surf)
                        continue;                                       // not lit by this light
 
                softwareuntransform(r_dlight[lnum].origin, local);
-//             VectorSubtract (r_dlight[lnum].origin, currentrenderentity->origin, local);
                dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
 
                // for comparisons to minimum acceptable light
                // compensate for LIGHTOFFSET
                maxdist = (int) r_dlight[lnum].cullradius2 + LIGHTOFFSET;
 
-               // already clamped, skip this
-               // clamp radius to avoid exceeding 32768 entry division table
-               //if (maxdist > 4194304)
-               //      maxdist = 4194304;
-
                dist2 = dist * dist;
                dist2 += LIGHTOFFSET;
                if (dist2 >= maxdist)
                        continue;
 
-               impact[0] = local[0] - surf->plane->normal[0] * dist;
-               impact[1] = local[1] - surf->plane->normal[1] * dist;
-               impact[2] = local[2] - surf->plane->normal[2] * dist;
+               if (surf->plane->type < 3)
+               {
+                       VectorCopy(local, impact);
+                       impact[surf->plane->type] -= dist;
+               }
+               else
+               {
+                       impact[0] = local[0] - surf->plane->normal[0] * dist;
+                       impact[1] = local[1] - surf->plane->normal[1] * dist;
+                       impact[2] = local[2] - surf->plane->normal[2] * dist;
+               }
 
                impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
                impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
@@ -209,9 +211,17 @@ loc0:
        {
                maxdist3 = maxdist - dist2;
 
-               impact[0] = origin[0] - node->plane->normal[0] * ndist;
-               impact[1] = origin[1] - node->plane->normal[1] * ndist;
-               impact[2] = origin[2] - node->plane->normal[2] * ndist;
+               if (node->plane->type < 3)
+               {
+                       VectorCopy(origin, impact);
+                       impact[node->plane->type] -= ndist;
+               }
+               else
+               {
+                       impact[0] = origin[0] - node->plane->normal[0] * ndist;
+                       impact[1] = origin[1] - node->plane->normal[1] * ndist;
+                       impact[2] = origin[2] - node->plane->normal[2] * ndist;
+               }
 
                for (surf = model->surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
                {
@@ -371,12 +381,8 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
        if ((currentrenderentity->effects & EF_FULLBRIGHT) || !cl.worldmodel->lightdata)
        {
                bl = blocklights;
-               for (i = 0;i < size;i++)
-               {
-                       *bl++ = 255*256;
-                       *bl++ = 255*256;
-                       *bl++ = 255*256;
-               }
+               for (i = 0;i < size3;i++)
+                       bl[i] = 255*256;
        }
        else
        {
@@ -402,21 +408,19 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
 
 // add all the lightmaps
                if (lightmap)
-                       for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
-                               for (scale = d_lightstylevalue[surf->styles[maps]], bl = blocklights, i = 0;i < size3;i++)
-                                       *bl++ += *lightmap++ * scale;
+               {
+                       bl = blocklights;
+                       for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
+                               for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
+                                       bl[i] += lightmap[i] * scale;
+               }
        }
 
        stain = surf->stainsamples;
-       if (stain)
-               for (bl = blocklights, i = 0;i < size3;i++)
-                       if (stain[i] < 255)
-                               bl[i] = (bl[i] * stain[i]) >> 8;
-
        bl = blocklights;
        out = templight;
        // deal with lightmap brightness scale
-       shift = 7 + lightscalebit;
+       shift = 15 + lightscalebit;
        if (currentrenderentity->model->lightmaprgba)
        {
                stride = (surf->lightmaptexturestride - smax) * 4;
@@ -424,9 +428,9 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
                {
                        for (j = 0;j < smax;j++)
                        {
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
                                *out++ = 255;
                        }
                }
@@ -438,9 +442,9 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
                {
                        for (j = 0;j < smax;j++)
                        {
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
                        }
                }
        }
@@ -448,27 +452,6 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
        R_UpdateTexture(surf->lightmaptexture, templight);
 }
 
-/*
-===============
-R_TextureAnimation
-
-Returns the proper texture for a given time and base texture
-===============
-*/
-/*
-// note: this was manually inlined in R_PrepareSurfaces
-static texture_t *R_TextureAnimation (texture_t *base)
-{
-       if (currentrenderentity->frame && base->alternate_anims != NULL)
-               base = base->alternate_anims;
-
-       if (base->anim_total < 2)
-               return base;
-
-       return base->anim_frames[(int)(cl.time * 5.0f) % base->anim_total];
-}
-*/
-
 
 /*
 =============================================================
@@ -485,7 +468,8 @@ static float turbsin[256] =
 };
 #define TURBSCALE (256.0 / (2 * M_PI))
 
-#define MAX_SURFVERTS 1024
+// only need to hold as many verts as the mesh splitter will allow in model_brush.c
+#define MAX_SURFVERTS 3072
 typedef struct
 {
        float v[4];
@@ -530,10 +514,6 @@ static void RSurfShader_Sky(msurface_t *firstsurf)
                                m.numtriangles = mesh->numtriangles;
                                m.numverts = mesh->numverts;
                                m.index = mesh->index;
-                               //m.cr = 0;
-                               //m.cg = 0;
-                               //m.cb = 0;
-                               //m.ca = 0;
                                if (softwaretransform_complexity)
                                {
                                        m.vertex = &svert[0].v[0];
@@ -903,8 +883,7 @@ static void RSurfShader_Water(msurface_t *firstsurf)
                        RSurfShader_Water_Pass_Glow(surf);
        if (fogenabled)
                for (surf = firstsurf;surf;surf = surf->chain)
-                       //if (currentrenderentity->alpha * (surf->flags & SURF_DRAWNOALPHA ? 1 : r_wateralpha.value) >= 1.0f)
-                               RSurfShader_Water_Pass_Fog(surf);
+                       RSurfShader_Water_Pass_Fog(surf);
 }
 
 static void RSurfShader_Wall_Pass_BaseMTex(msurface_t *surf)
@@ -1952,7 +1931,7 @@ Cshader_t *Cshaders[5] =
 
 void R_PrepareSurfaces(void)
 {
-       int i;
+       int i, entframe, texframe, framecount;
        texture_t *t;
        model_t *model;
        msurface_t *surf;
@@ -1961,6 +1940,8 @@ void R_PrepareSurfaces(void)
                Cshaders[i]->chain = NULL;
 
        model = currentrenderentity->model;
+       entframe = currentrenderentity->frame;
+       texframe = (int)(cl.time * 5.0f);
 
        for (i = 0;i < model->nummodelsurfaces;i++)
        {
@@ -1971,14 +1952,28 @@ void R_PrepareSurfaces(void)
                        {
                                surf->insertframe = r_framecount;
                                c_faces++;
-                               // manually inlined R_TextureAnimation
-                               //t = R_TextureAnimation(surf->texinfo->texture);
                                t = surf->texinfo->texture;
-                               if (t->alternate_anims != NULL && currentrenderentity->frame)
-                                       t = t->alternate_anims;
-                               if (t->anim_total >= 2)
-                                       t = t->anim_frames[(int)(cl.time * 5.0f) % t->anim_total];
-                               surf->currenttexture = t;
+                               if (t->animated)
+                               {
+                                       if (entframe)
+                                       {
+                                               framecount = t->anim_total[1];
+                                               if (framecount >= 2)
+                                                       surf->currenttexture = t->anim_frames[1][texframe % framecount];
+                                               else
+                                                       surf->currenttexture = t->anim_frames[1][0];
+                                       }
+                                       else
+                                       {
+                                               framecount = t->anim_total[0];
+                                               if (framecount >= 2)
+                                                       surf->currenttexture = t->anim_frames[0][texframe % framecount];
+                                               else
+                                                       surf->currenttexture = t->anim_frames[0][0];
+                                       }
+                               }
+                               else
+                                       surf->currenttexture = t;
                        }
 
                        surf->chain = surf->shader->chain;
@@ -2005,38 +2000,14 @@ static float portalpointbuffer[256][3];
 void R_DrawPortals(void)
 {
        int drawportals, i;
-//     mleaf_t *leaf, *endleaf;
        mportal_t *portal, *endportal;
-       mvertex_t *point/*, *endpoint*/;
+       mvertex_t *point;
        rmeshinfo_t m;
        drawportals = r_drawportals.integer;
+
        if (drawportals < 1)
                return;
-       /*
-       leaf = cl.worldmodel->leafs;
-       endleaf = leaf + cl.worldmodel->numleafs;
-       for (;leaf < endleaf;leaf++)
-       {
-               if (leaf->visframe == r_framecount && leaf->portals)
-               {
-                       i = leaf - cl.worldmodel->leafs;
-                       r = (i & 0x0007) << 5;
-                       g = (i & 0x0038) << 2;
-                       b = (i & 0x01C0) >> 1;
-                       portal = leaf->portals;
-                       while (portal)
-                       {
-                               transpolybegin(0, 0, 0, TPOLYTYPE_ALPHA);
-                               point = portal->points + portal->numpoints - 1;
-                               endpoint = portal->points;
-                               for (;point >= endpoint;point--)
-                                       transpolyvertub(point->position[0], point->position[1], point->position[2], 0, 0, r, g, b, 32);
-                               transpolyend();
-                               portal = portal->next;
-                       }
-               }
-       }
-       */
+
        memset(&m, 0, sizeof(m));
        m.transparent = true;
        m.blendfunc1 = GL_SRC_ALPHA;
@@ -2134,10 +2105,6 @@ static void R_SurfMarkLights (void)
                                         || (surf->styles[1] != 255 && (d_lightstylevalue[surf->styles[1]] != surf->cached_light[1]
                                         || (surf->styles[2] != 255 && (d_lightstylevalue[surf->styles[2]] != surf->cached_light[2]
                                         || (surf->styles[3] != 255 && (d_lightstylevalue[surf->styles[3]] != surf->cached_light[3]))))))))
-                                       //if (surf->cached_light[0] != d_lightstylevalue[surf->styles[0]]
-                                       // || surf->cached_light[1] != d_lightstylevalue[surf->styles[1]]
-                                       // || surf->cached_light[2] != d_lightstylevalue[surf->styles[2]]
-                                       // || surf->cached_light[3] != d_lightstylevalue[surf->styles[3]])
                                                R_BuildLightMap(surf, false); // base lighting changed
                                        else if (surf->dlightframe == r_framecount && r_dlightmap.integer)
                                                R_BuildLightMap(surf, true); // only dlights
@@ -2198,3 +2165,4 @@ void R_DrawBrushModelNormal (void)
                R_DrawSurfaces(SHADERSTAGE_SKY);
        R_DrawSurfaces(SHADERSTAGE_NORMAL);
 }
+