/* ============== R_AddAnimSurfaces ============== */ void R_AddAnimSurfaces(trRefEntity_t *ent) { mdsHeader_t *header = tr.currentModel->model.mds; mdsSurface_t *surface; shader_t *shader = 0; int i, fogNum, cull; qboolean personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; // don't add third_person objects if not in a portal // cull the entire model if merged bounding box of both frames // is outside the view frustum. cull = R_CullModel(header, ent); if (cull == CULL_OUT) { return; } // set up lighting now that we know we aren't culled if (!personalModel || r_shadows->integer > 1) { R_SetupEntityLighting(&tr.refdef, ent); } // see if we are in a fog volume fogNum = R_ComputeFogNum(header, ent); surface = ( mdsSurface_t * )((byte *)header + header->ofsSurfaces); for (i = 0 ; i < header->numSurfaces ; i++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t *skin; int hash; int j; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; if (ent->e.renderfx & RF_BLINK) { char *s = va("%s_b", surface->name); // append '_b' for 'blink' hash = Com_HashKey(s, strlen(s)); for (j = 0 ; j < skin->numSurfaces ; j++) { if (hash != skin->surfaces[j]->hash) { continue; } if (!strcmp(skin->surfaces[j]->name, s)) { shader = skin->surfaces[j]->shader; break; } } } if (shader == tr.defaultShader) // blink reference in skin was not found { hash = Com_HashKey(surface->name, sizeof(surface->name)); for (j = 0 ; j < skin->numSurfaces ; j++) { // the names have both been lowercased if (hash != skin->surfaces[j]->hash) { continue; } if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } if (shader == tr.defaultShader) { Ren_Developer("WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name); } else if (shader->defaultShader) { Ren_Developer("WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = R_GetShaderByHandle(surface->shaderIndex); } // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddDrawSurf((void *)surface, shader, fogNum, 0, 0); } surface = ( mdsSurface_t * )((byte *)surface + surface->ofsEnd); } }
void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) { mdrHeader_t *header; mdrSurface_t *surface; mdrLOD_t *lod; shader_t *shader; skin_t *skin; int i, j; int lodnum = 0; int fogNum = 0; int cull; int cubemapIndex; bool personalModel; header = (mdrHeader_t *) tr.currentModel->modelData; personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= header->numFrames; ent->e.oldframe %= header->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ((ent->e.frame >= header->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= header->numFrames) || (ent->e.oldframe < 0) ) { ri.Printf( PRINT_DEVELOPER, "R_MDRAddAnimSurfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_MDRCullModel (header, ent); if ( cull == CULL_OUT ) { return; } // figure out the current LOD of the model we're rendering, and set the lod pointer respectively. lodnum = R_ComputeLOD(ent); // check whether this model has as that many LODs at all. If not, try the closest thing we got. if(header->numLODs <= 0) return; if(header->numLODs <= lodnum) lodnum = header->numLODs - 1; lod = (mdrLOD_t *)( (byte *)header + header->ofsLODs); for(i = 0; i < lodnum; i++) { lod = (mdrLOD_t *) ((byte *) lod + lod->ofsEnd); } // set up lighting if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // fogNum? fogNum = R_MDRComputeFogNum( header, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); surface = (mdrSurface_t *)( (byte *)lod + lod->ofsSurfaces ); for ( i = 0 ; i < lod->numSurfaces ; i++ ) { if(ent->e.customShader) shader = R_GetShaderByHandle(ent->e.customShader); else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin = R_GetSkinByHandle(ent->e.customSkin); shader = tr.defaultShader; for(j = 0; j < skin->numSurfaces; j++) { if (!strcmp(skin->surfaces[j].name, surface->name)) { shader = skin->surfaces[j].shader; break; } } } else if(surface->shaderIndex > 0) shader = R_GetShaderByHandle( surface->shaderIndex ); else shader = tr.defaultShader; // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t*)surface, tr.shadowShader, 0, false, false, 0 ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t*)surface, tr.projectionShadowShader, 0, false, false, 0 ); } if (!personalModel) R_AddDrawSurf( (surfaceType_t*)surface, shader, fogNum, false, false, cubemapIndex ); surface = (mdrSurface_t *)( (byte *)surface + surface->ofsEnd ); } }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces( trRefEntity_t *ent ) { int i; md3Header_t *header = 0; md3Surface_t *surface = 0; md3Shader_t *md3Shader = 0; shader_t *shader = 0; shader_t *main_shader = 0; int cull; int lod; int fogNum; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; if ( ent->e.renderfx & RF_CAP_FRAMES) { if (ent->e.frame > tr.currentModel->md3[0]->numFrames-1) ent->e.frame = tr.currentModel->md3[0]->numFrames-1; if (ent->e.oldframe > tr.currentModel->md3[0]->numFrames-1) ent->e.oldframe = tr.currentModel->md3[0]->numFrames-1; } else if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= tr.currentModel->md3[0]->numFrames; ent->e.oldframe %= tr.currentModel->md3[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= tr.currentModel->md3[0]->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->md3[0]->numFrames) || (ent->e.oldframe < 0) ) { VID_Printf (PRINT_ALL, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD( ent ); header = tr.currentModel->md3[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel ( header, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // #ifdef VV_LIGHTING if ( !personalModel ) { VVLightMan.R_SetupEntityLighting( &tr.refdef, ent ); #else if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); #endif } // // see if we are in a fog volume // fogNum = R_ComputeFogNum( header, ent ); // // draw all surfaces // main_shader = R_GetShaderByHandle( ent->e.customShader ); surface = (md3Surface_t *)( (byte *)header + header->ofsSurfaces ); for ( i = 0 ; i < header->numSurfaces ; i++ ) { if ( ent->e.customShader ) {// a little more efficient shader = main_shader; } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; int j; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; for ( j = 0 ; j < skin->numSurfaces ; j++ ) { // the names have both been lowercased if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) { shader = skin->surfaces[j]->shader; break; } } } else if ( surface->numShaders <= 0 ) { shader = tr.defaultShader; } else { md3Shader = (md3Shader_t *) ( (byte *)surface + surface->ofsShaders ); md3Shader += ent->e.skinNum % surface->numShaders; shader = tr.shaders[ md3Shader->shaderIndex ]; } // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel && r_shadows->integer == 2 #ifndef VV_LIGHTING && fogNum == 0 #endif && (ent->e.renderfx & RF_SHADOW_PLANE ) && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t *)surface, tr.shadowShader, 0, qfalse ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (surfaceType_t *)surface, tr.projectionShadowShader, 0, qfalse ); } // don't add third_person objects if not viewing through a portal if ( !personalModel ) { #ifdef VV_LIGHTING int dlightBits = ( ent->dlightBits != 0 ); R_AddDrawSurf( (surfaceType_t *)surface, shader, fogNum, dlightBits ); #else R_AddDrawSurf( (surfaceType_t *)surface, shader, fogNum, qfalse ); #endif } surface = (md3Surface_t *)( (byte *)surface + surface->ofsEnd ); } }
/* ================= R_AddMDCSurfaces ================= */ void R_AddMDCSurfaces(trRefEntity_t *ent) { int i; mdcHeader_t *header = 0; mdcSurface_t *surface = 0; md3Shader_t *md3Shader = 0; shader_t *shader = 0; int cull; int lod; int fogNum; qboolean personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; // don't add third_person objects if not in a portal if (ent->e.renderfx & RF_WRAP_FRAMES) { ent->e.frame %= tr.currentModel->model.mdc[0]->numFrames; ent->e.oldframe %= tr.currentModel->model.mdc[0]->numFrames; } // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. if ((ent->e.frame >= tr.currentModel->model.mdc[0]->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->model.mdc[0]->numFrames) || (ent->e.oldframe < 0)) { ri.Printf(PRINT_DEVELOPER, "R_AddMDCSurfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name); ent->e.frame = 0; ent->e.oldframe = 0; } // compute LOD if (ent->e.renderfx & RF_FORCENOLOD) { lod = 0; } else { lod = R_ComputeLOD(ent); } header = tr.currentModel->model.mdc[lod]; // cull the entire model if merged bounding box of both frames // is outside the view frustum. cull = R_CullModel(header, ent); if (cull == CULL_OUT) { return; } // set up lighting now that we know we aren't culled if (!personalModel || r_shadows->integer > 1) { R_SetupEntityLighting(&tr.refdef, ent); } // see if we are in a fog volume fogNum = R_ComputeFogNum(header, ent); // draw all surfaces surface = ( mdcSurface_t * )((byte *)header + header->ofsSurfaces); for (i = 0 ; i < header->numSurfaces ; i++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t *skin; int hash; int j; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; // added blink if (ent->e.renderfx & RF_BLINK) { char *s = va("%s_b", surface->name); // append '_b' for 'blink' hash = Com_HashKey(s, strlen(s)); for (j = 0 ; j < skin->numSurfaces ; j++) { if (hash != skin->surfaces[j]->hash) { continue; } if (!strcmp(skin->surfaces[j]->name, s)) { shader = skin->surfaces[j]->shader; break; } } } if (shader == tr.defaultShader) // blink reference in skin was not found { hash = Com_HashKey(surface->name, sizeof(surface->name)); for (j = 0 ; j < skin->numSurfaces ; j++) { // the names have both been lowercased if (hash != skin->surfaces[j]->hash) { continue; } if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } } else if (surface->numShaders <= 0) { shader = tr.defaultShader; } else { md3Shader = ( md3Shader_t * )((byte *)surface + surface->ofsShaders); md3Shader += ent->e.skinNum % surface->numShaders; shader = tr.shaders[md3Shader->shaderIndex]; } // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if (!personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & (RF_NOSHADOW | RF_DEPTHHACK)) && shader->sort == SS_OPAQUE) { R_AddDrawSurf((void *)surface, tr.shadowShader, 0, 0, 0); } // projection shadows work fine with personal models if (r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE) && shader->sort == SS_OPAQUE) { R_AddDrawSurf((void *)surface, tr.projectionShadowShader, 0, 0, 0); } // for testing polygon shadows (on /all/ models) if (r_shadows->integer == 4) { R_AddDrawSurf((void *)surface, tr.projectionShadowShader, 0, 0, 0); } // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddDrawSurf((void *)surface, shader, fogNum, 0, 0); } surface = ( mdcSurface_t * )((byte *)surface + surface->ofsEnd); } }
/* ============== R_AddMD5Surfaces ============== */ void R_AddMD5Surfaces(trRefEntity_t* ent) { md5Model_t* model; md5Surface_t* surface; shader_t* shader; int i; bool personalModel; int fogNum; model = tr.currentModel->md5; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; // cull the entire model if merged bounding box of both frames // is outside the view frustum R_CullMD5(ent); if (ent->cull == CULL_OUT) { return; } // set up world bounds for light intersection tests R_SetupEntityWorldBounds(ent); // set up lighting now that we know we aren't culled if (!personalModel || r_shadows->integer > SHADOWING_BLOB) { R_SetupEntityLighting(&tr.refdef, ent, nullptr); } // see if we are in a fog volume fogNum = R_FogWorldBox(ent->worldBounds); if (!r_vboModels->integer || !model->numVBOSurfaces || (!glConfig2.vboVertexSkinningAvailable && ent->e.skeleton.type == SK_ABSOLUTE)) { // finally add surfaces for (i = 0, surface = model->surfaces; i < model->numSurfaces; i++, surface++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t* skin; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; // FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces if (i >= 0 && i < skin->numSurfaces && skin->surfaces[i]) { shader = skin->surfaces[i]->shader; } if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = R_GetShaderByHandle(surface->shaderIndex); if (ent->e.altShaderIndex > 0 && ent->e.altShaderIndex < MAX_ALTSHADERS && shader->altShader[ent->e.altShaderIndex].index) { shader = R_GetShaderByHandle( shader->altShader[ent->e.altShaderIndex].index); } } // we will add shadows even if the main object isn't visible in the view // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddDrawSurf((surfaceType_t*) surface, shader, -1, fogNum); } } } else { int i; srfVBOMD5Mesh_t* vboSurface; shader_t* shader; for (i = 0; i < model->numVBOSurfaces; i++) { vboSurface = model->vboSurfaces[i]; if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t* skin; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; // FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces if (vboSurface->skinIndex >= 0 && vboSurface->skinIndex < skin->numSurfaces && skin->surfaces[vboSurface->skinIndex]) { shader = skin->surfaces[vboSurface->skinIndex]->shader; } if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = vboSurface->shader; } // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddDrawSurf((surfaceType_t*) vboSurface, shader, -1, fogNum); } } } }
/* ================= R_AddMD5Interactions ================= */ void R_AddMD5Interactions(trRefEntity_t* ent, trRefLight_t* light, interactionType_t iaType) { int i; md5Model_t* model; md5Surface_t* surface; shader_t* shader = 0; bool personalModel; byte cubeSideBits = CUBESIDE_CLIPALL; // cull the entire model if merged bounding box of both frames // is outside the view frustum and we don't care about proper shadowing if (ent->cull == CULL_OUT) { iaType = (interactionType_t)(iaType & ~IA_LIGHT); } if (!iaType) { return; } // avoid drawing of certain objects #if defined(USE_REFENTITY_NOSHADOWID) if (light->l.inverseShadows) { if ((iaType & IA_SHADOW) && (light->l.noShadowID && (light->l.noShadowID != ent->e.noShadowID))) { return; } } else { if ((iaType & IA_SHADOW) && (light->l.noShadowID && (light->l.noShadowID == ent->e.noShadowID))) { return; } } #endif // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; model = tr.currentModel->md5; // do a quick AABB cull if (!BoundsIntersect(light->worldBounds[0], light->worldBounds[1], ent->worldBounds[0], ent->worldBounds[1])) { tr.pc.c_dlightSurfacesCulled += model->numSurfaces; return; } // do a more expensive and precise light frustum cull if (!r_noLightFrustums->integer) { if (R_CullLightWorldBounds(light, ent->worldBounds) == CULL_OUT) { tr.pc.c_dlightSurfacesCulled += model->numSurfaces; return; } } cubeSideBits = R_CalcLightCubeSideBits(light, ent->worldBounds); if (!r_vboModels->integer || !model->numVBOSurfaces || (!glConfig2.vboVertexSkinningAvailable && ent->e.skeleton.type == SK_ABSOLUTE)) { // generate interactions with all surfaces for (i = 0, surface = model->surfaces; i < model->numSurfaces; i++, surface++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t* skin; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; // FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces if (i >= 0 && i < skin->numSurfaces && skin->surfaces[i]) { shader = skin->surfaces[i]->shader; } if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = R_GetShaderByHandle(surface->shaderIndex); } // skip all surfaces that don't matter for lighting only pass if (shader->isSky || (!shader->interactLight && shader->noShadows)) { continue; } // we will add shadows even if the main object isn't visible in the view // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddLightInteraction(light, (surfaceType_t*) surface, shader, cubeSideBits, iaType); tr.pc.c_dlightSurfaces++; } } } else { int i; srfVBOMD5Mesh_t* vboSurface; shader_t* shader; for (i = 0; i < model->numVBOSurfaces; i++) { vboSurface = model->vboSurfaces[i]; if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t* skin; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; // FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces if (i >= 0 && i < skin->numSurfaces && skin->surfaces[i]) { shader = skin->surfaces[i]->shader; } if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = vboSurface->shader; } // skip all surfaces that don't matter for lighting only pass if (shader->isSky || (!shader->interactLight && shader->noShadows)) { continue; } // don't add third_person objects if not viewing through a portal if (!personalModel) { R_AddLightInteraction(light, (surfaceType_t*) vboSurface, shader, cubeSideBits, iaType); tr.pc.c_dlightSurfaces++; } } } }
/* ================= R_AddIQMSurfaces Add all surfaces of this model ================= */ void R_AddIQMSurfaces( trRefEntity_t *ent ) { IQModel_t *IQModel; srfIQModel_t *surface; int i, j; bool personalModel; int fogNum; shader_t *shader; skin_t *skin; IQModel = tr.currentModel->iqm; surface = IQModel->surfaces; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && tr.viewParms.portalLevel == 0; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // R_CullIQM( ent ); if ( ent->cull == cullResult_t::CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > Util::ordinal(shadowingMode_t::SHADOWING_BLOB) ) { R_SetupEntityLighting( &tr.refdef, ent, nullptr ); } // // see if we are in a fog volume // fogNum = R_FogWorldBox( ent->worldBounds ); for ( i = 0 ; i < IQModel->num_surfaces ; i++ ) { if(ent->e.customShader) shader = R_GetShaderByHandle( ent->e.customShader ); else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin = R_GetSkinByHandle(ent->e.customSkin); shader = tr.defaultShader; if (surface->name && *surface->name) { for(j = 0; j < skin->numSurfaces; j++) { if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } if ( shader == tr.defaultShader && i >= 0 && i < skin->numSurfaces && skin->surfaces[ i ] ) { shader = skin->surfaces[ i ]->shader; } } else { shader = surface->shader; if ( ent->e.altShaderIndex > 0 && ent->e.altShaderIndex < MAX_ALTSHADERS && shader->altShader[ ent->e.altShaderIndex ].index ) { shader = R_GetShaderByHandle( shader->altShader[ ent->e.altShaderIndex ].index ); } } // we will add shadows even if the main object isn't visible in the view if( !personalModel ) { R_AddDrawSurf( ( surfaceType_t *)surface, shader, -1, fogNum ); } surface++; } }
/* ================= R_AddIQMSurfaces Add all surfaces of this model ================= */ void R_AddIQMSurfaces( trRefEntity_t *ent ) { iqmData_t *data; srfIQModel_t *surface; int i, j; qboolean personalModel; int cull; int fogNum; shader_t *shader; skin_t *skin; data = tr.currentModel->modelData; surface = data->surfaces; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= data->num_frames; ent->e.oldframe %= data->num_frames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= data->num_frames) || (ent->e.frame < 0) || (ent->e.oldframe >= data->num_frames) || (ent->e.oldframe < 0) ) { ri.Printf( PRINT_DEVELOPER, "R_AddIQMSurfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullIQM ( data, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeIQMFogNum( data, ent ); for ( i = 0 ; i < data->num_surfaces ; i++ ) { if(ent->e.customShader) shader = R_GetShaderByHandle( ent->e.customShader ); else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin = R_GetSkinByHandle(ent->e.customSkin); shader = tr.defaultShader; for(j = 0; j < skin->numSurfaces; j++) { if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } else { shader = surface->shader; } // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, 0 ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, 0 ); } if( !personalModel ) { R_AddDrawSurf( (void *)surface, shader, fogNum, 0 ); } surface++; } }
/* ============== R_AddMD5Surfaces ============== */ void R_AddMD5Surfaces( trRefEntity_t *ent ) { md5Model_t *model; md5Surface_t *surface; shader_t *shader; int i; qboolean personalModel; int fogNum; model = tr.currentModel->model.md5; // don't add third_person objects if not in a portal personalModel = ( ent->e.renderfx & RF_THIRD_PERSON ) && !tr.viewParms.isPortal; // cull the entire model if merged bounding box of both frames // is outside the view frustum if ( R_CullMD5( ent ) == CULL_OUT ) { return; } // set up lighting now that we know we aren't culled if ( !personalModel || r_shadows->integer > SHADOWING_BLOB ) { R_SetupEntityLighting( &tr.refdef, ent ); } // see if we are in a fog volume fogNum = 0; //R_FogWorldBox(ent->worldBounds); // finally add surfaces for ( i = 0, surface = model->surfaces; i < model->numSurfaces; i++, surface++ ) { if ( ent->e.customShader ) { shader = R_GetShaderByHandle( ent->e.customShader ); } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; // FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces if ( i >= 0 && i < skin->numSurfaces && skin->surfaces[ i ] ) { shader = skin->surfaces[ i ]->shader; } if ( shader == tr.defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name ); } else if ( shader->defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name ); } } else { shader = R_GetShaderByHandle( surface->shaderIndex ); } // we will add shadows even if the main object isn't visible in the view // don't add third_person objects if not viewing through a portal if ( !personalModel ) { R_AddDrawSurf( ( void * ) surface, shader, fogNum, 0, 0 ); } } }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces(trRefEntity_t *ent) { int i; mdvModel_t *model = NULL; mdvSurface_t *surface = NULL; shader_t *shader = NULL; int cull; int lod; int fogNum; int cubemapIndex; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if (ent->e.renderfx & RF_WRAP_FRAMES) { ent->e.frame %= tr.currentModel->mdv[0]->numFrames; ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ((ent->e.frame >= tr.currentModel->mdv[0]->numFrames) || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames) || (ent->e.oldframe < 0)) { ri.Printf(PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD(ent); model = tr.currentModel->mdv[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel (model, ent); if (cull == CULL_OUT) { return; } // // set up lighting now that we know we aren't culled // if (!personalModel || r_shadows->integer > 1) { R_SetupEntityLighting(&tr.refdef, ent); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum(model, ent); cubemapIndex = R_CubemapForPoint(ent->e.origin); // // draw all surfaces // surface = model->surfaces; for (i = 0 ; i < model->numSurfaces ; i++) { if (ent->e.customShader) { shader = R_GetShaderByHandle(ent->e.customShader); } else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) { skin_t *skin; int j; skin = R_GetSkinByHandle(ent->e.customSkin); // match the surface name to something in the skin file shader = tr.defaultShader; //----(SA) added blink if (ent->e.renderfx & RF_BLINK) { const char *s = va("%s_b", surface->name); // append '_b' for 'blink' for (j = 0 ; j < skin->numSurfaces ; j++) { if (!strcmp(skin->surfaces[j]->name, s)) { shader = skin->surfaces[j]->shader; break; } } } if (shader == tr.defaultShader) { // blink reference in skin was not found for (j = 0 ; j < skin->numSurfaces ; j++) { // the names have both been lowercased if (!strcmp(skin->surfaces[j]->name, surface->name)) { shader = skin->surfaces[j]->shader; break; } } } //----(SA) end if (shader == tr.defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name); } else if (shader->defaultShader) { ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } //} else if (surface->numShaders <= 0) { //shader = tr.defaultShader; } else { //md3Shader = (md3Shader_t *) ((byte *)surface + surface->ofsShaders); //md3Shader += ent->e.skinNum % surface->numShaders; //shader = tr.shaders[ md3Shader->shaderIndex ]; shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ]; } // for testing polygon shadows (on /all/ models) if (r_shadows->integer == 4) { R_AddDrawSurf((void *)surface, tr.projectionShadowShader, 0, qfalse, qfalse, 0); } // don't add third_person objects if not viewing through a portal if(!personalModel) { srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i]; R_AddDrawSurf((void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex); } surface++; } }
/*============================================================== R_AddMyGhoulSurfaces This is where the system tosses MOD_GLM, surfaces are added here ==============================================================*/ void R_AddMyGhoulSurfaces( trRefEntity_t *ent ) { //model_t *animModel; //glaHeader_t *gla; glmHeader_t *header; // model_t *model_anims; glmHeader_t *anims = 0; //glmSurface_t *surf; glmSurface_t *surface; glmSurfHierarchy_t *surfh; //mg_animstate_t *as = NULL; int animated = 0; glmLOD_t *lod; glmLODSurfOffset_t *lod_surf_ofs; shader_t *shader; int i; //int cull; //int lod; int fogNum = 0; qboolean personalModel; int newQuatDeal = 0; //mygBQArr_t *oldframe; //mygBQArr_t *newframe; //mygBQArr_t *resframe; //mygBoneArr_t *pose; //vec3_t trans; //int bonewatch = 1; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; if( personalModel ) { //ent->needZFail = qtrue; } header = tr.currentModel->modelData; if( header->animIndex != 0 ) { #if 0 model_anims = R_GetModelByHandle( header->animIndex ); if( model_anims->type == MOD_GLA ) { anims = model_anims->gla; as = RE_AS_Fetch( ent->e.frame ); } if( as->index == 0 ) { anims = 0; animated = 0; } else { if( as->index != 0 ) { animated = 1; } } #endif } else { animated = 0; } // printf( "(GLM) myghoul model is " ); // if(personalModel) printf( "personal model, " ); // if(animated) printf( "animated." ); #if 0 if( animated ) { AnimStateAnimsPop( as, anims ); MG_InheritQuats( anims, (mgQuat_t*)as->resframe->quat, 0 ); if( !newQuatDeal ) MG_MatsPopulate( anims, (mgQuat_t*)as->resframe->quat, as->pose ); } #endif // compute LOD //lod = R_ComputeLOD( ent ); // cull the entire model if merged bounding box of both frames // is outside the view frustum. /*cull = R_CullModel ( header, ent ); if ( cull == CULL_OUT ) { return; }*/ // set up lighting now that we know we aren't culled if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // see if we are in a fog volume //fogNum = R_ComputeFogNum( header, ent ); //ri.Printf( PRINT_DEVELOPER, "(I) Adding this MG Model\n" ); lod = (glmLOD_t *)( (byte *)header + header->ofsLODs ); lod_surf_ofs = ( glmLODSurfOffset_t *) ((byte *)lod + 4 ); surfh = (glmSurfHierarchy_t *) ( (byte *)header + header->ofsSurfHierarchy ); surface = (glmSurface_t *)( (byte *)lod_surf_ofs + lod_surf_ofs->offsets[0] ); for ( i = 0 ; i < header->numSurfaces ; i++ ) { if( surfh->name[0] != '*' && strcmp( "stupidtriangle_off", surfh->name ) ) { if ( ent->e.customShader ) { shader = R_GetShaderByHandle( ent->e.customShader ); } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; int j; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; for ( j = 0 ; j < skin->numSurfaces ; j++ ) { // the names have both been lowercased if ( !strcmp( skin->surfaces[j]->name, surfh->name ) ) { shader = skin->surfaces[j]->shader; break; } } if (shader == tr.defaultShader) { //ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surfh->name, skin->name); } else if (shader->defaultShader) { //ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name); } } else { shader = R_GetShaderByHandle( surfh->shaderIndex ); } // we will add shadows even if the main object isn't visible in the view // stencil shadows can't do personal models unless I polyhedron clip if ( !personalModel ) { R_AddDrawSurf( (void *)surface, shader, 0, qfalse ); } if ( !personalModel && r_shadows->integer == 2 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse ); } if ( r_shadows->integer == 4 && fogNum == 0 && !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse ); } // projection shadows work fine with personal models if ( r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE ) && shader->sort == SS_OPAQUE ) { R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, qfalse ); } } surface = (glmSurface_t *)( (byte *)surface + surface->ofsEnd ); surfh = (glmSurfHierarchy_t *) ( (byte *)&surfh->childIndexes[surfh->numChildren] ); } }
/* ================= R_AddMD3Surfaces ================= */ void R_AddMD3Surfaces( trRefEntity_t *ent ) { int i; mdvModel_t *model = NULL; mdvSurface_t *surface = NULL; shader_t *shader = NULL; int cull; int lod; int fogNum; int cubemapIndex; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))); if ( ent->e.renderfx & RF_WRAP_FRAMES ) { ent->e.frame %= tr.currentModel->mdv[0]->numFrames; ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames; } // // Validate the frames so there is no chance of a crash. // This will write directly into the entity structure, so // when the surfaces are rendered, they don't need to be // range checked again. // if ( (ent->e.frame >= tr.currentModel->mdv[0]->numFrames) || ( ent->e.frame < 0 ) || (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames) || ( ent->e.oldframe < 0 ) ) { ri.Printf( PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n", ent->e.oldframe, ent->e.frame, tr.currentModel->name ); ent->e.frame = 0; ent->e.oldframe = 0; } // // compute LOD // lod = R_ComputeLOD( ent ); model = tr.currentModel->mdv[lod]; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel ( model, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum( model, ent ); cubemapIndex = R_CubemapForPoint(ent->e.origin); // // draw all surfaces // surface = model->surfaces; for ( i = 0 ; i < model->numSurfaces ; i++ ) { int j; //----(SA) blink will change to be an overlay rather than replacing the head texture. // think of it like batman's mask. the polygons that have eye texture are duplicated // and the 'lids' rendered with polygonoffset shader parm over the top of the open eyes. this gives // minimal overdraw/alpha blending/texture use without breaking the model and causing seams if ( !Q_stricmp( surface->name, "h_blink" ) ) { if ( !( ent->e.renderfx & RF_BLINK ) ) { //surface = ( md3Surface_t * )( (byte *)surface + surface->ofsEnd ); //surface++; continue; } } //----(SA) end if ( ent->e.customShader ) { shader = R_GetShaderByHandle( ent->e.customShader ); } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; for ( j = 0 ; j < skin->numSurfaces ; j++ ) { // the names have both been lowercased if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) { shader = skin->surfaces[j]->shader; break; } } if ( shader == tr.defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name ); } else if ( shader->defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name ); } //} else if ( surface->numShaders <= 0 ) { //shader = tr.defaultShader; } else { //md3Shader = ( md3Shader_t * )( (byte *)surface + surface->ofsShaders ); //md3Shader += ent->e.skinNum % surface->numShaders; shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ]; } // don't add third_person objects if not viewing through a portal if ( !personalModel ) { // GR - tessellate according to model capabilities srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i]; R_AddDrawSurf( (void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex, tr.currentModel->ATI_tess ); } surface++; } }
/* ============== R_AddAnimSurfaces ============== */ void R_AddAnimSurfaces( trRefEntity_t *ent ) { mdsHeader_t *header; mdsSurface_t *surface; shader_t *shader = 0; int i, fogNum, cull; qboolean personalModel; // don't add third_person objects if not in a portal personalModel = ( ent->e.renderfx & RF_THIRD_PERSON ) && !tr.viewParms.isPortal; header = tr.currentModel->mds; // // cull the entire model if merged bounding box of both frames // is outside the view frustum. // cull = R_CullModel( header, ent ); if ( cull == CULL_OUT ) { return; } // // set up lighting now that we know we aren't culled // if ( !personalModel || r_shadows->integer > 1 ) { R_SetupEntityLighting( &tr.refdef, ent ); } // // see if we are in a fog volume // fogNum = R_ComputeFogNum( header, ent ); surface = ( mdsSurface_t * )( (byte *)header + header->ofsSurfaces ); for ( i = 0 ; i < header->numSurfaces ; i++ ) { int j; //----(SA) blink will change to be an overlay rather than replacing the head texture. // think of it like batman's mask. the polygons that have eye texture are duplicated // and the 'lids' rendered with polygonoffset over the top of the open eyes. this gives // minimal overdraw/alpha blending/texture use without breaking the model and causing seams if ( !Q_stricmp( surface->name, "h_blink" ) ) { if ( !( ent->e.renderfx & RF_BLINK ) ) { surface = ( mdsSurface_t * )( (byte *)surface + surface->ofsEnd ); continue; } } //----(SA) end if ( ent->e.customShader ) { shader = R_GetShaderByHandle( ent->e.customShader ); } else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) { skin_t *skin; skin = R_GetSkinByHandle( ent->e.customSkin ); // match the surface name to something in the skin file shader = tr.defaultShader; for ( j = 0 ; j < skin->numSurfaces ; j++ ) { // the names have both been lowercased if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) { shader = skin->surfaces[j]->shader; break; } } if ( shader == tr.defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name ); } else if ( shader->defaultShader ) { ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name ); } } else { shader = R_GetShaderByHandle( surface->shaderIndex ); } // don't add third_person objects if not viewing through a portal if ( !personalModel ) { // GR - always tessellate these objects R_AddDrawSurf( (void *)surface, shader, fogNum, qfalse, ATI_TESS_TRUFORM ); } surface = ( mdsSurface_t * )( (byte *)surface + surface->ofsEnd ); } }