Advertisement
Guest User

r_brush.c

a guest
Jul 9th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. void GL_BuildLightmaps (void)
  2. {
  3. char name[24];
  4. int i, j;
  5. struct lightmap_s *lm;
  6. qmodel_t *m;
  7.  
  8. r_framecount = 1; // no dlightcache
  9.  
  10. //Spike -- wipe out all the lightmap data (johnfitz -- the gltexture objects were already freed by Mod_ClearAll)
  11. for (i=0; i < lightmap_count; i++)
  12. free(lightmap[i].data);
  13. free(lightmap);
  14. lightmap = NULL;
  15. last_lightmap_allocated = 0;
  16. lightmap_count = 0;
  17.  
  18. gl_lightmap_format = GL_RGBA;//FIXME: hardcoded for now!
  19.  
  20. switch (gl_lightmap_format)
  21. {
  22. case GL_RGBA:
  23. lightmap_bytes = 4;
  24. break;
  25. case GL_BGRA:
  26. lightmap_bytes = 4;
  27. break;
  28. default:
  29. Sys_Error ("GL_BuildLightmaps: bad lightmap format");
  30. }
  31.  
  32. for (j=1 ; j<MAX_MODELS ; j++)
  33. {
  34. m = cl.model_precache[j];
  35. if (!m)
  36. break;
  37. if (m->name[0] == '*')
  38. continue;
  39. r_pcurrentvertbase = m->vertexes;
  40. currentmodel = m;
  41. for (i=0 ; i<m->numsurfaces ; i++)
  42. {
  43. //johnfitz -- rewritten to use SURF_DRAWTILED instead of the sky/water flags
  44. //^ Lol
  45. if (m->surfaces[i].flags & SURF_DRAWSKY)
  46. continue;
  47. GL_CreateSurfaceLightmap(m->surfaces + i);
  48. BuildSurfaceDisplayList (m->surfaces + i);
  49. if (m->surfaces[i].flags & SURF_DRAWTILED)
  50. GL_SubdivideSurface(m->surfaces + i);
  51. //johnfitz
  52. }
  53. }
  54.  
  55. //
  56. // upload all lightmaps that were filled
  57. //
  58. for (i=0; i<lightmap_count; i++)
  59. {
  60. lm = &lightmap[i];
  61. lm->modified = false;
  62. lm->rectchange.l = LMBLOCK_WIDTH;
  63. lm->rectchange.t = LMBLOCK_HEIGHT;
  64. lm->rectchange.w = 0;
  65. lm->rectchange.h = 0;
  66.  
  67. //johnfitz -- use texture manager
  68. sprintf(name, "lightmap%07i",i);
  69. lm->texture = TexMgr_LoadImage (cl.worldmodel, name, LMBLOCK_WIDTH, LMBLOCK_HEIGHT,
  70. SRC_LIGHTMAP, lm->data, "", (src_offset_t)lm->data, TEXPREF_LINEAR | TEXPREF_NOPICMIP);
  71. //johnfitz
  72. }
  73.  
  74. //johnfitz -- warn about exceeding old limits
  75. //GLQuake limit was 64 textures of 128x128. Estimate how many 128x128 textures we would need
  76. //given that we are using lightmap_count of LMBLOCK_WIDTH x LMBLOCK_HEIGHT
  77. i = lightmap_count * ((LMBLOCK_WIDTH / 128) * (LMBLOCK_HEIGHT / 128));
  78. if (i > 64)
  79. Con_DWarning("%i lightmaps exceeds standard limit of 64.\n",i);
  80. //johnfitz
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement