+ if (r_showcollisionbrushes.integer && !skysurfaces)
+ R_DrawCollisionBrushes(r_refdef.worldentity);
+
+ if (r_showtris.integer || r_shownormals.integer)
+ R_DrawTrianglesAndNormals(r_refdef.worldentity, r_showtris.integer, r_shownormals.integer, flagsmask);
+}
+
+void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces)
+{
+ int i, f, flagsmask;
+ int counttriangles = 0;
+ msurface_t *surface, *endsurface, **surfacechain;
+ texture_t *t;
+ model_t *model = ent->model;
+ const int maxsurfacelist = 1024;
+ int numsurfacelist = 0;
+ msurface_t *surfacelist[1024];
+ if (model == NULL)
+ return;
+
+ // if the model is static it doesn't matter what value we give for
+ // wantnormals and wanttangents, so this logic uses only rules applicable
+ // to a model, knowing that they are meaningless otherwise
+ if (ent == r_refdef.worldentity)
+ RSurf_ActiveWorldEntity();
+ else if ((ent->effects & EF_FULLBRIGHT) || r_showsurfaces.integer || VectorLength2(ent->modellight_diffuse) < (1.0f / 256.0f))
+ RSurf_ActiveModelEntity(ent, false, false);
+ else
+ RSurf_ActiveModelEntity(ent, true, r_glsl.integer && gl_support_fragment_shader);
+
+ // update light styles
+ if (!skysurfaces && model->brushq1.light_styleupdatechains)
+ {
+ for (i = 0;i < model->brushq1.light_styles;i++)
+ {
+ if (model->brushq1.light_stylevalue[i] != r_refdef.lightstylevalue[model->brushq1.light_style[i]])
+ {
+ model->brushq1.light_stylevalue[i] = r_refdef.lightstylevalue[model->brushq1.light_style[i]];
+ if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
+ for (;(surface = *surfacechain);surfacechain++)
+ surface->cached_dlight = true;
+ }
+ }
+ }
+
+ R_UpdateAllTextureInfo(ent);
+ flagsmask = skysurfaces ? MATERIALFLAG_SKY : (MATERIALFLAG_WATER | MATERIALFLAG_WALL);
+ f = 0;
+ t = NULL;
+ rsurface_uselightmaptexture = false;
+ rsurface_texture = NULL;
+ numsurfacelist = 0;
+ surface = model->data_surfaces + model->firstmodelsurface;
+ endsurface = surface + model->nummodelsurfaces;
+ for (;surface < endsurface;surface++)
+ {
+ // if this surface fits the criteria, add it to the list
+ if (surface->texture->basematerialflags & flagsmask && surface->num_triangles)
+ {
+ // if lightmap parameters changed, rebuild lightmap texture
+ if (surface->cached_dlight)
+ R_BuildLightMap(ent, surface);
+ // add face to draw list
+ surfacelist[numsurfacelist++] = surface;
+ counttriangles += surface->num_triangles;
+ if (numsurfacelist >= maxsurfacelist)
+ {
+ R_QueueSurfaceList(numsurfacelist, surfacelist);
+ numsurfacelist = 0;
+ }
+ }
+ }
+ if (numsurfacelist)
+ R_QueueSurfaceList(numsurfacelist, surfacelist);
+ r_refdef.stats.entities_triangles += counttriangles;
+ RSurf_CleanUp();
+