/* ================ R_AliasDrawModel ================ */ void R_AliasDrawModel(alight_t *plighting) { finalvert_t finalverts[MAXALIASVERTS + ((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 1]; auxvert_t auxverts[MAXALIASVERTS]; r_amodels_drawn++; // cache align pfinalverts = (finalvert_t *) (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = &auxverts[0]; paliashdr = (aliashdr_t *)Mod_Extradata(currententity->model); pmdl = (mdl_t *)((byte *)paliashdr + paliashdr->model); R_AliasSetupSkin(); R_AliasSetUpTransform(currententity->trivial_accept); R_AliasSetupLighting(plighting); R_AliasSetupFrame(); if (!currententity->colormap) { Sys_Error("R_AliasDrawModel: !currententity->colormap"); } r_affinetridesc.drawtype = (currententity->trivial_accept == 3) && r_recursiveaffinetriangles; if (r_affinetridesc.drawtype) { D_PolysetUpdateTables(); // FIXME: precalc... } else { #if id386 D_Aff8Patch(currententity->colormap); #endif } acolormap = currententity->colormap; if (currententity != &cl.viewent) { ziscale = (float)0x8000 * (float)0x10000; } else { ziscale = (float)0x8000 * (float)0x10000 * 3.0; } if (currententity->trivial_accept) { R_AliasPrepareUnclippedPoints(); } else { R_AliasPreparePoints(); } }
void R_AliasDrawModel (alight_t *plighting) { int size; finalvert_t *finalverts; r_amodels_drawn++; if (!(paliashdr = currententity->model->aliashdr)) paliashdr = Cache_Get (¤tentity->model->cache); pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); size = (CACHE_SIZE - 1) + sizeof (finalvert_t) * (pmdl->numverts + 1) + sizeof (auxvert_t) * pmdl->numverts; finalverts = (finalvert_t *) Hunk_TempAlloc (size); if (!finalverts) Sys_Error ("R_AliasDrawModel: out of memory"); // cache align pfinalverts = (finalvert_t *) (((intptr_t) &finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1]; R_AliasSetupSkin (); R_AliasSetUpTransform (currententity->trivial_accept); R_AliasSetupLighting (plighting); R_AliasSetupFrame (); r_affinetridesc.drawtype = (currententity->trivial_accept == 3) && r_recursiveaffinetriangles; if (!acolormap) acolormap = vid.colormap8; if (r_affinetridesc.drawtype) { D_PolysetUpdateTables (); // FIXME: precalc... } else { #ifdef USE_INTEL_ASM D_Aff8Patch (acolormap); #endif } if (currententity != vr_data.view_model) ziscale = (float) 0x8000 *(float) 0x10000; else ziscale = (float) 0x8000 *(float) 0x10000 *3.0; if (currententity->trivial_accept && pmdl->ident != HEADER_MDL16) R_AliasPrepareUnclippedPoints (); else R_AliasPreparePoints (); if (!currententity->model->aliashdr) Cache_Release (¤tentity->model->cache); }
/* ================ R_AliasDrawModel ================ */ void R_AliasDrawModel(void) { if (r_lerpmodels->integer == 0) currententity->backlerp = 0; if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) r_refdef.xscale = -r_refdef.xscale; /* ** we have to set our frame pointers and transformations before ** doing any real work */ R_AliasSetupFrames(); R_AliasSetUpTransform(); // see if the bounding box lets us trivially reject, also sets // trivial accept status if (R_AliasCheckBBox() == BBOX_TRIVIAL_REJECT) goto exit; // set up the skin and verify it exists R_AliasSetupSkin(); r_amodels_drawn++; R_AliasSetupLighting(); R_AliasSetupBlend(); /* ** compute this_frame and old_frame addresses */ R_AliasSetUpLerpData(currententity->backlerp); if (currententity->flags & RF_DEPTHHACK) s_ziscale = (float)0x8000 * (float)0x10000 * 3.0; else s_ziscale = (float)0x8000 * (float)0x10000; R_AliasPreparePoints(); exit: if ((currententity->flags & (RF_WEAPONMODEL | RF_LEFTHAND)) == (RF_WEAPONMODEL | RF_LEFTHAND)) r_refdef.xscale = -r_refdef.xscale; }
/* ================ R_AliasCheckBBox ================ */ qboolean R_AliasCheckBBox(void) { int i, flags, frame, numv; aliashdr_t *pahdr; float zi, basepts[8][3], v0, v1, frac; finalvert_t *pv0, *pv1, viewpts[16]; auxvert_t *pa0, *pa1, viewaux[16]; maliasframedesc_t *pframedesc; qboolean zclipped, zfullyclipped; unsigned anyclip, allclip; int minz; // expand, rotate, and translate points into worldspace currententity->trivial_accept = 0; pmodel = currententity->model; pahdr = Mod_Extradata(pmodel); pmdl = (mdl_t *)((byte *)pahdr + pahdr->model); R_AliasSetUpTransform(0); // construct the base bounding box for this frame frame = currententity->frame; // TODO: don't repeat this check when drawing? if ((frame >= pmdl->numframes) || (frame < 0)) { Con_DPrintf("No such frame %d %s\n", frame, pmodel->name); frame = 0; } pframedesc = &pahdr->frames[frame]; // x worldspace coordinates basepts[0][0] = basepts[1][0] = basepts[2][0] = basepts[3][0] = (float)pframedesc->bboxmin.v[0]; basepts[4][0] = basepts[5][0] = basepts[6][0] = basepts[7][0] = (float)pframedesc->bboxmax.v[0]; // y worldspace coordinates basepts[0][1] = basepts[3][1] = basepts[5][1] = basepts[6][1] = (float)pframedesc->bboxmin.v[1]; basepts[1][1] = basepts[2][1] = basepts[4][1] = basepts[7][1] = (float)pframedesc->bboxmax.v[1]; // z worldspace coordinates basepts[0][2] = basepts[1][2] = basepts[4][2] = basepts[5][2] = (float)pframedesc->bboxmin.v[2]; basepts[2][2] = basepts[3][2] = basepts[6][2] = basepts[7][2] = (float)pframedesc->bboxmax.v[2]; zclipped = false; zfullyclipped = true; minz = 9999; for (i=0; i<8 ; i++) { R_AliasTransformVector(&basepts[i][0], &viewaux[i].fv[0]); if (viewaux[i].fv[2] < ALIAS_Z_CLIP_PLANE) { // we must clip points that are closer than the near clip plane viewpts[i].flags = ALIAS_Z_CLIP; zclipped = true; } else { if (viewaux[i].fv[2] < minz) { minz = viewaux[i].fv[2]; } viewpts[i].flags = 0; zfullyclipped = false; } } if (zfullyclipped) { return false; // everything was near-z-clipped } numv = 8; if (zclipped) { // organize points by edges, use edges to get new points (possible trivial // reject) for (i=0 ; i<12 ; i++) { // edge endpoints pv0 = &viewpts[aedges[i].index0]; pv1 = &viewpts[aedges[i].index1]; pa0 = &viewaux[aedges[i].index0]; pa1 = &viewaux[aedges[i].index1]; // if one end is clipped and the other isn't, make a new point if (pv0->flags ^ pv1->flags) { frac = (ALIAS_Z_CLIP_PLANE - pa0->fv[2]) / (pa1->fv[2] - pa0->fv[2]); viewaux[numv].fv[0] = pa0->fv[0] + (pa1->fv[0] - pa0->fv[0]) * frac; viewaux[numv].fv[1] = pa0->fv[1] + (pa1->fv[1] - pa0->fv[1]) * frac; viewaux[numv].fv[2] = ALIAS_Z_CLIP_PLANE; viewpts[numv].flags = 0; numv++; } } } // project the vertices that remain after clipping anyclip = 0; allclip = ALIAS_XY_CLIP_MASK; // TODO: probably should do this loop in ASM, especially if we use floats for (i=0 ; i<numv ; i++) { // we don't need to bother with vertices that were z-clipped if (viewpts[i].flags & ALIAS_Z_CLIP) { continue; } zi = 1.0 / viewaux[i].fv[2]; // FIXME: do with chop mode in ASM, or convert to float v0 = (viewaux[i].fv[0] * xscale * zi) + xcenter; v1 = (viewaux[i].fv[1] * yscale * zi) + ycenter; flags = 0; if (v0 < r_refdef.fvrectx) { flags |= ALIAS_LEFT_CLIP; } if (v1 < r_refdef.fvrecty) { flags |= ALIAS_TOP_CLIP; } if (v0 > r_refdef.fvrectright) { flags |= ALIAS_RIGHT_CLIP; } if (v1 > r_refdef.fvrectbottom) { flags |= ALIAS_BOTTOM_CLIP; } anyclip |= flags; allclip &= flags; } if (allclip) { return false; // trivial reject off one side } currententity->trivial_accept = !anyclip & !zclipped; if (currententity->trivial_accept) { if (minz > (r_aliastransition + (pmdl->size * r_resfudge))) { currententity->trivial_accept |= 2; } } return true; }
/* ================ R_AliasDrawModel ================ */ void R_AliasDrawModel(entity_t *currententity, const model_t *currentmodel) { s_pmdl = (dmdl_t *)currentmodel->extradata; if ( r_lerpmodels->value == 0 ) currententity->backlerp = 0; float oldAliasxscale = aliasxscale; float oldAliasyscale = aliasyscale; if ( currententity->flags & RF_WEAPONMODEL ) { if ( r_lefthand->value == 2.0F ) { return; } float gunfov = 2 * tan((float)r_gunfov->value / 360 * M_PI); aliasxscale = ((float)r_refdef.vrect.width / gunfov) * r_aliasuvscale; aliasyscale = aliasxscale; if ( r_lefthand->value == 1.0F ) aliasxscale = -aliasxscale; } /* ** we have to set our frame pointers and transformations before ** doing any real work */ R_AliasSetupFrames(currententity, currentmodel, s_pmdl); R_AliasSetUpTransform(currententity); // see if the bounding box lets us trivially reject, also sets // trivial accept status if ( R_AliasCheckBBox(currententity) == BBOX_TRIVIAL_REJECT ) { if ( currententity->flags & RF_WEAPONMODEL ) { aliasxscale = oldAliasxscale; aliasyscale = oldAliasyscale; } return; } // set up the skin and verify it exists if ( !R_AliasSetupSkin(currententity, currentmodel) ) { R_Printf( PRINT_ALL, "R_AliasDrawModel %s: NULL skin found\n", currentmodel->name); aliasxscale = oldAliasxscale; aliasyscale = oldAliasyscale; return; } r_amodels_drawn++; R_AliasSetupLighting(currententity); /* ** select the proper span routine based on translucency */ // added double damage shell // reordered to handle blending if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM) ) { int color; // added double color = currententity->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM); // reordered, new shells after old shells (so they get overriden) if ( color == RF_SHELL_RED ) r_aliasblendcolor = SHELL_RED_COLOR; else if ( color == RF_SHELL_GREEN ) r_aliasblendcolor = SHELL_GREEN_COLOR; else if ( color == RF_SHELL_BLUE ) r_aliasblendcolor = SHELL_BLUE_COLOR; else if ( color == (RF_SHELL_RED | RF_SHELL_GREEN) ) r_aliasblendcolor = SHELL_RG_COLOR; else if ( color == (RF_SHELL_RED | RF_SHELL_BLUE) ) r_aliasblendcolor = SHELL_RB_COLOR; else if ( color == (RF_SHELL_BLUE | RF_SHELL_GREEN) ) r_aliasblendcolor = SHELL_BG_COLOR; // added this .. it's yellowish else if ( color == (RF_SHELL_DOUBLE) ) r_aliasblendcolor = SHELL_DOUBLE_COLOR; else if ( color == (RF_SHELL_HALF_DAM) ) r_aliasblendcolor = SHELL_HALF_DAM_COLOR; else r_aliasblendcolor = SHELL_WHITE_COLOR; if ( currententity->alpha > 0.33 ) d_pdrawspans = R_PolysetDrawSpansConstant8_66; else d_pdrawspans = R_PolysetDrawSpansConstant8_33; } else if ( currententity->flags & RF_TRANSLUCENT ) { if ( currententity->alpha > 0.66 ) d_pdrawspans = R_PolysetDrawSpans8_Opaque; else if ( currententity->alpha > 0.33 ) d_pdrawspans = R_PolysetDrawSpans8_66; else d_pdrawspans = R_PolysetDrawSpans8_33; } else { d_pdrawspans = R_PolysetDrawSpans8_Opaque; } /* ** compute this_frame and old_frame addresses */ R_AliasSetUpLerpData(currententity, s_pmdl, currententity->backlerp); if (currententity->flags & RF_DEPTHHACK) s_ziscale = (float)0x8000 * (float)SHIFT16XYZ_MULT * 3.0; else s_ziscale = (float)0x8000 * (float)SHIFT16XYZ_MULT; R_AliasPreparePoints(currententity, finalverts, finalverts_max); if ( currententity->flags & RF_WEAPONMODEL ) { aliasxscale = oldAliasxscale; aliasyscale = oldAliasyscale; } }
/* ================ R_AliasDrawModel ================ */ void R_AliasDrawModel (alight_t *plighting) { finalvert_t finalverts[MAXALIASVERTS + ((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 1]; auxvert_t auxverts[MAXALIASVERTS]; // finalvert_t *finalverts; // auxvert_t *auxverts; //Anders> Change malloc to static allocated memory to avoid malloc? // finalverts = malloc( (sizeof(finalvert_t)*MAXALIASVERTS) + (sizeof(finalvert_t)*(((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 1))); // auxverts = malloc( (sizeof(finalvert_t)*MAXALIASVERTS)); GpError("R_AliasDrawModel A",11); r_amodels_drawn++; // cache align pfinalverts = (finalvert_t *) (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); pauxverts = &auxverts[0]; GpError("R_AliasDrawModel B",11); paliashdr = (aliashdr_t *)Mod_Extradata (currententity->model); pmdl = (mdl_t *)((byte *)paliashdr + paliashdr->model); GpError("R_AliasDrawModel C",11); R_AliasSetupSkin (); GpError("R_AliasDrawModel D",11); R_AliasSetUpTransform (currententity->trivial_accept); GpError("R_AliasDrawModel E",11); R_AliasSetupLighting (plighting); GpError("R_AliasDrawModel F",11); R_AliasSetupFrame (); GpError("R_AliasDrawModel G",11); if (!currententity->colormap) Sys_Error ("R_AliasDrawModel: !currententity->colormap"); r_affinetridesc.drawtype = (currententity->trivial_accept == 3) && r_recursiveaffinetriangles; if (r_affinetridesc.drawtype) { GpError("R_AliasDrawModel H",11); D_PolysetUpdateTables (); // FIXME: precalc... } else { #if id386 D_Aff8Patch (currententity->colormap); #endif } acolormap = currententity->colormap; if (currententity != &cl.viewent) ziscale = (float)0x8000 * (float)0x10000; else ziscale = (float)0x8000 * (float)0x10000 * 3.0; if (currententity->trivial_accept){ GpError("R_AliasDrawModel I",11); R_AliasPrepareUnclippedPoints (); } else{ GpError("R_AliasDrawModel J",11); R_AliasPreparePoints (); } // free(finalverts); // free(auxverts); GpError("R_AliasDrawModel end",11); }
void R_AliasDrawModel (alight_t *plighting) #endif { // h2 int mls; int i, j; byte *dest, *source, *sourceA; // h2 finalvert_t finalverts[MAXALIASVERTS + ((CACHE_SIZE - 1) / sizeof(finalvert_t)) + 1]; auxvert_t auxverts[MAXALIASVERTS]; r_amodels_drawn++; // cache align pfinalverts = (finalvert_t *) (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1)); #ifdef INTERPOL7 if(r_lerpmodels->value) pauxverts = &r_auxverts[0]; else pauxverts = &auxverts[0]; #else pauxverts = &auxverts[0]; #endif paliashdr = (aliashdr_t *)Mod_Extradata (currententity->model); pmdl = (mdl_t *)((byte *)paliashdr + paliashdr->model); R_AliasSetupSkin (); #ifdef INTERPOL7 if (r_lerpmodels->value) R_AliasSetUpTransform (0); else R_AliasSetUpTransform (currententity->trivial_accept); // R_AliasSetUpTransform (currententity->trivial_accept); #else R_AliasSetUpTransform (currententity->trivial_accept); #endif if (r_shading->value > 1 && (lightingavailable)) R_AliasSetupLighting_enhanced (plighting); // leilei - further hacked else if (r_shading->value > 1 && !lightingavailable) R_AliasSetupLighting (plighting); // no lighting available so we fall back else if (r_shading->value) R_AliasSetupLighting (plighting); else R_AliasSetupLightingSimple (plighting); #ifdef INTERPOL7 R_AliasSetupFrame (currententity); #else R_AliasSetupFrame (); #endif if (!currententity->colormap) Sys_Error ("R_AliasDrawModel: !currententity->colormap"); if (!coloredlights){ r_affinetridesc.drawtype = (currententity->trivial_accept == 3) && r_recursiveaffinetriangles; } if (r_affinetridesc.drawtype) { D_PolysetUpdateTables (); // FIXME: precalc... } else { #if id386broken D_Aff8Patch (currententity->colormap); #endif } acolormap = currententity->colormap; #ifdef VMTOC // if (viewmodel) // ziscale = (float)0x8000 * (float)0x10000 * 3.0; // else if (viewmodel) ziscale = (float)0x8000 * (float)0x10000 * 3.0; else ziscale = (float)0x8000 * (float)0x10000; #else if (currententity != &cl.viewent) ziscale = (float)0x8000 * (float)0x10000; else ziscale = (float)0x8000 * (float)0x10000 * 3.0; #endif if (currententity->trivial_accept) R_AliasPrepareUnclippedPoints (); else R_AliasPreparePoints (); }