]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
added error messages when opening sockets (reports both success and failure)
[xonotic/darkplaces.git] / gl_rsurf.c
index 51be852cd5aae54ad66b745d7fac8c6668498818..80f8096b7ab54e8d3805613898d514a528024e4f 100644 (file)
@@ -250,7 +250,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
 
        // set to full bright if no light data
                bl = intblocklights;
-               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->lightdata)
+               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
                {
                        for (i = 0;i < size3;i++)
                                bl[i] = 255*256;
@@ -289,7 +289,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
                out = templight;
                // deal with lightmap brightness scale
                shift = 7 + r_lightmapscalebit + 8;
-               if (ent->model->lightmaprgba)
+               if (ent->model->brushq1.lightmaprgba)
                {
                        stride = (surf->lightmaptexturestride - smax) * 4;
                        for (i = 0;i < tmax;i++, out += stride)
@@ -336,7 +336,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
 
        // set to full bright if no light data
                bl = floatblocklights;
-               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->lightdata)
+               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
                        j = 255*256;
                else
                        j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style
@@ -371,7 +371,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
                out = templight;
                // deal with lightmap brightness scale
                scale = 1.0f / (1 << (7 + r_lightmapscalebit + 8));
-               if (ent->model->lightmaprgba)
+               if (ent->model->brushq1.lightmaprgba)
                {
                        stride = (surf->lightmaptexturestride - smax) * 4;
                        for (i = 0;i < tmax;i++, out += stride)
@@ -444,7 +444,7 @@ loc0:
                impact[2] = origin[2] - node->plane->normal[2] * ndist;
        }
 
-       for (surf = model->surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
+       for (surf = model->brushq1.surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
        {
                if (surf->stainsamples)
                {
@@ -532,7 +532,7 @@ void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int
        entity_render_t *ent;
        model_t *model;
        vec3_t org;
-       if (cl.worldmodel == NULL)
+       if (cl.worldmodel == NULL || !cl.worldmodel->brushq1.nodes)
                return;
        fcolor[0] = cr1;
        fcolor[1] = cg1;
@@ -543,7 +543,7 @@ void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int
        fcolor[6] = cb2 - cb1;
        fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
 
-       R_StainNode(cl.worldmodel->nodes + cl.worldmodel->hulls[0].firstclipnode, cl.worldmodel, origin, radius, fcolor);
+       R_StainNode(cl.worldmodel->brushq1.nodes + cl.worldmodel->brushq1.hulls[0].firstclipnode, cl.worldmodel, origin, radius, fcolor);
 
        // look for embedded bmodels
        for (n = 0;n < cl_num_brushmodel_entities;n++)
@@ -553,10 +553,10 @@ void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int
                if (model && model->name[0] == '*')
                {
                        Mod_CheckLoaded(model);
-                       if (model->type == mod_brush)
+                       if (model->brushq1.nodes)
                        {
                                Matrix4x4_Transform(&ent->inversematrix, origin, org);
-                               R_StainNode(model->nodes + model->hulls[0].firstclipnode, model, org, radius, fcolor);
+                               R_StainNode(model->brushq1.nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
                        }
                }
        }
@@ -729,7 +729,7 @@ static void RSurfShader_Sky(const entity_render_t *ent, const texture_t *texture
        rmeshstate_t m;
 
        // LordHavoc: HalfLife maps have freaky skypolys...
-       if (ent->model->ishlbsp)
+       if (ent->model->brush.ishlbsp)
                return;
 
        if (skyrendernow)
@@ -778,7 +778,7 @@ static void RSurfShader_Sky(const entity_render_t *ent, const texture_t *texture
 static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
 {
        const entity_render_t *ent = calldata1;
-       const msurface_t *surf = ent->model->surfaces + calldata2;
+       const msurface_t *surf = ent->model->brushq1.surfaces + calldata2;
        float f, colorscale;
        const surfmesh_t *mesh;
        rmeshstate_t m;
@@ -879,14 +879,14 @@ static void RSurfShader_Water(const entity_render_t *ent, const texture_t *textu
                        if (surf->visframe == r_framecount)
                        {
                                Matrix4x4_Transform(&ent->matrix, surf->poly_center, center);
-                               R_MeshQueue_AddTransparent(center, RSurfShader_Water_Callback, ent, surf - ent->model->surfaces);
+                               R_MeshQueue_AddTransparent(center, RSurfShader_Water_Callback, ent, surf - ent->model->brushq1.surfaces);
                        }
                }
        }
        else
                for (chain = surfchain;(surf = *chain) != NULL;chain++)
                        if (surf->visframe == r_framecount)
-                               RSurfShader_Water_Callback(ent, surf - ent->model->surfaces);
+                               RSurfShader_Water_Callback(ent, surf - ent->model->brushq1.surfaces);
 }
 
 static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const msurface_t *surf, const texture_t *texture, int rendertype, float currentalpha)
@@ -1278,7 +1278,7 @@ static void RSurfShader_OpaqueWall_Pass_OpaqueGlow(const entity_render_t *ent, c
 static void RSurfShader_Wall_Vertex_Callback(const void *calldata1, int calldata2)
 {
        const entity_render_t *ent = calldata1;
-       const msurface_t *surf = ent->model->surfaces + calldata2;
+       const msurface_t *surf = ent->model->brushq1.surfaces + calldata2;
        int rendertype;
        float currentalpha;
        texture_t *texture;
@@ -1318,7 +1318,7 @@ static void RSurfShader_Wall_Lightmap(const entity_render_t *ent, const texture_
                        if (surf->visframe == r_framecount)
                        {
                                Matrix4x4_Transform(&ent->matrix, surf->poly_center, center);
-                               R_MeshQueue_AddTransparent(center, RSurfShader_Wall_Vertex_Callback, ent, surf - ent->model->surfaces);
+                               R_MeshQueue_AddTransparent(center, RSurfShader_Wall_Vertex_Callback, ent, surf - ent->model->brushq1.surfaces);
                        }
                }
        }
@@ -1396,9 +1396,9 @@ void R_UpdateTextureInfo(entity_render_t *ent)
 
        alttextures = ent->frame != 0;
        texframe = (int)(cl.time * 5.0f);
-       for (i = 0;i < ent->model->numtextures;i++)
+       for (i = 0;i < ent->model->brushq1.numtextures;i++)
        {
-               t = ent->model->textures + i;
+               t = ent->model->brushq1.textures + i;
                t->currentalpha = ent->alpha;
                if (t->flags & SURF_WATERALPHA)
                        t->currentalpha *= r_wateralpha.value;
@@ -1427,30 +1427,30 @@ void R_PrepareSurfaces(entity_render_t *ent)
 
        model = ent->model;
        Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
-       numsurfaces = model->nummodelsurfaces;
-       surfaces = model->surfaces + model->firstmodelsurface;
-       surfacevisframes = model->surfacevisframes + model->firstmodelsurface;
+       numsurfaces = model->brushq1.nummodelsurfaces;
+       surfaces = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
 
        R_UpdateTextureInfo(ent);
 
        if (r_dynamic.integer && !r_shadow_realtime_dlight.integer)
                R_MarkLights(ent);
 
-       if (model->light_ambient != r_ambient.value || model->light_scalebit != r_lightmapscalebit)
+       if (model->brushq1.light_ambient != r_ambient.value || model->brushq1.light_scalebit != r_lightmapscalebit)
        {
-               model->light_ambient = r_ambient.value;
-               model->light_scalebit = r_lightmapscalebit;
-               for (i = 0;i < model->nummodelsurfaces;i++)
-                       model->surfaces[i + model->firstmodelsurface].cached_dlight = true;
+               model->brushq1.light_ambient = r_ambient.value;
+               model->brushq1.light_scalebit = r_lightmapscalebit;
+               for (i = 0;i < model->brushq1.nummodelsurfaces;i++)
+                       model->brushq1.surfaces[i + model->brushq1.firstmodelsurface].cached_dlight = true;
        }
        else
        {
-               for (i = 0;i < model->light_styles;i++)
+               for (i = 0;i < model->brushq1.light_styles;i++)
                {
-                       if (model->light_stylevalue[i] != d_lightstylevalue[model->light_style[i]])
+                       if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
                        {
-                               model->light_stylevalue[i] = d_lightstylevalue[model->light_style[i]];
-                               for (surfchain = model->light_styleupdatechains[i];*surfchain;surfchain++)
+                               model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
+                               for (surfchain = model->brushq1.light_styleupdatechains[i];*surfchain;surfchain++)
                                        (**surfchain).cached_dlight = true;
                        }
                }
@@ -1491,7 +1491,7 @@ void R_DrawSurfaces(entity_render_t *ent, int type, msurface_t ***chains)
        if (ent->model == NULL)
                return;
        R_Mesh_Matrix(&ent->matrix);
-       for (i = 0, t = ent->model->textures;i < ent->model->numtextures;i++, t++)
+       for (i = 0, t = ent->model->brushq1.textures;i < ent->model->brushq1.numtextures;i++, t++)
                if (t->shader->shaderfunc[type] && t->currentframe && chains[i] != NULL)
                        t->shader->shaderfunc[type](ent, t->currentframe, chains[i]);
 }
@@ -1502,7 +1502,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
        float *v;
        rmeshstate_t m;
        const entity_render_t *ent = calldata1;
-       const mportal_t *portal = ent->model->portals + calldata2;
+       const mportal_t *portal = ent->model->brushq1.portals + calldata2;
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
@@ -1512,7 +1512,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
        memset(&m, 0, sizeof(m));
        R_Mesh_State_Texture(&m);
 
-       i = portal - ent->model->portals;
+       i = portal - ent->model->brushq1.portals;
        GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f) * r_colorscale,
                         ((i & 0x0038) >> 3) * (1.0f / 7.0f) * r_colorscale,
                         ((i & 0x01C0) >> 6) * (1.0f / 7.0f) * r_colorscale,
@@ -1528,6 +1528,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
        R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
 }
 
+// LordHavoc: this is just a nice debugging tool, very slow
 static void R_DrawPortals(entity_render_t *ent)
 {
        int i;
@@ -1535,9 +1536,9 @@ static void R_DrawPortals(entity_render_t *ent)
        float temp[3], center[3], f;
        if (ent->model == NULL)
                return;
-       for (portal = ent->model->portals, endportal = portal + ent->model->numportals;portal < endportal;portal++)
+       for (portal = ent->model->brushq1.portals, endportal = portal + ent->model->brushq1.numportals;portal < endportal;portal++)
        {
-               if ((portal->here->pvsframe == ent->model->pvsframecount || portal->past->pvsframe == ent->model->pvsframecount) && portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
+               if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
                {
                        VectorClear(temp);
                        for (i = 0;i < portal->numpoints;i++)
@@ -1545,7 +1546,7 @@ static void R_DrawPortals(entity_render_t *ent)
                        f = ixtable[portal->numpoints];
                        VectorScale(temp, f, temp);
                        Matrix4x4_Transform(&ent->matrix, temp, center);
-                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, ent, portal - ent->model->portals);
+                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, ent, portal - ent->model->brushq1.portals);
                }
        }
 }
@@ -1567,10 +1568,10 @@ void R_PrepareBrushModel(entity_render_t *ent)
 #if WORLDNODECULLBACKFACES
        Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
 #endif
-       numsurfaces = model->nummodelsurfaces;
-       surf = model->surfaces + model->firstmodelsurface;
-       surfacevisframes = model->surfacevisframes + model->firstmodelsurface;
-       surfacepvsframes = model->surfacepvsframes + model->firstmodelsurface;
+       numsurfaces = model->brushq1.nummodelsurfaces;
+       surf = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
+       surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
        for (i = 0;i < numsurfaces;i++, surf++)
        {
 #if WORLDNODECULLBACKFACES
@@ -1602,11 +1603,11 @@ void R_SurfaceWorldNode (entity_render_t *ent)
        model = ent->model;
        if (model == NULL)
                return;
-       surfacevisframes = model->surfacevisframes + model->firstmodelsurface;
-       surfacepvsframes = model->surfacepvsframes + model->firstmodelsurface;
+       surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
+       surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
        Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
 
-       for (leaf = model->pvsleafchain;leaf;leaf = leaf->pvschain)
+       for (leaf = model->brushq1.pvsleafchain;leaf;leaf = leaf->pvschain)
        {
                if (!R_CullBox (leaf->mins, leaf->maxs))
                {
@@ -1615,10 +1616,10 @@ void R_SurfaceWorldNode (entity_render_t *ent)
                }
        }
 
-       for (i = 0;i < model->pvssurflistlength;i++)
+       for (i = 0;i < model->brushq1.pvssurflistlength;i++)
        {
-               surfnum = model->pvssurflist[i];
-               surf = model->surfaces + surfnum;
+               surfnum = model->brushq1.pvssurflist[i];
+               surf = model->brushq1.surfaces + surfnum;
 #if WORLDNODECULLBACKFACES
                if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
                {
@@ -1639,7 +1640,7 @@ void R_SurfaceWorldNode (entity_render_t *ent)
 
 static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
 {
-       int c, leafstackpos, *mark, *surfacevisframes;
+       int c, leafstackpos, *mark, *surfacevisframes, bitnum;
 #if WORLDNODECULLBACKFACES
        int n;
        msurface_t *surf;
@@ -1654,8 +1655,8 @@ static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
        // follows portals leading outward from viewleaf, does not venture
        // offscreen or into leafs that are not visible, faster than Quake's
        // RecursiveWorldNode
-       surfaces = ent->model->surfaces;
-       surfacevisframes = ent->model->surfacevisframes;
+       surfaces = ent->model->brushq1.surfaces;
+       surfacevisframes = ent->model->brushq1.surfacevisframes;
        Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
        viewleaf->worldnodeframe = r_framecount;
        leafstack[0] = viewleaf;
@@ -1703,7 +1704,8 @@ static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
                                {
                                        leaf->worldnodeframe = r_framecount;
                                        // FIXME: R_CullBox is absolute, should be done relative
-                                       if (leaf->pvsframe == ent->model->pvsframecount && !R_CullBox(leaf->mins, leaf->maxs))
+                                       bitnum = (leaf - ent->model->brushq1.leafs) - 1;
+                                       if ((r_pvsbits[bitnum >> 3] & (1 << (bitnum & 7))) && !R_CullBox(leaf->mins, leaf->maxs))
                                                leafstack[leafstackpos++] = leaf;
                                }
                        }
@@ -1713,58 +1715,46 @@ static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
 
 void R_PVSUpdate (entity_render_t *ent, mleaf_t *viewleaf)
 {
-       int i, j, l, c, bits, *surfacepvsframes, *mark;
+       int j, c, *surfacepvsframes, *mark;
        mleaf_t *leaf;
-       qbyte *vis;
        model_t *model;
 
        model = ent->model;
-       if (model && (model->pvsviewleaf != viewleaf || model->pvsviewleafnovis != r_novis.integer))
+       if (model && (model->brushq1.pvsviewleaf != viewleaf || model->brushq1.pvsviewleafnovis != r_novis.integer))
        {
-               model->pvsframecount++;
-               model->pvsviewleaf = viewleaf;
-               model->pvsviewleafnovis = r_novis.integer;
-               model->pvsleafchain = NULL;
-               model->pvssurflistlength = 0;
+               model->brushq1.pvsframecount++;
+               model->brushq1.pvsviewleaf = viewleaf;
+               model->brushq1.pvsviewleafnovis = r_novis.integer;
+               model->brushq1.pvsleafchain = NULL;
+               model->brushq1.pvssurflistlength = 0;
                if (viewleaf)
                {
-                       surfacepvsframes = model->surfacepvsframes;
-                       vis = model->LeafPVS(model, viewleaf);
-                       for (j = 0;j < model->numleafs;j += 8)
+                       surfacepvsframes = model->brushq1.surfacepvsframes;
+                       for (j = 0;j < model->brushq1.visleafs;j++)
                        {
-                               bits = *vis++;
-                               if (bits)
+                               if (r_pvsbits[j >> 3] & (1 << (j & 7)))
                                {
-                                       l = model->numleafs - j;
-                                       if (l > 8)
-                                               l = 8;
-                                       for (i = 0;i < l;i++)
-                                       {
-                                               if (bits & (1 << i))
-                                               {
-                                                       leaf = &model->leafs[j + i + 1];
-                                                       leaf->pvschain = model->pvsleafchain;
-                                                       model->pvsleafchain = leaf;
-                                                       leaf->pvsframe = model->pvsframecount;
-                                                       // mark surfaces bounding this leaf as visible
-                                                       for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--, mark++)
-                                                               surfacepvsframes[*mark] = model->pvsframecount;
-                                               }
-                                       }
+                                       leaf = model->brushq1.leafs + j + 1;
+                                       leaf->pvsframe = model->brushq1.pvsframecount;
+                                       leaf->pvschain = model->brushq1.pvsleafchain;
+                                       model->brushq1.pvsleafchain = leaf;
+                                       // mark surfaces bounding this leaf as visible
+                                       for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--, mark++)
+                                               surfacepvsframes[*mark] = model->brushq1.pvsframecount;
                                }
                        }
-                       model->BuildPVSTextureChains(model);
+                       model->brushq1.BuildPVSTextureChains(model);
                }
        }
 }
 
-void R_WorldVisibility (entity_render_t *ent)
+void R_WorldVisibility(entity_render_t *ent)
 {
        vec3_t modelorg;
        mleaf_t *viewleaf;
 
        Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
-       viewleaf = ent->model->PointInLeaf(ent->model, modelorg);
+       viewleaf = (ent->model && ent->model->brushq1.PointInLeaf) ? ent->model->brushq1.PointInLeaf(ent->model, modelorg) : NULL;
        R_PVSUpdate(ent, viewleaf);
 
        if (!viewleaf)
@@ -1776,34 +1766,39 @@ void R_WorldVisibility (entity_render_t *ent)
                R_PortalWorldNode (ent, viewleaf);
 }
 
-void R_DrawWorld (entity_render_t *ent)
+void R_DrawWorld(entity_render_t *ent)
 {
        if (ent->model == NULL)
                return;
-       R_PrepareSurfaces(ent);
-       R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->pvstexturechains);
-       R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->pvstexturechains);
-       if (r_drawportals.integer)
-               R_DrawPortals(ent);
+       if (!ent->model->brushq1.numleafs && ent->model->Draw)
+               ent->model->Draw(ent);
+       else
+       {
+               R_PrepareSurfaces(ent);
+               R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->brushq1.pvstexturechains);
+               R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->brushq1.pvstexturechains);
+               if (r_drawportals.integer)
+                       R_DrawPortals(ent);
+       }
 }
 
-void R_Model_Brush_DrawSky (entity_render_t *ent)
+void R_Model_Brush_DrawSky(entity_render_t *ent)
 {
        if (ent->model == NULL)
                return;
        if (ent != &cl_entities[0].render)
                R_PrepareBrushModel(ent);
-       R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->pvstexturechains);
+       R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->brushq1.pvstexturechains);
 }
 
