numpoints = min(portal->numpoints, POLYGONELEMENTS_MAXPOINTS);
+ R_Mesh_VertexPointer(vertex3f, 0, 0);
+ R_Mesh_ColorPointer(NULL, 0, 0);
R_Mesh_ResetTextureState();
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
isvis = (portal->here->clusterindex >= 0 && portal->past->clusterindex >= 0 && portal->here->clusterindex != portal->past->clusterindex);
isvis ? 0.125f : 0.03125f);
for (i = 0, v = vertex3f;i < numpoints;i++, v += 3)
VectorCopy(portal->points[i].position, v);
- R_Mesh_PrepareVertices_Generic_Arrays(numpoints, vertex3f, NULL, NULL);
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1);
- R_Mesh_Draw(0, numpoints, 0, numpoints - 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
+ R_Mesh_Draw(0, numpoints, 0, numpoints - 2, polygonelement3i, polygonelement3s, 0, 0);
}
// LordHavoc: this is just a nice debugging tool, very slow
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(true);
GL_AlphaTest(false);
+ R_Mesh_ColorPointer(NULL, 0, 0);
R_Mesh_ResetTextureState();
R_SetupShader_DepthOrShadow();
if (ent == r_refdef.scene.worldentity)
if (castshadow)
SETPVSBIT(info->outshadowtrispvs, t);
}
-#if 0
+#if 1
else if (r_shadow_frontsidecasting.integer)
{
// front side casting occludes backfaces,
}
}
+static msurface_t *r_q1bsp_getlightinfo_surfaces;
+
+int R_Q1BSP_GetLightInfo_comparefunc(const void *ap, const void *bp)
+{
+ int a = *(int*)ap;
+ int b = *(int*)bp;
+ const msurface_t *as = r_q1bsp_getlightinfo_surfaces + a;
+ const msurface_t *bs = r_q1bsp_getlightinfo_surfaces + b;
+ if (as->texture < bs->texture)
+ return -1;
+ if (as->texture > bs->texture)
+ return 1;
+ return a - b;
+}
+
+extern cvar_t r_shadow_sortsurfaces;
+
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, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs, int numfrustumplanes, const mplane_t *frustumplanes)
{
r_q1bsp_getlightinfo_t info;
*outnumleafspointer = info.outnumleafs;
*outnumsurfacespointer = info.outnumsurfaces;
+
+ // now sort surfaces by texture for faster rendering
+ r_q1bsp_getlightinfo_surfaces = info.model->data_surfaces;
+ if (r_shadow_sortsurfaces.integer)
+ qsort(info.outsurfacelist, info.outnumsurfaces, sizeof(*info.outsurfacelist), R_Q1BSP_GetLightInfo_comparefunc);
}
void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist)
rsurface.texture = R_GetCurrentTexture(surface->texture);
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_NOSHADOW)
continue;
- R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface.modelvertex3f, rsurface.modelelement3i, relativelightorigin, relativelightdirection, lightmins, lightmaxs, surface->mins, surface->maxs);
+ RSurf_PrepareVerticesForBatch(false, false, 1, &surface);
+ R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface.vertex3f, rsurface.modelelement3i, relativelightorigin, relativelightdirection, lightmins, lightmaxs, surface->mins, surface->maxs);
}
- R_Shadow_VolumeFromList(model->surfmesh.num_vertices, model->surfmesh.num_triangles, rsurface.modelvertex3f, model->surfmesh.data_element3i, model->surfmesh.data_neighbor3i, relativelightorigin, relativelightdirection, projectdistance, numshadowmark, shadowmarklist, ent->mins, ent->maxs);
+ R_Shadow_VolumeFromList(model->surfmesh.num_vertices, model->surfmesh.num_triangles, rsurface.vertex3f, model->surfmesh.data_element3i, model->surfmesh.data_neighbor3i, relativelightorigin, relativelightdirection, projectdistance, numshadowmark, shadowmarklist, ent->mins, ent->maxs);
}
if (ent->model->brush.submodel)
GL_PolygonOffset(r_refdef.shadowpolygonfactor, r_refdef.shadowpolygonoffset);
}
--modelsurfacelistindex;
GL_CullFace(rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE ? GL_NONE : r_refdef.view.cullface_back);
- RSurf_PrepareVerticesForBatch(BATCHNEED_VERTEXPOSITION, batchnumsurfaces, batchsurfacelist);
- R_Mesh_PrepareVertices_Position(rsurface.batchnumvertices, rsurface.batchvertexposition, rsurface.batchvertexpositionbuffer);
- RSurf_DrawBatch();
+ RSurf_PrepareVerticesForBatch(false, false, batchnumsurfaces, batchsurfacelist);
+ RSurf_DrawBatch_Simple(batchnumsurfaces, batchsurfacelist);
}
}
int i, j, endsurface;
texture_t *t;
const msurface_t *surface;
- // note: in practice this never actually receives batches
+ // note: in practice this never actually receives batches), oh well
R_Shadow_RenderMode_Begin();
R_Shadow_RenderMode_ActiveLight(rtlight);
R_Shadow_RenderMode_Lighting(false, true, false);
surface = rsurface.modelsurfaces + surfacelist[j];
if (t != surface->texture)
break;
- R_Shadow_RenderLighting(1, &surface);
+ RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
+ R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_firsttriangle, surface->num_triangles, ent->model->surfmesh.data_element3i, ent->model->surfmesh.data_element3s, ent->model->surfmesh.ebo3i, ent->model->surfmesh.ebo3s);
}
}
R_Shadow_RenderMode_End();
{
dp_model_t *model = ent->model;
const msurface_t *surface;
- int i, k, kend, l, endsurface, batchnumsurfaces, texturenumsurfaces;
- const msurface_t **texturesurfacelist;
+ int i, k, kend, l, m, mend, endsurface, batchnumsurfaces, batchnumtriangles, batchfirstvertex, batchlastvertex, batchfirsttriangle;
const int *element3i;
+ static int batchelements[BATCHSIZE*3];
texture_t *tex;
CHECKGLERROR
element3i = rsurface.modelelement3i;
}
if (r_shadow_usingdeferredprepass)
continue;
- texturenumsurfaces = kend - k;
- texturesurfacelist = batchsurfacelist + k;
- R_Shadow_RenderLighting(texturenumsurfaces, texturesurfacelist);
+ batchnumtriangles = 0;
+ batchfirsttriangle = surface->num_firsttriangle;
+ m = 0; // hush warning
+ for (l = k;l < kend;l++)
+ {
+ surface = batchsurfacelist[l];
+ RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
+ for (m = surface->num_firsttriangle, mend = m + surface->num_triangles;m < mend;m++)
+ {
+ if (lighttrispvs && r_test.integer && !CHECKPVSBIT(lighttrispvs, m))
+ continue;
+ if (batchnumtriangles >= BATCHSIZE)
+ {
+ r_refdef.stats.lights_lighttriangles += batchnumtriangles;
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ // use the element buffer if all triangles are consecutive
+ if (m == batchfirsttriangle + batchnumtriangles)
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchfirsttriangle, batchnumtriangles, ent->model->surfmesh.data_element3i, ent->model->surfmesh.data_element3s, ent->model->surfmesh.ebo3i, ent->model->surfmesh.ebo3s);
+ else
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, 0, batchnumtriangles, batchelements, NULL, 0, 0);
+ batchnumtriangles = 0;
+ batchfirsttriangle = m;
+ }
+ batchelements[batchnumtriangles*3+0] = element3i[m*3+0];
+ batchelements[batchnumtriangles*3+1] = element3i[m*3+1];
+ batchelements[batchnumtriangles*3+2] = element3i[m*3+2];
+ batchnumtriangles++;
+ }
+ }
+ if (batchnumtriangles > 0)
+ {
+ r_refdef.stats.lights_lighttriangles += batchnumtriangles;
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ // use the element buffer if all triangles are consecutive
+ if (m == batchfirsttriangle + batchnumtriangles)
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchfirsttriangle, batchnumtriangles, ent->model->surfmesh.data_element3i, ent->model->surfmesh.data_element3s, ent->model->surfmesh.ebo3i, ent->model->surfmesh.ebo3s);
+ else
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, 0, batchnumtriangles, batchelements, NULL, 0, 0);
+ }
}
}
}