private void AddAmbientDrawSurfaces(ViewEntity viewEntity)
{
idRenderEntity def = viewEntity.EntityDef;
idRenderModel model;
idMaterial material;
Surface geometry;
if(def.DynamicModel != null)
{
model = def.DynamicModel;
}
else
{
model = def.Parameters.Model;
}
// add all the surfaces
int total = model.SurfaceCount;
for(int i = 0; i < total; i++)
{
RenderModelSurface surface = model.GetSurface(i);
// for debugging, only show a single surface at a time
if((idE.CvarSystem.GetInteger("r_singleSurface") >= 0) && (i != idE.CvarSystem.GetInteger("r_singleSurface")))
{
continue;
}
geometry = surface.Geometry;
if(geometry == null)
{
continue;
}
else if(geometry.Indexes.Length == 0)
{
continue;
}
material = surface.Material;
material = RemapMaterialBySkin(material, def.Parameters.CustomSkin, def.Parameters.CustomMaterial);
material = GlobalMaterialOverride(material);
if(material == null)
{
continue;
}
else if(material.IsDrawn == false)
{
continue;
}
// debugging tool to make sure we are have the correct pre-calculated bounds
if(idE.CvarSystem.GetBool("r_checkBounds") == true)
{
idConsole.Warning("TODO: r_checkBounds");
/*int j, k;
for ( j = 0 ; j < tri->numVerts ; j++ ) {
for ( k = 0 ; k < 3 ; k++ ) {
if ( tri->verts[j].xyz[k] > tri->bounds[1][k] + CHECK_BOUNDS_EPSILON
|| tri->verts[j].xyz[k] < tri->bounds[0][k] - CHECK_BOUNDS_EPSILON ) {
common->Printf( "bad tri->bounds on %s:%s\n", def->parms.hModel->Name(), shader->GetName() );
break;
}
if ( tri->verts[j].xyz[k] > def->referenceBounds[1][k] + CHECK_BOUNDS_EPSILON
|| tri->verts[j].xyz[k] < def->referenceBounds[0][k] - CHECK_BOUNDS_EPSILON ) {
common->Printf( "bad referenceBounds on %s:%s\n", def->parms.hModel->Name(), shader->GetName() );
break;
}
}
if ( k != 3 ) {
break;
}
}*/
}
// TODO: CullLocalBox
// if ( !R_CullLocalBox( tri->bounds, vEntity->modelMatrix, 5, tr.viewDef->frustum ) ) {
{
def.ViewCount = this.ViewCount;
// make sure we have an ambient cache
if(CreateAmbientCache(geometry, /* TODO: shader->ReceivesLighting() */ false) == false)
{
// don't add anything if the vertex cache was too full to give us an ambient cache
return;
}
// touch it so it won't get purged
//vertexCache.Touch( tri->ambientCache );
/*if ( r_useIndexBuffers.GetBool() && !tri->indexCache ) {
vertexCache.Alloc( tri->indexes, tri->numIndexes * sizeof( tri->indexes[0] ), &tri->indexCache, true );
}
if ( tri->indexCache ) {
vertexCache.Touch( tri->indexCache );
}*/
// add the surface for drawing
AddDrawSurface(geometry, viewEntity, viewEntity.EntityDef.Parameters, material, viewEntity.ScissorRectangle);
// ambientViewCount is used to allow light interactions to be rejected
// if the ambient surface isn't visible at all
geometry.AmbientViewCount = this.ViewCount;
}
}
// add the lightweight decal surfaces
// TODO: decals
/*for ( idRenderModelDecal *decal = def->decals; decal; decal = decal->Next() ) {
decal->AddDecalDrawSurf( vEntity );
}*/
}