-void R_Model_Brush_Draw (entity_render_t *ent)
+void R_Model_Brush_Draw(entity_render_t *ent)
 {
        if (ent->model == NULL)
                return;
        c_bmodels++;
        if (ent != &cl_entities[0].render)
                R_PrepareBrushModel(ent);
-       R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->pvstexturechains);
+       R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->brushq1.pvstexturechains);
 }
 
 void R_Model_Brush_DrawShadowVolume (entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
@@ -1818,7 +1813,7 @@ void R_Model_Brush_DrawShadowVolume (entity_render_t *ent, vec3_t relativelighto
        lightradius2 = lightradius * lightradius;
        R_UpdateTextureInfo(ent);
        projectdistance = 1000000000.0f;//lightradius + ent->model->radius;
-       for (i = 0, surf = ent->model->surfaces + ent->model->firstmodelsurface;i < ent->model->nummodelsurfaces;i++, surf++)
+       for (i = 0, surf = ent->model->brushq1.surfaces + ent->model->brushq1.firstmodelsurface;i < ent->model->brushq1.nummodelsurfaces;i++, surf++)
        {
                if (surf->texinfo->texture->rendertype == SURFRENDER_OPAQUE && surf->flags & SURF_SHADOWCAST)
                {
@@ -1884,7 +1879,7 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
        lightmaxs[1] = relativelightorigin[1] + lightradius;
        lightmaxs[2] = relativelightorigin[2] + lightradius;
        R_UpdateTextureInfo(ent);
-       for (surfnum = 0, surf = ent->model->surfaces + ent->model->firstmodelsurface;surfnum < ent->model->nummodelsurfaces;surfnum++, surf++)
+       for (surfnum = 0, surf = ent->model->brushq1.surfaces + ent->model->brushq1.firstmodelsurface;surfnum < ent->model->brushq1.nummodelsurfaces;surfnum++, surf++)
        {
                if ((ent != &cl_entities[0].render || surf->visframe == r_framecount) && BoxesOverlap(surf->poly_mins, surf->poly_maxs, lightmins, lightmaxs))
                {
@@ -1907,6 +1902,152 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
        }
 }
 
+void R_DrawCollisionBrush(colbrushf_t *brush)
+{
+       int i;
+       i = ((int)brush) / sizeof(colbrushf_t);
+       GL_Color((i & 31) * (1.0f / 32.0f) * r_colorscale, ((i >> 5) & 31) * (1.0f / 32.0f) * r_colorscale, ((i >> 10) & 31) * (1.0f / 32.0f) * r_colorscale, 0.2f);
+       GL_VertexPointer(brush->points->v);
+       R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
+}
+
+void R_Q3BSP_DrawFace_Mesh(entity_render_t *ent, q3mface_t *face)
+{
+       rmeshstate_t m;
+       memset(&m, 0, sizeof(m));
+       GL_BlendFunc(GL_ONE, GL_ZERO);
+       GL_DepthMask(true);
+       GL_DepthTest(true);
+       m.tex[0] = R_GetTexture(face->texture->skin.base);
+       m.pointer_texcoord[0] = face->data_texcoordtexture2f;
+       if (face->lightmaptexture)
+       {
+               m.tex[1] = R_GetTexture(face->lightmaptexture);
+               m.pointer_texcoord[1] = face->data_texcoordlightmap2f;
+               m.texrgbscale[1] = 2;
+               GL_Color(r_colorscale, r_colorscale, r_colorscale, 1);
+       }
+       else
+       {
+               m.texrgbscale[0] = 2;
+               GL_ColorPointer(face->data_color4f);
+       }
+       R_Mesh_State_Texture(&m);
+       GL_VertexPointer(face->data_vertex3f);
+       R_Mesh_Draw(face->numvertices, face->numtriangles, face->data_element3i);
+}
+
+void R_Q3BSP_DrawFace_Patch(entity_render_t *ent, q3mface_t *face)
+{
+}
+
+void R_Q3BSP_DrawFace(entity_render_t *ent, q3mface_t *face)
+{
+       if (face->texture->renderflags & Q3MTEXTURERENDERFLAGS_NODRAW)
+               return;
+       switch(face->type)
+       {
+               case Q3FACETYPE_POLYGON:
+               case Q3FACETYPE_MESH:
+                       R_Q3BSP_DrawFace_Mesh(ent, face);
+                       break;
+               case Q3FACETYPE_PATCH:
+                       R_Q3BSP_DrawFace_Patch(ent, face);
+                       break;
+               case Q3FACETYPE_FLARE:
+                       break;
+       }
+}
+
+/*
+void R_Q3BSP_DrawSky(entity_render_t *ent)
+{
+}
+*/
+
+void R_Q3BSP_RecursiveWorldNode(entity_render_t *ent, q3mnode_t *node, const vec3_t modelorg, qbyte *pvs, int markframe)
+{
+       int i;
+       q3mleaf_t *leaf;
+       while (node->isnode)
+       {
+               if (R_CullBox(node->mins, node->maxs))
+                       return;
+               R_Q3BSP_RecursiveWorldNode(ent, node->children[0], modelorg, pvs, markframe);
+               node = node->children[1];
+       }
+       if (R_CullBox(node->mins, node->maxs))
+               return;
+       leaf = (q3mleaf_t *)node;
+       if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7)))
+       {
+               for (i = 0;i < leaf->numleaffaces;i++)
+               {
+                       if (leaf->firstleafface[i]->markframe != markframe)
+                       {
+                               leaf->firstleafface[i]->markframe = markframe;
+                               R_Q3BSP_DrawFace(ent, leaf->firstleafface[i]);
+                       }
+               }
+       }
+}
+
+
+
+void R_Q3BSP_Draw(entity_render_t *ent)
+{
+       int i;
+       q3mface_t *face;
+       vec3_t modelorg;
+       model_t *model;
+       qbyte *pvs;
+       static int markframe = 0;
+       R_Mesh_Matrix(&ent->matrix);
+       model = ent->model;
+       if (r_drawcollisionbrushes.integer < 2)
+       {
+               if (ent == &cl_entities[0].render)
+               {
+                       Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
+                       pvs = model->brush.GetPVS(model, modelorg);
+                       R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, ++markframe);
+               }
+               else
+                       for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
+                               R_Q3BSP_DrawFace(ent, face);
+       }
+       if (r_drawcollisionbrushes.integer >= 1)
+       {
+               rmeshstate_t m;
+               memset(&m, 0, sizeof(m));
+               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
+               GL_DepthMask(false);
+               GL_DepthTest(true);
+               R_Mesh_State_Texture(&m);
+               for (i = 0;i < model->brushq3.data_thismodel->numbrushes;i++)
+                       if (model->brushq3.data_thismodel->firstbrush[i].colbrushf && model->brushq3.data_thismodel->firstbrush[i].colbrushf->numtriangles)
+                               R_DrawCollisionBrush(model->brushq3.data_thismodel->firstbrush[i].colbrushf);
+       }
+}
+
+/*
+void R_Q3BSP_DrawFakeShadow(entity_render_t *ent)
+{
+}
+*/
+
+/*
+void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
+{
+}
+*/
+
+/*
+void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
+{
+}
+*/
+
 static void gl_surf_start(void)
 {
 }