gl_texture.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. *
  31. *---------------------------------------------------------------------
  32. */
  33. #include "z_zone.h"
  34. #ifdef _WIN32
  35. #define WIN32_LEAN_AND_MEAN
  36. #include <windows.h>
  37. #endif
  38. #ifndef CALLBACK
  39. #define CALLBACK
  40. #endif
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <math.h>
  44. //#include <SDL.h>
  45. #include "SDL_opengl.h"
  46. #include "doomtype.h"
  47. #include "w_wad.h"
  48. #include "m_argv.h"
  49. #include "d_event.h"
  50. #include "v_video.h"
  51. #include "doomstat.h"
  52. #include "r_bsp.h"
  53. #include "r_main.h"
  54. #include "r_draw.h"
  55. #include "r_sky.h"
  56. #include "r_plane.h"
  57. #include "r_data.h"
  58. #include "p_maputl.h"
  59. #include "p_tick.h"
  60. #include "m_bbox.h"
  61. #include "lprintf.h"
  62. #include "gl_intern.h"
  63. #include "gl_struct.h"
  64. /* TEXTURES */
  65. /* static */ GLTexture **gld_GLTextures=NULL;
  66. /* PATCHES FLATS SPRITES */
  67. /* static */ GLTexture **gld_GLPatchTextures=NULL;
  68. boolean use_mipmapping=false;
  69. int gld_max_texturesize=0;
  70. char *gl_tex_format_string;
  71. //int gl_tex_format=GL_RGBA8;
  72. int gl_tex_format=GL_RGB5_A1;
  73. //int gl_tex_format=GL_RGBA4;
  74. //int gl_tex_format=GL_RGBA2;
  75. GLTexture *last_gltexture=NULL;
  76. int last_cm=-1;
  77. int transparent_pal_index;
  78. unsigned char gld_palmap[256];
  79. void gld_InitPalettedTextures(void)
  80. {
  81. const unsigned char *playpal;
  82. int pal[256];
  83. int i,j;
  84. playpal= staticPlaypal; // JDC W_CacheLumpName("PLAYPAL");
  85. for (i=0; i<256; i++) {
  86. pal[i] = (playpal[i*3+0] << 16) | (playpal[i*3+1] << 8) | playpal[i*3+2];
  87. gld_palmap[i] = i;
  88. }
  89. transparent_pal_index = -1;
  90. for (i=0; i<256; i++) {
  91. for (j=i+1; j<256; j++) {
  92. if (pal[i] == pal[j]) {
  93. transparent_pal_index = j;
  94. gld_palmap[j] = i;
  95. break;
  96. }
  97. }
  98. if (transparent_pal_index >= 0)
  99. break;
  100. }
  101. // JDC W_UnlockLumpName("PLAYPAL");
  102. }
  103. void gld_UploadAndMip32BitTexture( int width, int height, const byte *rgba ) { // JDC
  104. // OpenGL ES doesn't allow format conversions by glTexImage, so if we want
  105. // a 16 bit image, we need to convert it ourselves. For more efficient
  106. // load times we should go directly there from the paletted textures, but
  107. // this will be a fallback
  108. unsigned short *buffer = malloc( width * height * 2 );
  109. int i, c;
  110. c = width * height;
  111. for ( i = 0 ; i < c ; i++ ) {
  112. int r = rgba[i*4+0];
  113. int g = rgba[i*4+1];
  114. int b = rgba[i*4+2];
  115. int a = rgba[i*4+3];
  116. buffer[i] = ( (r>>3)<<11 ) | ( (g>>3)<<6) | ( (b>>3)<<1 ) | ( (a>>7)<<0 );
  117. // buffer[i] = ( (r>>3)<<0 ) | ( (g>>3)<<5) | ( (b>>3)<<10 ) | ( (a>>7)<<15 );
  118. }
  119. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
  120. width, height,
  121. 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, buffer);
  122. free( buffer );
  123. // the built-in generate mipmaps is pretty fast
  124. #ifdef GL_OES_framebuffer_object // JDC
  125. glGenerateMipmapOES( GL_TEXTURE_2D );
  126. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  127. #endif
  128. }
  129. int gld_GetTexDimension(int value)
  130. {
  131. int i;
  132. i=1;
  133. while (i<value)
  134. i*=2;
  135. if (i>gld_max_texturesize)
  136. i=gld_max_texturesize;
  137. return i;
  138. }
  139. static GLTexture *gld_AddNewGLTexture(int texture_num)
  140. {
  141. if (texture_num<0)
  142. return NULL;
  143. if (texture_num>=numtextures)
  144. return NULL;
  145. if (!gld_GLTextures)
  146. {
  147. gld_GLTextures=Z_Malloc(numtextures*sizeof(GLTexture *),PU_STATIC,0);
  148. memset(gld_GLTextures,0,numtextures*sizeof(GLTexture *));
  149. }
  150. if (!gld_GLTextures[texture_num])
  151. {
  152. gld_GLTextures[texture_num]=Z_Malloc(sizeof(GLTexture),PU_STATIC,0);
  153. memset(gld_GLTextures[texture_num], 0, sizeof(GLTexture));
  154. gld_GLTextures[texture_num]->textype=GLDT_UNREGISTERED;
  155. }
  156. return gld_GLTextures[texture_num];
  157. }
  158. static GLTexture *gld_AddNewGLPatchTexture(int lump)
  159. {
  160. if (lump<0)
  161. return NULL;
  162. if (lump>=numlumps)
  163. return NULL;
  164. if (!gld_GLPatchTextures)
  165. {
  166. gld_GLPatchTextures=Z_Malloc(numlumps*sizeof(GLTexture *),PU_STATIC,0);
  167. memset(gld_GLPatchTextures,0,numlumps*sizeof(GLTexture *));
  168. }
  169. if (!gld_GLPatchTextures[lump])
  170. {
  171. gld_GLPatchTextures[lump]=Z_Malloc(sizeof(GLTexture),PU_STATIC,0);
  172. memset(gld_GLPatchTextures[lump], 0, sizeof(GLTexture));
  173. gld_GLPatchTextures[lump]->textype=GLDT_UNREGISTERED;
  174. }
  175. return gld_GLPatchTextures[lump];
  176. }
  177. void gld_SetTexturePalette(GLenum target)
  178. {
  179. const unsigned char *playpal;
  180. unsigned char pal[1024];
  181. int i;
  182. playpal= staticPlaypal; // JDC W_CacheLumpName("PLAYPAL");
  183. for (i=0; i<256; i++) {
  184. pal[i*4+0] = playpal[i*3+0];
  185. pal[i*4+1] = playpal[i*3+1];
  186. pal[i*4+2] = playpal[i*3+2];
  187. pal[i*4+3] = 255;
  188. }
  189. pal[transparent_pal_index*4+0]=0;
  190. pal[transparent_pal_index*4+1]=0;
  191. pal[transparent_pal_index*4+2]=0;
  192. pal[transparent_pal_index*4+3]=0;
  193. gld_ColorTableEXT(target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, pal);
  194. //JDC W_UnlockLumpName("PLAYPAL");
  195. }
  196. static void gld_AddPatchToTexture_UnTranslated(GLTexture *gltexture, unsigned char *buffer, const rpatch_t *patch, int originx, int originy, int paletted)
  197. {
  198. int x,y,j;
  199. int xs,xe;
  200. int js,je;
  201. const rcolumn_t *column;
  202. const byte *source;
  203. int i, pos;
  204. const unsigned char *playpal;
  205. if (!gltexture)
  206. return;
  207. if (!patch)
  208. return;
  209. playpal= staticPlaypal; // JDC W_CacheLumpName("PLAYPAL");
  210. xs=0;
  211. xe=patch->width;
  212. if ((xs+originx)>=gltexture->realtexwidth)
  213. return;
  214. if ((xe+originx)<=0)
  215. return;
  216. if ((xs+originx)<0)
  217. xs=-originx;
  218. if ((xe+originx)>gltexture->realtexwidth)
  219. xe+=(gltexture->realtexwidth-(xe+originx));
  220. for (x=xs;x<xe;x++)
  221. {
  222. #ifdef RANGECHECK
  223. if (x>=patch->width)
  224. {
  225. lprintf(LO_ERROR,"gld_AddPatchToTexture_UnTranslated x>=patch->width (%i >= %i)\n",x,patch->width);
  226. return;
  227. }
  228. #endif
  229. column = &patch->columns[x];
  230. for (i=0; i<column->numPosts; i++) {
  231. const rpost_t *post = &column->posts[i];
  232. y=(post->topdelta+originy);
  233. js=0;
  234. je=post->length;
  235. if ((js+y)>=gltexture->realtexheight)
  236. continue;
  237. if ((je+y)<=0)
  238. continue;
  239. if ((js+y)<0)
  240. js=-y;
  241. if ((je+y)>gltexture->realtexheight)
  242. je+=(gltexture->realtexheight-(je+y));
  243. source = column->pixels + post->topdelta;
  244. if (paletted) {
  245. pos=(((js+y)*gltexture->buffer_width)+x+originx);
  246. for (j=js;j<je;j++,pos+=(gltexture->buffer_width))
  247. {
  248. #ifdef RANGECHECK
  249. if (pos>=gltexture->buffer_size)
  250. {
  251. lprintf(LO_ERROR,"gld_AddPatchToTexture_UnTranslated pos>=size (%i >= %i)\n",pos+3,gltexture->buffer_size);
  252. return;
  253. }
  254. #endif
  255. buffer[pos]=gld_palmap[source[j]];
  256. }
  257. } else {
  258. pos=4*(((js+y)*gltexture->buffer_width)+x+originx);
  259. for (j=js;j<je;j++,pos+=(4*gltexture->buffer_width))
  260. {
  261. #ifdef RANGECHECK
  262. if ((pos+3)>=gltexture->buffer_size)
  263. {
  264. lprintf(LO_ERROR,"gld_AddPatchToTexture_UnTranslated pos+3>=size (%i >= %i)\n",pos+3,gltexture->buffer_size);
  265. return;
  266. }
  267. #endif
  268. buffer[pos]=playpal[source[j]*3];
  269. buffer[pos+1]=playpal[source[j]*3+1];
  270. buffer[pos+2]=playpal[source[j]*3+2];
  271. buffer[pos+3]=255;
  272. }
  273. }
  274. }
  275. }
  276. // JDC W_UnlockLumpName("PLAYPAL");
  277. }
  278. void gld_AddPatchToTexture(GLTexture *gltexture, unsigned char *buffer, const rpatch_t *patch, int originx, int originy, int cm, int paletted)
  279. {
  280. int x,y,j;
  281. int xs,xe;
  282. int js,je;
  283. const rcolumn_t *column;
  284. const byte *source;
  285. int i, pos;
  286. const unsigned char *playpal;
  287. const unsigned char *outr;
  288. if (!gltexture)
  289. return;
  290. if (!patch)
  291. return;
  292. if ((cm==CR_DEFAULT) || (cm==CR_LIMIT))
  293. {
  294. gld_AddPatchToTexture_UnTranslated(gltexture,buffer,patch,originx,originy, paletted);
  295. return;
  296. }
  297. if (cm<CR_LIMIT)
  298. outr=colrngs[cm];
  299. else
  300. outr=translationtables + 256*((cm-CR_LIMIT)-1);
  301. playpal= staticPlaypal; // JDC W_CacheLumpName("PLAYPAL");
  302. xs=0;
  303. xe=patch->width;
  304. if ((xs+originx)>=gltexture->realtexwidth)
  305. return;
  306. if ((xe+originx)<=0)
  307. return;
  308. if ((xs+originx)<0)
  309. xs=-originx;
  310. if ((xe+originx)>gltexture->realtexwidth)
  311. xe+=(gltexture->realtexwidth-(xe+originx));
  312. for (x=xs;x<xe;x++)
  313. {
  314. #ifdef RANGECHECK
  315. if (x>=patch->width)
  316. {
  317. lprintf(LO_ERROR,"gld_AddPatchToTexture x>=patch->width (%i >= %i)\n",x,patch->width);
  318. return;
  319. }
  320. #endif
  321. column = &patch->columns[x];
  322. for (i=0; i<column->numPosts; i++) {
  323. const rpost_t *post = &column->posts[i];
  324. y=(post->topdelta+originy);
  325. js=0;
  326. je=post->length;
  327. if ((js+y)>=gltexture->realtexheight)
  328. continue;
  329. if ((je+y)<=0)
  330. continue;
  331. if ((js+y)<0)
  332. js=-y;
  333. if ((je+y)>gltexture->realtexheight)
  334. je+=(gltexture->realtexheight-(je+y));
  335. source = column->pixels + post->topdelta;
  336. if (paletted) {
  337. pos=(((js+y)*gltexture->buffer_width)+x+originx);
  338. for (j=js;j<je;j++,pos+=(gltexture->buffer_width))
  339. {
  340. #ifdef RANGECHECK
  341. if (pos>=gltexture->buffer_size)
  342. {
  343. lprintf(LO_ERROR,"gld_AddPatchToTexture_UnTranslated pos>=size (%i >= %i)\n",pos+3,gltexture->buffer_size);
  344. return;
  345. }
  346. #endif
  347. buffer[pos]=gld_palmap[outr[source[j]]];
  348. }
  349. } else {
  350. pos=4*(((js+y)*gltexture->buffer_width)+x+originx);
  351. for (j=js;j<je;j++,pos+=(4*gltexture->buffer_width))
  352. {
  353. #ifdef RANGECHECK
  354. if ((pos+3)>=gltexture->buffer_size)
  355. {
  356. lprintf(LO_ERROR,"gld_AddPatchToTexture pos+3>=size (%i >= %i)\n",pos+3,gltexture->buffer_size);
  357. return;
  358. }
  359. #endif
  360. buffer[pos]=playpal[outr[source[j]]*3];
  361. buffer[pos+1]=playpal[outr[source[j]]*3+1];
  362. buffer[pos+2]=playpal[outr[source[j]]*3+2];
  363. buffer[pos+3]=255;
  364. }
  365. }
  366. }
  367. }
  368. // JDC W_UnlockLumpName("PLAYPAL");
  369. }
  370. static void gld_AddFlatToTexture(GLTexture *gltexture, unsigned char *buffer, const unsigned char *flat, int paletted)
  371. {
  372. int x,y,pos;
  373. const unsigned char *playpal;
  374. if (!gltexture)
  375. return;
  376. if (!flat)
  377. return;
  378. if (paletted) {
  379. for (y=0;y<gltexture->realtexheight;y++)
  380. {
  381. pos=(y*gltexture->buffer_width);
  382. for (x=0;x<gltexture->realtexwidth;x++,pos++)
  383. {
  384. #ifdef RANGECHECK
  385. if (pos>=gltexture->buffer_size)
  386. {
  387. lprintf(LO_ERROR,"gld_AddFlatToTexture pos>=size (%i >= %i)\n",pos,gltexture->buffer_size);
  388. return;
  389. }
  390. #endif
  391. buffer[pos]=gld_palmap[flat[y*64+x]];
  392. }
  393. }
  394. } else {
  395. playpal= staticPlaypal; // JDC W_CacheLumpName("PLAYPAL");
  396. for (y=0;y<gltexture->realtexheight;y++)
  397. {
  398. pos=4*(y*gltexture->buffer_width);
  399. for (x=0;x<gltexture->realtexwidth;x++,pos+=4)
  400. {
  401. #ifdef RANGECHECK
  402. if ((pos+3)>=gltexture->buffer_size)
  403. {
  404. lprintf(LO_ERROR,"gld_AddFlatToTexture pos+3>=size (%i >= %i)\n",pos+3,gltexture->buffer_size);
  405. return;
  406. }
  407. #endif
  408. buffer[pos]=playpal[flat[y*64+x]*3];
  409. buffer[pos+1]=playpal[flat[y*64+x]*3+1];
  410. buffer[pos+2]=playpal[flat[y*64+x]*3+2];
  411. buffer[pos+3]=255;
  412. }
  413. }
  414. // JDC W_UnlockLumpName("PLAYPAL");
  415. }
  416. }
  417. //e6y: "force" flag for loading texture with zero index
  418. GLTexture *gld_RegisterTexture(int texture_num, boolean mipmap, boolean force)
  419. {
  420. GLTexture *gltexture;
  421. //e6y: textures with zero index should be loaded sometimes
  422. if (texture_num==NO_TEXTURE && !force)
  423. return NULL;
  424. gltexture=gld_AddNewGLTexture(texture_num);
  425. if (!gltexture)
  426. return NULL;
  427. if (gltexture->textype==GLDT_UNREGISTERED)
  428. {
  429. texture_t *texture=NULL;
  430. if ((texture_num>=0) || (texture_num<numtextures))
  431. texture=textures[texture_num];
  432. if (!texture)
  433. return NULL;
  434. gltexture->textype=GLDT_BROKEN;
  435. gltexture->index=texture_num;
  436. gltexture->mipmap=mipmap;
  437. gltexture->realtexwidth=texture->width;
  438. gltexture->realtexheight=texture->height;
  439. gltexture->leftoffset=0;
  440. gltexture->topoffset=0;
  441. gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth);
  442. gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight);
  443. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  444. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  445. gltexture->buffer_width=gltexture->tex_width;
  446. gltexture->buffer_height=gltexture->tex_height;
  447. #ifdef USE_GLU_IMAGESCALE
  448. gltexture->width=gltexture->tex_width;
  449. gltexture->height=gltexture->tex_height;
  450. gltexture->buffer_width=gltexture->realtexwidth;
  451. gltexture->buffer_height=gltexture->realtexheight;
  452. #endif
  453. if (gltexture->mipmap & use_mipmapping)
  454. {
  455. gltexture->width=gltexture->tex_width;
  456. gltexture->height=gltexture->tex_height;
  457. gltexture->buffer_width=gltexture->realtexwidth;
  458. gltexture->buffer_height=gltexture->realtexheight;
  459. }
  460. gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4;
  461. if (gltexture->realtexwidth>gltexture->buffer_width)
  462. return gltexture;
  463. if (gltexture->realtexheight>gltexture->buffer_height)
  464. return gltexture;
  465. gltexture->textype=GLDT_TEXTURE;
  466. }
  467. return gltexture;
  468. }
  469. void gld_BindTexture(GLTexture *gltexture)
  470. {
  471. const rpatch_t *patch;
  472. int i;
  473. unsigned char *buffer;
  474. if (gltexture==last_gltexture)
  475. return;
  476. last_gltexture=gltexture;
  477. if (!gltexture) {
  478. glBindTexture(GL_TEXTURE_2D, 0);
  479. last_gltexture = NULL;
  480. last_cm = -1;
  481. return;
  482. }
  483. if (gltexture->textype!=GLDT_TEXTURE)
  484. {
  485. glBindTexture(GL_TEXTURE_2D, 0);
  486. last_gltexture = NULL;
  487. last_cm = -1;
  488. return;
  489. }
  490. if (gltexture->glTexID[CR_DEFAULT]!=0)
  491. {
  492. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  493. #ifndef GL_VERSION_ES_CL_1_1 // no GL_TEXTURE_RESIDENT in GLES
  494. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  495. #ifdef _DEBUG
  496. if (i!=GL_TRUE)
  497. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  498. #endif
  499. if (i==GL_TRUE)
  500. #endif // GL_VERSION_ES_CL_1_1
  501. return;
  502. }
  503. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  504. if (!(gltexture->mipmap & use_mipmapping) & gl_paletted_texture)
  505. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  506. else
  507. memset(buffer,0,gltexture->buffer_size);
  508. patch=R_CacheTextureCompositePatchNum(gltexture->index);
  509. gld_AddPatchToTexture(gltexture, buffer, patch,
  510. 0, 0,
  511. CR_DEFAULT, !(gltexture->mipmap & use_mipmapping) & gl_paletted_texture);
  512. R_UnlockTextureCompositePatchNum(gltexture->index);
  513. if (gltexture->glTexID[CR_DEFAULT]==0)
  514. glGenTextures(1,&gltexture->glTexID[CR_DEFAULT]);
  515. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  516. #ifdef USE_GLU_MIPMAP
  517. if (gltexture->mipmap & use_mipmapping)
  518. {
  519. gluBuild2DMipmaps(GL_TEXTURE_2D, gl_tex_format,
  520. gltexture->buffer_width, gltexture->buffer_height,
  521. GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  522. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  523. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  524. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  525. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_mipmap_filter);
  526. if (gl_texture_filter_anisotropic)
  527. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0);
  528. }
  529. else
  530. #endif /* USE_GLU_MIPMAP */
  531. {
  532. #ifdef USE_GLU_IMAGESCALE
  533. if ((gltexture->buffer_width!=gltexture->tex_width) ||
  534. (gltexture->buffer_height!=gltexture->tex_height)
  535. )
  536. {
  537. unsigned char *scaledbuffer;
  538. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  539. if (scaledbuffer)
  540. {
  541. gluScaleImage(GL_RGBA,
  542. gltexture->buffer_width, gltexture->buffer_height,
  543. GL_UNSIGNED_BYTE,buffer,
  544. gltexture->tex_width, gltexture->tex_height,
  545. GL_UNSIGNED_BYTE,scaledbuffer);
  546. Z_Free(buffer);
  547. buffer=scaledbuffer;
  548. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  549. gltexture->tex_width, gltexture->tex_height,
  550. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  551. }
  552. }
  553. else
  554. #endif /* USE_GLU_IMAGESCALE */
  555. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  556. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  557. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  558. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  559. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  560. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  561. #else
  562. {
  563. if (gl_paletted_texture) {
  564. gld_SetTexturePalette(GL_TEXTURE_2D);
  565. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  566. gltexture->buffer_width, gltexture->buffer_height,
  567. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  568. } else {
  569. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  570. gltexture->buffer_width, gltexture->buffer_height,
  571. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  572. }
  573. }
  574. #endif
  575. }
  576. Z_Free(buffer);
  577. }
  578. GLTexture *gld_RegisterPatch(int lump, int cm)
  579. {
  580. const rpatch_t *patch;
  581. GLTexture *gltexture;
  582. gltexture=gld_AddNewGLPatchTexture(lump);
  583. if (!gltexture)
  584. return NULL;
  585. if (gltexture->textype==GLDT_UNREGISTERED)
  586. {
  587. patch=R_CachePatchNum(lump);
  588. if (!patch)
  589. return NULL;
  590. gltexture->textype=GLDT_BROKEN;
  591. gltexture->index=lump;
  592. gltexture->mipmap=false;
  593. gltexture->realtexwidth=patch->width;
  594. gltexture->realtexheight=patch->height;
  595. gltexture->leftoffset=patch->leftoffset;
  596. gltexture->topoffset=patch->topoffset;
  597. gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth);
  598. gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight);
  599. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  600. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  601. gltexture->buffer_width=gltexture->tex_width;
  602. gltexture->buffer_height=gltexture->tex_height;
  603. #ifdef USE_GLU_IMAGESCALE
  604. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  605. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  606. gltexture->buffer_width=MAX(gltexture->realtexwidth, gltexture->tex_width);
  607. gltexture->buffer_height=MAX(gltexture->realtexheight, gltexture->tex_height);
  608. #endif
  609. gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4;
  610. R_UnlockPatchNum(lump);
  611. if (gltexture->realtexwidth>gltexture->buffer_width)
  612. return gltexture;
  613. if (gltexture->realtexheight>gltexture->buffer_height)
  614. return gltexture;
  615. gltexture->textype=GLDT_PATCH;
  616. }
  617. return gltexture;
  618. }
  619. void gld_BindPatch(GLTexture *gltexture, int cm)
  620. {
  621. const rpatch_t *patch;
  622. int i;
  623. unsigned char *buffer;
  624. if ((gltexture==last_gltexture) && (cm==last_cm))
  625. return;
  626. last_gltexture=gltexture;
  627. last_cm=cm;
  628. if (!gltexture)
  629. return;
  630. if (gltexture->textype!=GLDT_PATCH)
  631. {
  632. glBindTexture(GL_TEXTURE_2D, 0);
  633. last_gltexture = NULL;
  634. last_cm = -1;
  635. return;
  636. }
  637. if (gltexture->glTexID[cm]!=0)
  638. {
  639. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]);
  640. #ifndef GL_VERSION_ES_CL_1_1 // JDC no GL_TEXTURE_RESIDENT in GLES
  641. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  642. #ifdef _DEBUG
  643. if (i!=GL_TRUE)
  644. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  645. #endif
  646. if (i==GL_TRUE)
  647. #endif // GL_VERSION_ES_CL_1_1
  648. return;
  649. }
  650. patch=R_CachePatchNum(gltexture->index);
  651. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  652. if (gl_paletted_texture)
  653. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  654. else
  655. memset(buffer,0,gltexture->buffer_size);
  656. gld_AddPatchToTexture(gltexture, buffer, patch, 0, 0, cm, gl_paletted_texture);
  657. assert( cm >= 0 && cm < sizeof( gltexture->glTexID ) / sizeof( gltexture->glTexID[0] ) ); // JDC
  658. if (gltexture->glTexID[cm]==0)
  659. glGenTextures(1,&gltexture->glTexID[cm]);
  660. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]);
  661. #ifdef USE_GLU_IMAGESCALE
  662. if ((gltexture->buffer_width>gltexture->tex_width) ||
  663. (gltexture->buffer_height>gltexture->tex_height)
  664. )
  665. {
  666. unsigned char *scaledbuffer;
  667. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  668. if (scaledbuffer)
  669. {
  670. gluScaleImage(GL_RGBA,
  671. gltexture->buffer_width, gltexture->buffer_height,
  672. GL_UNSIGNED_BYTE,buffer,
  673. gltexture->tex_width, gltexture->tex_height,
  674. GL_UNSIGNED_BYTE,scaledbuffer);
  675. Z_Free(buffer);
  676. buffer=scaledbuffer;
  677. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  678. gltexture->tex_width, gltexture->tex_height,
  679. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  680. }
  681. }
  682. else
  683. #endif /* USE_GLU_IMAGESCALE */
  684. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  685. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  686. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  687. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  688. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  689. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  690. #else
  691. {
  692. if (gl_paletted_texture) {
  693. gld_SetTexturePalette(GL_TEXTURE_2D);
  694. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  695. gltexture->buffer_width, gltexture->buffer_height,
  696. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  697. } else {
  698. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  699. gltexture->buffer_width, gltexture->buffer_height,
  700. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  701. }
  702. }
  703. #endif
  704. printf( "bindPatch on lump: %i '%s' : %i\n", gltexture->index, lumpinfo[ gltexture->index ].name, cm ); // !@# JDC
  705. Z_Free(buffer);
  706. R_UnlockPatchNum(gltexture->index);
  707. }
  708. GLTexture *gld_RegisterFlat(int lump, boolean mipmap)
  709. {
  710. GLTexture *gltexture;
  711. gltexture=gld_AddNewGLPatchTexture(firstflat+lump);
  712. if (!gltexture)
  713. return NULL;
  714. if (gltexture->textype==GLDT_UNREGISTERED)
  715. {
  716. gltexture->textype=GLDT_BROKEN;
  717. gltexture->index=firstflat+lump;
  718. gltexture->mipmap=mipmap;
  719. gltexture->realtexwidth=64;
  720. gltexture->realtexheight=64;
  721. gltexture->leftoffset=0;
  722. gltexture->topoffset=0;
  723. gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth);
  724. gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight);
  725. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  726. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  727. gltexture->buffer_width=gltexture->tex_width;
  728. gltexture->buffer_height=gltexture->tex_height;
  729. #ifdef USE_GLU_IMAGESCALE
  730. gltexture->width=gltexture->tex_width;
  731. gltexture->height=gltexture->tex_height;
  732. gltexture->buffer_width=gltexture->realtexwidth;
  733. gltexture->buffer_height=gltexture->realtexheight;
  734. #endif
  735. if (gltexture->mipmap & use_mipmapping)
  736. {
  737. gltexture->width=gltexture->tex_width;
  738. gltexture->height=gltexture->tex_height;
  739. gltexture->buffer_width=gltexture->realtexwidth;
  740. gltexture->buffer_height=gltexture->realtexheight;
  741. }
  742. gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4;
  743. if (gltexture->realtexwidth>gltexture->buffer_width)
  744. return gltexture;
  745. if (gltexture->realtexheight>gltexture->buffer_height)
  746. return gltexture;
  747. gltexture->textype=GLDT_FLAT;
  748. }
  749. return gltexture;
  750. }
  751. void gld_BindFlat(GLTexture *gltexture)
  752. {
  753. const unsigned char *flat;
  754. int i;
  755. unsigned char *buffer;
  756. if (gltexture==last_gltexture)
  757. return;
  758. last_gltexture=gltexture;
  759. if (!gltexture)
  760. return;
  761. if (gltexture->textype!=GLDT_FLAT)
  762. {
  763. glBindTexture(GL_TEXTURE_2D, 0);
  764. last_gltexture = NULL;
  765. last_cm = -1;
  766. return;
  767. }
  768. if (gltexture->glTexID[CR_DEFAULT]!=0)
  769. {
  770. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  771. #ifndef GL_VERSION_ES_CL_1_1 // no GL_TEXTURE_RESIDENT in GLES
  772. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  773. #ifdef _DEBUG
  774. if (i!=GL_TRUE)
  775. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  776. #endif
  777. if (i==GL_TRUE)
  778. #endif // GL_VERSION_ES_CL_1_1
  779. return;
  780. }
  781. flat=W_CacheLumpNum(gltexture->index);
  782. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  783. if (!(gltexture->mipmap & use_mipmapping) & gl_paletted_texture)
  784. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  785. else
  786. memset(buffer,0,gltexture->buffer_size);
  787. gld_AddFlatToTexture(gltexture, buffer, flat, !(gltexture->mipmap & use_mipmapping) & gl_paletted_texture);
  788. if (gltexture->glTexID[CR_DEFAULT]==0)
  789. glGenTextures(1,&gltexture->glTexID[CR_DEFAULT]);
  790. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  791. #if USE_GLU_MIPMAP
  792. if (gltexture->mipmap & use_mipmapping)
  793. {
  794. gluBuild2DMipmaps(GL_TEXTURE_2D, gl_tex_format,
  795. gltexture->buffer_width, gltexture->buffer_height,
  796. GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  797. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  798. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  799. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  800. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_mipmap_filter);
  801. if (gl_texture_filter_anisotropic)
  802. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0);
  803. }
  804. else
  805. #endif /* USE_GLU_MIPMAP */
  806. {
  807. #ifdef USE_GLU_IMAGESCALE
  808. if ((gltexture->buffer_width!=gltexture->tex_width) ||
  809. (gltexture->buffer_height!=gltexture->tex_height)
  810. )
  811. {
  812. unsigned char *scaledbuffer;
  813. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  814. if (scaledbuffer)
  815. {
  816. gluScaleImage(GL_RGBA,
  817. gltexture->buffer_width, gltexture->buffer_height,
  818. GL_UNSIGNED_BYTE,buffer,
  819. gltexture->tex_width, gltexture->tex_height,
  820. GL_UNSIGNED_BYTE,scaledbuffer);
  821. Z_Free(buffer);
  822. buffer=scaledbuffer;
  823. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  824. gltexture->tex_width, gltexture->tex_height,
  825. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  826. }
  827. }
  828. else
  829. #endif /* USE_GLU_IMAGESCALE */
  830. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  831. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  832. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  833. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  834. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  835. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  836. #else
  837. {
  838. if (gl_paletted_texture) {
  839. gld_SetTexturePalette(GL_TEXTURE_2D);
  840. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  841. gltexture->buffer_width, gltexture->buffer_height,
  842. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  843. } else {
  844. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  845. gltexture->buffer_width, gltexture->buffer_height,
  846. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  847. }
  848. }
  849. #endif
  850. }
  851. Z_Free(buffer);
  852. W_UnlockLumpNum(gltexture->index);
  853. }
  854. static void gld_CleanTextures(void)
  855. {
  856. int i,j;
  857. if (!gld_GLTextures)
  858. return;
  859. for (i=0; i<numtextures; i++)
  860. {
  861. if (gld_GLTextures[i])
  862. {
  863. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  864. glDeleteTextures(1,&(gld_GLTextures[i]->glTexID[j]));
  865. Z_Free(gld_GLTextures[i]);
  866. }
  867. }
  868. memset(gld_GLTextures,0,numtextures*sizeof(GLTexture *));
  869. }
  870. static void gld_CleanPatchTextures(void)
  871. {
  872. int i,j;
  873. if (!gld_GLPatchTextures)
  874. return;
  875. for (i=0; i<numlumps; i++)
  876. {
  877. if (gld_GLPatchTextures[i])
  878. {
  879. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  880. glDeleteTextures(1,&(gld_GLPatchTextures[i]->glTexID[j]));
  881. Z_Free(gld_GLPatchTextures[i]);
  882. }
  883. }
  884. memset(gld_GLPatchTextures,0,numlumps*sizeof(GLTexture *));
  885. }
  886. void DrawEmptyTriangleToForceTextureLoad() { // JDC
  887. // The iPhone OpenGL driver (and many others), don't
  888. // do all the texture loading work until it is actually
  889. // used to draw something. If you want to avoid all
  890. // hitches during gameplay, call this after binding
  891. // during the precache.
  892. glBegin( GL_TRIANGLES );
  893. glVertex2f( 0, 0 );
  894. glVertex2f( 0, 0 );
  895. glVertex2f( 0, 0 );
  896. glEnd();
  897. }
  898. void gld_Precache(void)
  899. {
  900. int i, j, k;
  901. byte *flatHitlist = alloca( numflats );
  902. byte *wallHitlist = alloca( numtextures );
  903. byte *spriteHitlist = alloca( numsprites );
  904. // JDC: significant rework here to also take over the
  905. // work of gld_CleanMemory() and avoid freeing and reloading
  906. // things that are still needed, making respawning many times
  907. // faster.
  908. // this updates the spinning wheel icon as we load textures
  909. void iphonePacifierUpdate();
  910. // JDC if (demoplayback)
  911. // JDC return;
  912. //-----------------------------------------
  913. // find everything we will need before loading anything
  914. //-----------------------------------------
  915. // find flats
  916. memset(flatHitlist, 0, numflats);
  917. for (i = numsectors; --i >= 0; ) {
  918. // JDC: todo: get animated flats
  919. assert( (unsigned)sectors[i].floorpic < numflats );
  920. assert( (unsigned)sectors[i].ceilingpic < numflats );
  921. flatHitlist[sectors[i].floorpic] = 1;
  922. flatHitlist[sectors[i].ceilingpic] = 1;
  923. }
  924. // find walls
  925. memset(wallHitlist, 0, numtextures);
  926. for (i = numsides; --i >= 0;) {
  927. assert( (unsigned)sides[i].bottomtexture < numtextures );
  928. assert( (unsigned)sides[i].toptexture < numtextures );
  929. assert( (unsigned)sides[i].midtexture < numtextures );
  930. wallHitlist[sides[i].bottomtexture] = 1;
  931. wallHitlist[sides[i].toptexture] = 1;
  932. wallHitlist[sides[i].midtexture] = 1;
  933. }
  934. // Sky texture is always present.
  935. // Note that F_SKY1 is the name used to
  936. // indicate a sky floor/ceiling as a flat,
  937. // while the sky texture is stored like
  938. // a wall texture, with an episode dependend
  939. // name.
  940. wallHitlist[skytexture] = 1;
  941. // find sprites
  942. memset(spriteHitlist, 0, numsprites);
  943. for ( i = 0 ; i < numsectors ; i++ ) {
  944. for ( mobj_t *thing = sectors[i].thinglist; thing; thing = thing->snext) {
  945. assert( (unsigned)thing->sprite < numsprites );
  946. spriteHitlist[thing->sprite] = 1;
  947. }
  948. }
  949. //-----------------------------------------
  950. // free textures not used
  951. //-----------------------------------------
  952. if ( gld_GLPatchTextures ) {
  953. for (i = numflats; --i >= 0; ) {
  954. if (!flatHitlist[i]) {
  955. int patchNum = firstflat + i;
  956. if ( gld_GLPatchTextures[patchNum] ) {
  957. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  958. glDeleteTextures(1,(GLuint *)&(gld_GLPatchTextures[patchNum]->glTexID[j]));
  959. Z_Free(gld_GLPatchTextures[patchNum]);
  960. gld_GLPatchTextures[patchNum] = NULL;
  961. }
  962. }
  963. }
  964. }
  965. if ( gld_GLTextures ) {
  966. for (i = numtextures; --i >= 0; ) {
  967. if ( !wallHitlist[i] ) {
  968. if (gld_GLTextures[i]) {
  969. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  970. glDeleteTextures(1,(GLuint *)&(gld_GLTextures[i]->glTexID[j]));
  971. Z_Free(gld_GLTextures[i]);
  972. gld_GLTextures[i] = NULL;
  973. }
  974. }
  975. }
  976. }
  977. if ( gld_GLPatchTextures ) {
  978. for (i=numsprites; --i >= 0;) {
  979. if ( !spriteHitlist[i] ) {
  980. for ( int j = 0 ; j < sprites[i].numframes ; j++ ) {
  981. short *sflump = sprites[i].spriteframes[j].lump;
  982. for ( k = 0 ; k < 7 ; k++ ) {
  983. int patchNum = firstspritelump + sflump[k];
  984. if ( gld_GLPatchTextures[patchNum] ) {
  985. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  986. glDeleteTextures(1,(GLuint *)&(gld_GLPatchTextures[patchNum]->glTexID[j]));
  987. Z_Free(gld_GLPatchTextures[patchNum]);
  988. gld_GLPatchTextures[patchNum] = NULL;
  989. }
  990. }
  991. }
  992. }
  993. }
  994. }
  995. //-----------------------------------------
  996. // now load everything that isn't already in memory
  997. //-----------------------------------------
  998. // flats
  999. for (i = numflats; --i >= 0; )
  1000. if (flatHitlist[i]) {
  1001. gld_BindFlat(gld_RegisterFlat(i,true));
  1002. DrawEmptyTriangleToForceTextureLoad(); // JDC
  1003. iphonePacifierUpdate();
  1004. }
  1005. // wall textures
  1006. for (i = numtextures; --i >= 0; )
  1007. if (wallHitlist[i]) {
  1008. gld_BindTexture(gld_RegisterTexture(i,true,false));
  1009. DrawEmptyTriangleToForceTextureLoad(); // JDC
  1010. iphonePacifierUpdate();
  1011. }
  1012. // sprites
  1013. for (i=numsprites; --i >= 0;)
  1014. if (spriteHitlist[i])
  1015. {
  1016. int j = sprites[i].numframes;
  1017. while (--j >= 0)
  1018. {
  1019. short *sflump = sprites[i].spriteframes[j].lump;
  1020. int k = 7;
  1021. do {
  1022. // JDC: changed from CR_DEFAULT to CR_LIMIT to match game behavior
  1023. gld_BindPatch(gld_RegisterPatch(firstspritelump + sflump[k],CR_LIMIT),CR_LIMIT);
  1024. DrawEmptyTriangleToForceTextureLoad();
  1025. iphonePacifierUpdate();
  1026. } while (--k >= 0);
  1027. }
  1028. }
  1029. }
  1030. void gld_CleanMemory(void)
  1031. {
  1032. #if 0 // JDC: changed to only free things not used in the current level
  1033. // that will use somewhat more memory during the transition period,
  1034. // but it makes most level transitions faster, and respawns many
  1035. // times faster.
  1036. gld_CleanTextures();
  1037. gld_CleanPatchTextures();
  1038. #endif
  1039. }