]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
q3bsp is still not working yet, but getting closer
[xonotic/darkplaces.git] / gl_rsurf.c
index 4727958b220d35c6be594bf6bc1f7c70dded859a..892193e867b598065778da21c8756a34c8e365e6 100644 (file)
@@ -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;
@@ -553,7 +553,7 @@ 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->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->brushq1.ishlbsp)
+       if (ent->model->brush.ishlbsp)
                return;
 
        if (skyrendernow)
@@ -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;
@@ -1537,7 +1538,7 @@ static void R_DrawPortals(entity_render_t *ent)
                return;
        for (portal = ent->model->brushq1.portals, endportal = portal + ent->model->brushq1.numportals;portal < endportal;portal++)
        {
-               if ((portal->here->pvsframe == ent->model->brushq1.pvsframecount || portal->past->pvsframe == ent->model->brushq1.pvsframecount) && portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
+               if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
                {
                        VectorClear(temp);
                        for (i = 0;i < portal->numpoints;i++)
@@ -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;
@@ -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->brushq1.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,9 +1715,8 @@ 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;
@@ -1729,28 +1730,17 @@ void R_PVSUpdate (entity_render_t *ent, mleaf_t *viewleaf)
                if (viewleaf)
                {
                        surfacepvsframes = model->brushq1.surfacepvsframes;
-                       vis = model->brushq1.LeafPVS(model, viewleaf);
-                       for (j = 0;j < model->brushq1.numleafs;j += 8)
+                       for (j = 0;j < model->brushq1.visleafs;j++)
                        {
-                               bits = *vis++;
-                               if (bits)
+                               if (r_pvsbits[j >> 3] & (1 << (j & 7)))
                                {
-                                       l = model->brushq1.numleafs - j;
-                                       if (l > 8)
-                                               l = 8;
-                                       for (i = 0;i < l;i++)
-                                       {
-                                               if (bits & (1 << i))
-                                               {
-                                                       leaf = &model->brushq1.leafs[j + i + 1];
-                                                       leaf->pvschain = model->brushq1.pvsleafchain;
-                                                       model->brushq1.pvsleafchain = leaf;
-                                                       leaf->pvsframe = model->brushq1.pvsframecount;
-                                                       // mark surfaces bounding this leaf as visible
-                                                       for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--, mark++)
-                                                               surfacepvsframes[*mark] = model->brushq1.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->brushq1.BuildPVSTextureChains(model);
@@ -1758,13 +1748,13 @@ void R_PVSUpdate (entity_render_t *ent, mleaf_t *viewleaf)
        }
 }
 
-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 ? ent->model->brushq1.PointInLeaf(ent->model, modelorg) : NULL;
+       viewleaf = (ent->model && ent->model->brushq1.PointInLeaf) ? ent->model->brushq1.PointInLeaf(ent->model, modelorg) : NULL;
        R_PVSUpdate(ent, viewleaf);
 
        if (!viewleaf)
@@ -1776,18 +1766,23 @@ 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->brushq1.pvstexturechains);
-       R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->brushq1.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;
@@ -1796,7 +1791,7 @@ void R_Model_Brush_DrawSky (entity_render_t *ent)
        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;
@@ -1907,6 +1902,87 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
        }
 }
 
+void R_Q3BSP_DrawFace_Mesh(entity_render_t *ent, q3mface_t *face)
+{
+       const surfmesh_t *mesh;
+       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(mesh->numverts, mesh->numtriangles, mesh->element3i);
+}
+
+void R_Q3BSP_DrawFace_Patch(entity_render_t *ent, q3mface_t *face)
+{
+}
+
+void R_Q3BSP_DrawFace(entity_render_t *ent, q3mface_t *face)
+{
+       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_Draw(entity_render_t *ent)
+{
+       int i;
+       q3mface_t *face;
+       model_t *model;
+       model = ent->model;
+       for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
+               R_Q3BSP_DrawFace(ent, face);
+}
+
+/*
+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)
 {
 }