]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
eliminated qbyte type, now uses unsigned char throughout the engine for this purpose
[xonotic/darkplaces.git] / gl_rsurf.c
index cff28d66c9b6d4fb5570990808330b958420bf28..68ac13e4c83afa44bc6a76da7cad7f5b0f1cfc0c 100644 (file)
@@ -36,11 +36,11 @@ cvar_t r_q3bsp_renderskydepth = {0, "r_q3bsp_renderskydepth", "0"};
 // flag arrays used for visibility checking on world model
 // (all other entities have no per-surface/per-leaf visibility checks)
 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
-qbyte r_pvsbits[(32768+7)>>3];
+unsigned char r_pvsbits[(32768+7)>>3];
 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
-qbyte r_worldleafvisible[32768];
+unsigned char r_worldleafvisible[32768];
 // TODO: dynamic resize according to r_refdef.worldmodel->num_surfaces
-qbyte r_worldsurfacevisible[262144];
+unsigned char r_worldsurfacevisible[262144];
 
 /*
 ===============
@@ -53,9 +53,9 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
 {
        int smax, tmax, i, j, size, size3, maps, stride, l;
        unsigned int *bl, scale;
-       qbyte *lightmap, *out, *stain;
+       unsigned char *lightmap, *out, *stain;
        static unsigned int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
-       static qbyte templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
+       static unsigned char templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
 
        // update cached lighting info
        surface->cached_dlight = 0;
@@ -83,7 +83,7 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
                {
                        bl = intblocklights;
                        for (maps = 0;maps < MAXLIGHTMAPS && surface->lightmapinfo->styles[maps] != 255;maps++, lightmap += size3)
-                               for (scale = d_lightstylevalue[surface->lightmapinfo->styles[maps]], i = 0;i < size3;i++)
+                               for (scale = r_refdef.lightstylevalue[surface->lightmapinfo->styles[maps]], i = 0;i < size3;i++)
                                        bl[i] += lightmap[i] * scale;
                }
        }
@@ -131,7 +131,7 @@ void R_StainNode (mnode_t *node, model_t *model, const vec3_t origin, float radi
        float ndist, a, ratio, maxdist, maxdist2, maxdist3, invradius, sdtable[256], td, dist2;
        msurface_t *surface, *endsurface;
        int i, s, t, smax, tmax, smax3, impacts, impactt, stained;
-       qbyte *bl;
+       unsigned char *bl;
        vec3_t impact;
 
        maxdist = radius * radius;
@@ -209,9 +209,9 @@ loc0:
                                                        {
                                                                if (a > 1)
                                                                        a = 1;
-                                                               bl[0] = (qbyte) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
-                                                               bl[1] = (qbyte) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
-                                                               bl[2] = (qbyte) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
+                                                               bl[0] = (unsigned char) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
+                                                               bl[1] = (unsigned char) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
+                                                               bl[2] = (unsigned char) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
                                                                stained = true;
                                                        }
                                                }
@@ -275,7 +275,6 @@ void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int
                model = ent->model;
                if (model && model->name[0] == '*')
                {
-                       Mod_CheckLoaded(model);
                        if (model->brush.data_nodes)
                        {
                                Matrix4x4_Transform(&ent->inversematrix, origin, org);
@@ -299,7 +298,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
        int i;
        float *v;
        rmeshstate_t m;
-       const mportal_t *portal = calldata1;
+       const mportal_t *portal = (mportal_t *)calldata1;
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -421,7 +420,7 @@ void R_WorldVisibility(void)
                        // if leaf is in current pvs and on the screen, mark its surfaces
                        if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
                        {
-                               c_leafs++;
+                               renderstats.world_leafs++;
                                r_worldleafvisible[j] = true;
                                if (leaf->numleafsurfaces)
                                        for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
@@ -443,7 +442,7 @@ void R_WorldVisibility(void)
                leafstackpos = 1;
                while (leafstackpos)
                {
-                       c_leafs++;
+                       renderstats.world_leafs++;
                        leaf = leafstack[--leafstackpos];
                        r_worldleafvisible[leaf - model->brush.data_leafs] = true;
                        // mark any surfaces bounding this leaf
@@ -458,8 +457,11 @@ void R_WorldVisibility(void)
                        // and the leaf is visible in the pvs
                        // (the first two checks won't cause as many cache misses as the leaf checks)
                        for (p = leaf->portals;p;p = p->next)
+                       {
+                               renderstats.world_portals++;
                                if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !R_CullBox(p->mins, p->maxs) && !r_worldleafvisible[p->past - model->brush.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex))
                                        leafstack[leafstackpos++] = p->past;
+                       }
                }
        }
 
@@ -477,15 +479,14 @@ void R_Q1BSP_DrawSky(entity_render_t *ent)
 
 void R_Q1BSP_Draw(entity_render_t *ent)
 {
-       if (ent->model == NULL)
+       model_t *model = ent->model;
+       if (model == NULL)
                return;
-       c_bmodels++;
        if (r_drawcollisionbrushes.integer < 2)
                R_DrawSurfaces(ent, false);
-       if (r_drawcollisionbrushes.integer >= 1 && ent->model->brush.num_brushes)
+       if (r_drawcollisionbrushes.integer >= 1 && model->brush.num_brushes)
        {
                int i;
-               model_t *model = ent->model;
                msurface_t *surface;
                q3mbrush_t *brush;
                R_Mesh_Matrix(&ent->matrix);
@@ -509,16 +510,16 @@ typedef struct r_q1bsp_getlightinfo_s
        vec3_t relativelightorigin;
        float lightradius;
        int *outleaflist;
-       qbyte *outleafpvs;
+       unsigned char *outleafpvs;
        int outnumleafs;
        int *outsurfacelist;
-       qbyte *outsurfacepvs;
+       unsigned char *outsurfacepvs;
        int outnumsurfaces;
        vec3_t outmins;
        vec3_t outmaxs;
        vec3_t lightmins;
        vec3_t lightmaxs;
-       const qbyte *pvs;
+       const unsigned char *pvs;
 }
 r_q1bsp_getlightinfo_t;
 
@@ -528,18 +529,22 @@ void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t *node)
        mleaf_t *leaf;
        for (;;)
        {
-               if (!BoxesOverlap(info->lightmins, info->lightmaxs, node->mins, node->maxs))
-                       return;
-               if (!node->plane)
+               mplane_t *plane = node->plane;
+               //if (!BoxesOverlap(info->lightmins, info->lightmaxs, node->mins, node->maxs))
+               //      return;
+               if (!plane)
                        break;
-               sides = BoxOnPlaneSide(info->lightmins, info->lightmaxs, node->plane) - 1;
-               if (sides == 2)
+               if (plane->type < 3)
+                       sides = ((info->lightmaxs[plane->type] >= plane->dist) | ((info->lightmins[plane->type] < plane->dist) << 1));
+               else
+                       sides = BoxOnPlaneSide(info->lightmins, info->lightmaxs, plane);
+               if (sides == 3)
                {
                        R_Q1BSP_RecursiveGetLightInfo(info, node->children[0]);
                        node = node->children[1];
                }
                else
-                       node = node->children[sides];
+                       node = node->children[sides - 1];
        }
        leaf = (mleaf_t *)node;
        if (info->pvs == NULL || CHECKPVSBIT(info->pvs, leaf->clusterindex))
@@ -593,7 +598,7 @@ void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t *node)
        }
 }
 
-void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, qbyte *outleafpvs, int *outnumleafspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer)
+void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer)
 {
        r_q1bsp_getlightinfo_t info;
        VectorCopy(relativelightorigin, info.relativelightorigin);
@@ -764,6 +769,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, float *light
                if ((ent == r_refdef.worldentity && !r_worldsurfacevisible[surfacelist[surfacelistindex]]))
                        continue;
                surface = model->data_surfaces + surfacelist[surfacelistindex];
+               renderstats.lights_lighttriangles += surface->num_triangles;
                if (tex != surface->texture)
                {
                        if (batchnumsurfaces > 0)