/** * @sa R_ModLoadSurfaces */ void R_CreateSurfaceLightmap (mBspSurface_t * surf) { int smax, tmax; byte *samples, *directions; if (!(surf->flags & MSURF_LIGHTMAP)) return; smax = (surf->stextents[0] / surf->lightmap_scale) + 1; tmax = (surf->stextents[1] / surf->lightmap_scale) + 1; if (!R_AllocLightmapBlock(smax, tmax, &surf->light_s, &surf->light_t)) { /* upload the last block */ R_UploadLightmapBlock(); if (!R_AllocLightmapBlock(smax, tmax, &surf->light_s, &surf->light_t)) Com_Error(ERR_DROP, "R_CreateSurfaceLightmap: Consecutive calls to R_AllocLightmapBlock(%d,%d) failed (lightmap_scale: %i, stextends: %f %f)\n", smax, tmax, surf->lightmap_scale, surf->stextents[0], surf->stextents[1]); } surf->lightmap_texnum = r_lightmaps.lightmap_texnums[r_lightmaps.lightmap_count]; surf->deluxemap_texnum = r_lightmaps.deluxemap_texnums[r_lightmaps.deluxemap_count]; samples = r_lightmaps.sample_buffer; samples += (surf->light_t * r_lightmaps.size + surf->light_s) * LIGHTMAP_BLOCK_BYTES; directions = r_lightmaps.direction_buffer; directions += (surf->light_t * r_lightmaps.size + surf->light_s) * DELUXEMAP_BLOCK_BYTES; if (!surf->samples) /* make it fullbright */ R_BuildDefaultLightmap(surf, samples, directions, r_lightmaps.size * LIGHTMAP_BLOCK_BYTES); else /* or light it properly */ R_BuildLightmap(surf, samples, directions, r_lightmaps.size * LIGHTMAP_BLOCK_BYTES); }
/** * @sa R_BeginBuildingLightmaps * @sa R_ModBeginLoading */ void R_EndBuildingLightmaps (void) { /* upload the pending lightmap block */ R_UploadLightmapBlock(); Mem_Free(r_lightmaps.allocated); Mem_Free(r_lightmaps.sample_buffer); Mem_Free(r_lightmaps.direction_buffer); r_lightmaps.allocated = NULL; r_lightmaps.sample_buffer = NULL; r_lightmaps.direction_buffer = NULL; }
/** * @sa R_BeginBuildingLightmaps * @sa R_ModBeginLoading */ void R_EndBuildingLightmaps (void) { /* upload the pending lightmap block */ R_UploadLightmapBlock(); }