示例#1
0
文件: misc.c 项目: Jenco420/q2pro
/*
===============
R_SetupFrame
===============
*/
void R_SetupFrame(void)
{
    int         i;
    vrect_t     vrect;

    if (r_fullbright->modified) {
        r_fullbright->modified = qfalse;
        D_FlushCaches();    // so all lighting changes
    }

    r_framecount++;


// build the transformation matrix for the given view angles
    VectorCopy(r_newrefdef.vieworg, modelorg);
    VectorCopy(r_newrefdef.vieworg, r_origin);

    AngleVectors(r_newrefdef.viewangles, vpn, vright, vup);

// current viewleaf
    if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) {
        r_viewleaf = BSP_PointLeaf(r_worldmodel->nodes, r_origin);
        r_viewcluster = r_viewleaf->cluster;
    }

    if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER))
        r_dowarp = qtrue;
    else
        r_dowarp = qfalse;

    if (r_dowarp) {
        // warp into off screen buffer
        vrect.x = 0;
        vrect.y = 0;
        vrect.width = r_newrefdef.width < WARP_WIDTH ? r_newrefdef.width : WARP_WIDTH;
        vrect.height = r_newrefdef.height < WARP_HEIGHT ? r_newrefdef.height : WARP_HEIGHT;

        d_viewbuffer = r_warpbuffer;
        d_screenrowbytes = WARP_WIDTH * VID_BYTES;
    } else {
        vrect.x = r_newrefdef.x;
        vrect.y = r_newrefdef.y;
        vrect.width = r_newrefdef.width;
        vrect.height = r_newrefdef.height;

        d_viewbuffer = (void *)vid.buffer;
        d_screenrowbytes = vid.rowbytes;
    }

    R_ViewChanged(&vrect);

// start off with just the four screen edge clip planes
    R_TransformFrustum();
    R_SetUpFrustumIndexes();

// save base values
    VectorCopy(vpn, base_vpn);
    VectorCopy(vright, base_vright);
    VectorCopy(vup, base_vup);

// clear frame counts
    c_faceclip = 0;
    r_polycount = 0;
    r_drawnpolycount = 0;
    r_wholepolycount = 0;
    r_amodels_drawn = 0;
    r_outofsurfaces = 0;
    r_outofedges = 0;

// d_setup
    for (i = 0; i < vid.height; i++) {
        d_spantable[i] = d_viewbuffer + i * d_screenrowbytes;
        d_zspantable[i] = d_pzbuffer + i * d_zwidth;
    }

// clear Z-buffer and color-buffers if we're doing the gallery
    if (r_newrefdef.rdflags & RDF_NOWORLDMODEL) {
        memset(d_pzbuffer, 0xff, vid.width * vid.height * sizeof(d_pzbuffer[0]));
#if 0
        R_DrawFill8(r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*(int)sw_clearcolor->value & 0xff*/0);
#endif
    }

    d_minmip = Cvar_ClampInteger(sw_mipcap, 0, NUM_MIPS - 1);

    for (i = 0; i < (NUM_MIPS - 1); i++)
        d_scalemip[i] = basemip[i] * sw_mipscale->value;
}
示例#2
0
文件: gl_world.c 项目: Bad-ptr/q2pro
static void GL_MarkLeaves( void ) {
    static int lastNodesVisible;
    byte vis1[VIS_MAX_BYTES];
    byte vis2[VIS_MAX_BYTES];
    mleaf_t *leaf;
    mnode_t *node;
    uint_fast32_t *src1, *src2;
    int cluster1, cluster2, longs;
    vec3_t tmp;
    int i;
    bsp_t *bsp = gl_static.world.cache;

    leaf = BSP_PointLeaf( bsp->nodes, glr.fd.vieworg );
    cluster1 = cluster2 = leaf->cluster;
    VectorCopy( glr.fd.vieworg, tmp );
    if( !leaf->contents ) {
        tmp[2] -= 16;   
    } else {
        tmp[2] += 16;   
    }   
    leaf = BSP_PointLeaf( bsp->nodes, tmp );
    if( !( leaf->contents & CONTENTS_SOLID ) ) {
        cluster2 = leaf->cluster;
    }
    
    if( cluster1 == glr.viewcluster1 && cluster2 == glr.viewcluster2 ) {
        goto finish;
    }
        
    if( gl_lockpvs->integer ) {
        goto finish;
    }

    glr.visframe++;
    glr.viewcluster1 = cluster1;
    glr.viewcluster2 = cluster2;

    if( !bsp->vis || gl_novis->integer || cluster1 == -1 ) {
        // mark everything visible
        for( i = 0; i < bsp->numnodes; i++ ) {
            bsp->nodes[i].visframe = glr.visframe;
        }
        for( i = 0; i < bsp->numleafs; i++ ) {
            bsp->leafs[i].visframe = glr.visframe;
        }
        lastNodesVisible = bsp->numnodes;
        goto finish;
    }

    BSP_ClusterVis( bsp, vis1, cluster1, DVIS_PVS );
    if( cluster1 != cluster2 ) {
        BSP_ClusterVis( bsp, vis2, cluster2, DVIS_PVS );
        longs = VIS_FAST_LONGS( bsp );
        src1 = ( uint_fast32_t * )vis1;
        src2 = ( uint_fast32_t * )vis2;
        while( longs-- ) {
            *src1++ |= *src2++;
        }
    }

    lastNodesVisible = 0;
    for( i = 0, leaf = bsp->leafs; i < bsp->numleafs; i++, leaf++ ) {
        cluster1 = leaf->cluster;
        if( cluster1 == -1 ) {
            continue;
        }
        if( Q_IsBitSet( vis1, cluster1 ) ) {
            node = ( mnode_t * )leaf;

            // mark parent nodes visible
            do {
                if( node->visframe == glr.visframe ) {
                    break;
                }
                node->visframe = glr.visframe;
                node = node->parent;
                lastNodesVisible++;
            } while( node );
        }
    }
    
finish:
    c.nodesVisible = lastNodesVisible;

}