Exemplo n.º 1
0
/*
 * R_SortBspSurfacesArrays_
 */
static void R_SortBspSurfacesArrays_(r_bsp_surfaces_t *surfs) {
	unsigned int i, j;

	for (i = 0; i < surfs->count; i++) {

		const int texnum = surfs->surfaces[i]->texinfo->image->texnum;

		R_SurfaceToSurfaces(r_sorted_surfaces[texnum], surfs->surfaces[i]);
	}

	surfs->count = 0;

	for (i = 0; i < r_num_images; i++) {

		r_bsp_surfaces_t *sorted = r_sorted_surfaces[r_images[i].texnum];

		if (sorted && sorted->count) {

			for (j = 0; j < sorted->count; j++)
				R_SurfaceToSurfaces(surfs, sorted->surfaces[j]);

			sorted->count = 0;
		}
	}
}
Exemplo n.º 2
0
static void R_LoadSurfacesArrays_ (model_t *mod)
{
	mBspSurface_t *surf, *s;
	int i, ns;

	/* allocate the surfaces array structures */
	for (i = 0; i < NUM_SURFACES_ARRAYS; i++)
		mod->bsp.sorted_surfaces[i] = (mBspSurfaces_t *)Mem_PoolAlloc(sizeof(mBspSurfaces_t), vid_modelPool, 0);

	/* resolve the start surface and total surface count */
	if (mod->type == mod_bsp) {  /* world model */
		s = mod->bsp.surfaces;
		ns = mod->bsp.numsurfaces;
	} else {  /* submodels */
		s = &mod->bsp.surfaces[mod->bsp.firstmodelsurface];
		ns = mod->bsp.nummodelsurfaces;
	}

	/* determine the maximum counts for each rendered type in order to
	 * allocate only what is necessary for the specified model */
	for (i = 0, surf = s; i < ns; i++, surf++) {
		const mBspTexInfo_t *texinfo = surf->texinfo;
		const material_t *material = &texinfo->image->material;
		if (texinfo->flags & (SURF_BLEND33 | SURF_BLEND66)) {
			if (texinfo->flags & SURF_WARP)
				mod->bsp.blend_warp_surfaces->count++;
			else
				mod->bsp.blend_surfaces->count++;
		} else {
			if (texinfo->flags & SURF_WARP)
				mod->bsp.opaque_warp_surfaces->count++;
			else if (texinfo->flags & SURF_ALPHATEST)
				mod->bsp.alpha_test_surfaces->count++;
			else
				mod->bsp.opaque_surfaces->count++;
		}

		if (material->flags & STAGE_RENDER)
			mod->bsp.material_surfaces->count++;

		if (material->flags & STAGE_FLARE)
			mod->bsp.flare_surfaces->count++;
	}

	/* allocate the surfaces pointers based on the counts */
	for (i = 0; i < NUM_SURFACES_ARRAYS; i++) {
		mBspSurfaces_t *surfaces = mod->bsp.sorted_surfaces[i];
		if (surfaces->count) {
			surfaces->surfaces = (mBspSurface_t **)Mem_PoolAlloc(sizeof(*surfaces) * surfaces->count, vid_modelPool, 0);
			surfaces->count = 0;
		}
	}

	/* iterate the surfaces again, populating the allocated arrays based
	 * on primary render type */
	for (i = 0, surf = s; i < ns; i++, surf++) {
		const mBspTexInfo_t *texinfo = surf->texinfo;
		const material_t *material = &texinfo->image->material;
		if (texinfo->flags & (SURF_BLEND33 | SURF_BLEND66)) {
			if (texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(mod->bsp.blend_warp_surfaces, surf);
			else
				R_SurfaceToSurfaces(mod->bsp.blend_surfaces, surf);
		} else {
			if (texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(mod->bsp.opaque_warp_surfaces, surf);
			else if (texinfo->flags & SURF_ALPHATEST)
				R_SurfaceToSurfaces(mod->bsp.alpha_test_surfaces, surf);
			else
				R_SurfaceToSurfaces(mod->bsp.opaque_surfaces, surf);
		}

		if (material->flags & STAGE_RENDER)
			R_SurfaceToSurfaces(mod->bsp.material_surfaces, surf);

		if (material->flags & STAGE_FLARE)
			R_SurfaceToSurfaces(mod->bsp.flare_surfaces, surf);
	}

	/* now sort them by texture */
	R_SortSurfacesArrays(mod);
}
Exemplo n.º 3
0
/*
 * R_LoadBspSurfacesArrays_
 */
static void R_LoadBspSurfacesArrays_(r_model_t *mod) {
	r_bsp_surface_t *surf, *s;
	int i, ns;

	// allocate the surfaces array structures
	for (i = 0; i < NUM_SURFACES_ARRAYS; i++)
		mod->sorted_surfaces[i] = (r_bsp_surfaces_t *) R_HunkAlloc(
				sizeof(r_bsp_surfaces_t));

	// resolve the start surface and total surface count
	if (mod->type == mod_bsp) { // world model
		s = mod->surfaces;
		ns = mod->num_surfaces;
	} else { // submodels
		s = &mod->surfaces[mod->first_model_surface];
		ns = mod->num_model_surfaces;
	}

	// determine the maximum counts for each rendered type in order to
	// allocate only what is necessary for the specified model
	for (i = 0, surf = s; i < ns; i++, surf++) {

		if (surf->texinfo->flags & SURF_SKY) {
			mod->sky_surfaces->count++;
			continue;
		}

		if (surf->texinfo->flags & (SURF_BLEND_33 | SURF_BLEND_66)) {
			if (surf->texinfo->flags & SURF_WARP)
				mod->blend_warp_surfaces->count++;
			else
				mod->blend_surfaces->count++;
		} else {
			if (surf->texinfo->flags & SURF_WARP)
				mod->opaque_warp_surfaces->count++;
			else if (surf->texinfo->flags & SURF_ALPHA_TEST)
				mod->alpha_test_surfaces->count++;
			else
				mod->opaque_surfaces->count++;
		}

		if (surf->texinfo->image->material.flags & STAGE_RENDER)
			mod->material_surfaces->count++;

		if (surf->texinfo->image->material.flags & STAGE_FLARE)
			mod->flare_surfaces->count++;

		if (!(surf->texinfo->flags & SURF_WARP))
			mod->back_surfaces->count++;
	}

	// allocate the surfaces pointers based on the counts
	for (i = 0; i < NUM_SURFACES_ARRAYS; i++) {

		if (mod->sorted_surfaces[i]->count) {
			mod->sorted_surfaces[i]->surfaces
					= (r_bsp_surface_t **) R_HunkAlloc(
							sizeof(r_bsp_surface_t *)
									* mod->sorted_surfaces[i]->count);

			mod->sorted_surfaces[i]->count = 0;
		}
	}

	// iterate the surfaces again, populating the allocated arrays based
	// on primary render type
	for (i = 0, surf = s; i < ns; i++, surf++) {

		if (surf->texinfo->flags & SURF_SKY) {
			R_SurfaceToSurfaces(mod->sky_surfaces, surf);
			continue;
		}

		if (surf->texinfo->flags & (SURF_BLEND_33 | SURF_BLEND_66)) {
			if (surf->texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(mod->blend_warp_surfaces, surf);
			else
				R_SurfaceToSurfaces(mod->blend_surfaces, surf);
		} else {
			if (surf->texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(mod->opaque_warp_surfaces, surf);
			else if (surf->texinfo->flags & SURF_ALPHA_TEST)
				R_SurfaceToSurfaces(mod->alpha_test_surfaces, surf);
			else
				R_SurfaceToSurfaces(mod->opaque_surfaces, surf);
		}

		if (surf->texinfo->image->material.flags & STAGE_RENDER)
			R_SurfaceToSurfaces(mod->material_surfaces, surf);

		if (surf->texinfo->image->material.flags & STAGE_FLARE)
			R_SurfaceToSurfaces(mod->flare_surfaces, surf);

		if (!(surf->texinfo->flags & SURF_WARP))
			R_SurfaceToSurfaces(mod->back_surfaces, surf);
	}

	// now sort them by texture
	R_SortBspSurfacesArrays(mod);
}
Exemplo n.º 4
0
/*
 * @brief Allocate, populate and sort the surfaces arrays for the world model.
 */
static void R_LoadBspSurfacesArrays(r_model_t *mod) {
	r_sorted_bsp_surfaces_t *sorted;
	r_bsp_surface_t *surf;
	size_t i;

	// allocate the surfaces array structures
	sorted = Z_LinkMalloc(sizeof(r_sorted_bsp_surfaces_t), mod->bsp);
	mod->bsp->sorted_surfaces = sorted;

	// determine the maximum counts for each rendered type in order to
	// allocate only what is necessary for the specified model
	surf = mod->bsp->surfaces;
	for (i = 0; i < mod->bsp->num_surfaces; i++, surf++) {

		if (surf->texinfo->flags & SURF_SKY) {
			sorted->sky.count++;
			continue;
		}

		if (surf->texinfo->flags & (SURF_BLEND_33 | SURF_BLEND_66)) {
			if (surf->texinfo->flags & SURF_WARP)
				sorted->blend_warp.count++;
			else
				sorted->blend.count++;
		} else {
			if (surf->texinfo->flags & SURF_WARP)
				sorted->opaque_warp.count++;
			else if (surf->texinfo->flags & SURF_ALPHA_TEST)
				sorted->alpha_test.count++;
			else
				sorted->opaque.count++;
		}

		if (surf->texinfo->material->flags & STAGE_DIFFUSE)
			sorted->material.count++;

		if (surf->texinfo->material->flags & STAGE_FLARE)
			sorted->flare.count++;

		if (!(surf->texinfo->flags & SURF_WARP))
			sorted->back.count++;
	}

	// allocate the surfaces pointers based on the counts
	const size_t len = sizeof(r_sorted_bsp_surfaces_t) / sizeof(r_bsp_surfaces_t);
	r_bsp_surfaces_t *surfs = (r_bsp_surfaces_t *) sorted;
	for (i = 0; i < len; i++, surfs++) {

		if (surfs->count) {
			surfs->surfaces = Z_LinkMalloc(surfs->count * sizeof(r_bsp_surface_t *), mod->bsp);
			surfs->count = 0;
		}
	}

	// iterate the surfaces again, populating the allocated arrays based
	// on primary render type
	surf = mod->bsp->surfaces;
	for (i = 0; i < mod->bsp->num_surfaces; i++, surf++) {

		if (surf->texinfo->flags & SURF_SKY) {
			R_SurfaceToSurfaces(&sorted->sky, surf);
			continue;
		}

		if (surf->texinfo->flags & (SURF_BLEND_33 | SURF_BLEND_66)) {
			if (surf->texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(&sorted->blend_warp, surf);
			else
				R_SurfaceToSurfaces(&sorted->blend, surf);
		} else {
			if (surf->texinfo->flags & SURF_WARP)
				R_SurfaceToSurfaces(&sorted->opaque_warp, surf);
			else if (surf->texinfo->flags & SURF_ALPHA_TEST)
				R_SurfaceToSurfaces(&sorted->alpha_test, surf);
			else
				R_SurfaceToSurfaces(&sorted->opaque, surf);
		}

		if (surf->texinfo->material->flags & STAGE_DIFFUSE)
			R_SurfaceToSurfaces(&sorted->material, surf);

		if (surf->texinfo->material->flags & STAGE_FLARE)
			R_SurfaceToSurfaces(&sorted->flare, surf);

		if (!(surf->texinfo->flags & SURF_WARP))
			R_SurfaceToSurfaces(&sorted->back, surf);
	}

	// now sort them by texture
	R_SortBspSurfacesArrays(mod->bsp);
}