gl_texture.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. const char *gl_tex_format_string;
  71. //int gl_tex_format=GL_RGBA8;
  72. int gl_tex_format=GL_RGBA;
  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. unsigned char *buffer;
  473. if (gltexture==last_gltexture)
  474. return;
  475. last_gltexture=gltexture;
  476. if (!gltexture) {
  477. glBindTexture(GL_TEXTURE_2D, 0);
  478. last_gltexture = NULL;
  479. last_cm = -1;
  480. return;
  481. }
  482. if (gltexture->textype!=GLDT_TEXTURE)
  483. {
  484. glBindTexture(GL_TEXTURE_2D, 0);
  485. last_gltexture = NULL;
  486. last_cm = -1;
  487. return;
  488. }
  489. if (gltexture->glTexID[CR_DEFAULT]!=0)
  490. {
  491. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  492. #ifndef GL_VERSION_ES_CL_1_1 // no GL_TEXTURE_RESIDENT in GLES
  493. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  494. #ifdef _DEBUG
  495. if (i!=GL_TRUE)
  496. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  497. #endif
  498. if (i==GL_TRUE)
  499. #endif // GL_VERSION_ES_CL_1_1
  500. return;
  501. }
  502. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  503. if (!(gltexture->mipmap & use_mipmapping) & gl_paletted_texture)
  504. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  505. else
  506. memset(buffer,0,gltexture->buffer_size);
  507. patch=R_CacheTextureCompositePatchNum(gltexture->index);
  508. gld_AddPatchToTexture(gltexture, buffer, patch,
  509. 0, 0,
  510. CR_DEFAULT, !(gltexture->mipmap & use_mipmapping) & gl_paletted_texture);
  511. R_UnlockTextureCompositePatchNum(gltexture->index);
  512. if (gltexture->glTexID[CR_DEFAULT]==0)
  513. glGenTextures(1,&gltexture->glTexID[CR_DEFAULT]);
  514. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  515. #ifdef USE_GLU_MIPMAP
  516. if (gltexture->mipmap & use_mipmapping)
  517. {
  518. gluBuild2DMipmaps(GL_TEXTURE_2D, gl_tex_format,
  519. gltexture->buffer_width, gltexture->buffer_height,
  520. GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  521. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  522. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  523. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  524. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_mipmap_filter);
  525. if (gl_texture_filter_anisotropic)
  526. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0);
  527. }
  528. else
  529. #endif /* USE_GLU_MIPMAP */
  530. {
  531. #ifdef USE_GLU_IMAGESCALE
  532. if ((gltexture->buffer_width!=gltexture->tex_width) ||
  533. (gltexture->buffer_height!=gltexture->tex_height)
  534. )
  535. {
  536. unsigned char *scaledbuffer;
  537. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  538. if (scaledbuffer)
  539. {
  540. gluScaleImage(GL_RGBA,
  541. gltexture->buffer_width, gltexture->buffer_height,
  542. GL_UNSIGNED_BYTE,buffer,
  543. gltexture->tex_width, gltexture->tex_height,
  544. GL_UNSIGNED_BYTE,scaledbuffer);
  545. Z_Free(buffer);
  546. buffer=scaledbuffer;
  547. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  548. gltexture->tex_width, gltexture->tex_height,
  549. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  550. }
  551. }
  552. else
  553. #endif /* USE_GLU_IMAGESCALE */
  554. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  555. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  556. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  557. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  558. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  559. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  560. #else
  561. {
  562. if (gl_paletted_texture) {
  563. gld_SetTexturePalette(GL_TEXTURE_2D);
  564. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  565. gltexture->buffer_width, gltexture->buffer_height,
  566. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  567. } else {
  568. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  569. gltexture->buffer_width, gltexture->buffer_height,
  570. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  571. }
  572. }
  573. #endif
  574. }
  575. Z_Free(buffer);
  576. }
  577. GLTexture *gld_RegisterPatch(int lump, int cm)
  578. {
  579. const rpatch_t *patch;
  580. GLTexture *gltexture;
  581. gltexture=gld_AddNewGLPatchTexture(lump);
  582. if (!gltexture)
  583. return NULL;
  584. if (gltexture->textype==GLDT_UNREGISTERED)
  585. {
  586. patch=R_CachePatchNum(lump);
  587. if (!patch)
  588. return NULL;
  589. gltexture->textype=GLDT_BROKEN;
  590. gltexture->index=lump;
  591. gltexture->mipmap=false;
  592. gltexture->realtexwidth=patch->width;
  593. gltexture->realtexheight=patch->height;
  594. gltexture->leftoffset=patch->leftoffset;
  595. gltexture->topoffset=patch->topoffset;
  596. gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth);
  597. gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight);
  598. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  599. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  600. gltexture->buffer_width=gltexture->tex_width;
  601. gltexture->buffer_height=gltexture->tex_height;
  602. #ifdef USE_GLU_IMAGESCALE
  603. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  604. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  605. gltexture->buffer_width=MAX(gltexture->realtexwidth, gltexture->tex_width);
  606. gltexture->buffer_height=MAX(gltexture->realtexheight, gltexture->tex_height);
  607. #endif
  608. gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4;
  609. R_UnlockPatchNum(lump);
  610. if (gltexture->realtexwidth>gltexture->buffer_width)
  611. return gltexture;
  612. if (gltexture->realtexheight>gltexture->buffer_height)
  613. return gltexture;
  614. gltexture->textype=GLDT_PATCH;
  615. }
  616. return gltexture;
  617. }
  618. void gld_BindPatch(GLTexture *gltexture, int cm)
  619. {
  620. const rpatch_t *patch;
  621. unsigned char *buffer;
  622. if ((gltexture==last_gltexture) && (cm==last_cm))
  623. return;
  624. last_gltexture=gltexture;
  625. last_cm=cm;
  626. if (!gltexture)
  627. return;
  628. if (gltexture->textype!=GLDT_PATCH)
  629. {
  630. glBindTexture(GL_TEXTURE_2D, 0);
  631. last_gltexture = NULL;
  632. last_cm = -1;
  633. return;
  634. }
  635. if (gltexture->glTexID[cm]!=0)
  636. {
  637. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]);
  638. #ifndef GL_VERSION_ES_CL_1_1 // JDC no GL_TEXTURE_RESIDENT in GLES
  639. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  640. #ifdef _DEBUG
  641. if (i!=GL_TRUE)
  642. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  643. #endif
  644. if (i==GL_TRUE)
  645. #endif // GL_VERSION_ES_CL_1_1
  646. return;
  647. }
  648. patch=R_CachePatchNum(gltexture->index);
  649. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  650. if (gl_paletted_texture)
  651. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  652. else
  653. memset(buffer,0,gltexture->buffer_size);
  654. gld_AddPatchToTexture(gltexture, buffer, patch, 0, 0, cm, gl_paletted_texture);
  655. assert( cm >= 0 && cm < sizeof( gltexture->glTexID ) / sizeof( gltexture->glTexID[0] ) ); // JDC
  656. if (gltexture->glTexID[cm]==0)
  657. glGenTextures(1,&gltexture->glTexID[cm]);
  658. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[cm]);
  659. #ifdef USE_GLU_IMAGESCALE
  660. if ((gltexture->buffer_width>gltexture->tex_width) ||
  661. (gltexture->buffer_height>gltexture->tex_height)
  662. )
  663. {
  664. unsigned char *scaledbuffer;
  665. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  666. if (scaledbuffer)
  667. {
  668. gluScaleImage(GL_RGBA,
  669. gltexture->buffer_width, gltexture->buffer_height,
  670. GL_UNSIGNED_BYTE,buffer,
  671. gltexture->tex_width, gltexture->tex_height,
  672. GL_UNSIGNED_BYTE,scaledbuffer);
  673. Z_Free(buffer);
  674. buffer=scaledbuffer;
  675. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  676. gltexture->tex_width, gltexture->tex_height,
  677. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  678. }
  679. }
  680. else
  681. #endif /* USE_GLU_IMAGESCALE */
  682. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  683. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  684. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  685. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  686. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  687. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  688. #else
  689. {
  690. if (gl_paletted_texture) {
  691. gld_SetTexturePalette(GL_TEXTURE_2D);
  692. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  693. gltexture->buffer_width, gltexture->buffer_height,
  694. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  695. } else {
  696. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  697. gltexture->buffer_width, gltexture->buffer_height,
  698. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  699. }
  700. }
  701. #endif
  702. printf( "bindPatch on lump: %i '%s' : %i\n", gltexture->index, lumpinfo[ gltexture->index ].name, cm ); // !@# JDC
  703. Z_Free(buffer);
  704. R_UnlockPatchNum(gltexture->index);
  705. }
  706. GLTexture *gld_RegisterFlat(int lump, boolean mipmap)
  707. {
  708. GLTexture *gltexture;
  709. gltexture=gld_AddNewGLPatchTexture(firstflat+lump);
  710. if (!gltexture)
  711. return NULL;
  712. if (gltexture->textype==GLDT_UNREGISTERED)
  713. {
  714. gltexture->textype=GLDT_BROKEN;
  715. gltexture->index=firstflat+lump;
  716. gltexture->mipmap=mipmap;
  717. gltexture->realtexwidth=64;
  718. gltexture->realtexheight=64;
  719. gltexture->leftoffset=0;
  720. gltexture->topoffset=0;
  721. gltexture->tex_width=gld_GetTexDimension(gltexture->realtexwidth);
  722. gltexture->tex_height=gld_GetTexDimension(gltexture->realtexheight);
  723. gltexture->width=MIN(gltexture->realtexwidth, gltexture->tex_width);
  724. gltexture->height=MIN(gltexture->realtexheight, gltexture->tex_height);
  725. gltexture->buffer_width=gltexture->tex_width;
  726. gltexture->buffer_height=gltexture->tex_height;
  727. #ifdef USE_GLU_IMAGESCALE
  728. gltexture->width=gltexture->tex_width;
  729. gltexture->height=gltexture->tex_height;
  730. gltexture->buffer_width=gltexture->realtexwidth;
  731. gltexture->buffer_height=gltexture->realtexheight;
  732. #endif
  733. if (gltexture->mipmap & use_mipmapping)
  734. {
  735. gltexture->width=gltexture->tex_width;
  736. gltexture->height=gltexture->tex_height;
  737. gltexture->buffer_width=gltexture->realtexwidth;
  738. gltexture->buffer_height=gltexture->realtexheight;
  739. }
  740. gltexture->buffer_size=gltexture->buffer_width*gltexture->buffer_height*4;
  741. if (gltexture->realtexwidth>gltexture->buffer_width)
  742. return gltexture;
  743. if (gltexture->realtexheight>gltexture->buffer_height)
  744. return gltexture;
  745. gltexture->textype=GLDT_FLAT;
  746. }
  747. return gltexture;
  748. }
  749. void gld_BindFlat(GLTexture *gltexture)
  750. {
  751. const unsigned char *flat;
  752. unsigned char *buffer;
  753. if (gltexture==last_gltexture)
  754. return;
  755. last_gltexture=gltexture;
  756. if (!gltexture)
  757. return;
  758. if (gltexture->textype!=GLDT_FLAT)
  759. {
  760. glBindTexture(GL_TEXTURE_2D, 0);
  761. last_gltexture = NULL;
  762. last_cm = -1;
  763. return;
  764. }
  765. if (gltexture->glTexID[CR_DEFAULT]!=0)
  766. {
  767. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  768. #ifndef GL_VERSION_ES_CL_1_1 // no GL_TEXTURE_RESIDENT in GLES
  769. glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_RESIDENT,&i);
  770. #ifdef _DEBUG
  771. if (i!=GL_TRUE)
  772. lprintf(LO_INFO, "glGetTexParam: %i\n", i);
  773. #endif
  774. if (i==GL_TRUE)
  775. #endif // GL_VERSION_ES_CL_1_1
  776. return;
  777. }
  778. flat=W_CacheLumpNum(gltexture->index);
  779. buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  780. if (!(gltexture->mipmap & use_mipmapping) & gl_paletted_texture)
  781. memset(buffer,transparent_pal_index,gltexture->buffer_size);
  782. else
  783. memset(buffer,0,gltexture->buffer_size);
  784. gld_AddFlatToTexture(gltexture, buffer, flat, !(gltexture->mipmap & use_mipmapping) & gl_paletted_texture);
  785. if (gltexture->glTexID[CR_DEFAULT]==0)
  786. glGenTextures(1,&gltexture->glTexID[CR_DEFAULT]);
  787. glBindTexture(GL_TEXTURE_2D, gltexture->glTexID[CR_DEFAULT]);
  788. #if USE_GLU_MIPMAP
  789. if (gltexture->mipmap & use_mipmapping)
  790. {
  791. gluBuild2DMipmaps(GL_TEXTURE_2D, gl_tex_format,
  792. gltexture->buffer_width, gltexture->buffer_height,
  793. GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  794. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  795. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  796. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  797. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_mipmap_filter);
  798. if (gl_texture_filter_anisotropic)
  799. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0);
  800. }
  801. else
  802. #endif /* USE_GLU_MIPMAP */
  803. {
  804. #ifdef USE_GLU_IMAGESCALE
  805. if ((gltexture->buffer_width!=gltexture->tex_width) ||
  806. (gltexture->buffer_height!=gltexture->tex_height)
  807. )
  808. {
  809. unsigned char *scaledbuffer;
  810. scaledbuffer=(unsigned char*)Z_Malloc(gltexture->tex_width*gltexture->tex_height*4,PU_STATIC,0);
  811. if (scaledbuffer)
  812. {
  813. gluScaleImage(GL_RGBA,
  814. gltexture->buffer_width, gltexture->buffer_height,
  815. GL_UNSIGNED_BYTE,buffer,
  816. gltexture->tex_width, gltexture->tex_height,
  817. GL_UNSIGNED_BYTE,scaledbuffer);
  818. Z_Free(buffer);
  819. buffer=scaledbuffer;
  820. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  821. gltexture->tex_width, gltexture->tex_height,
  822. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  823. }
  824. }
  825. else
  826. #endif /* USE_GLU_IMAGESCALE */
  827. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  828. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  829. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_tex_filter);
  830. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_tex_filter);
  831. #ifdef IPHONE // JDC, convert the texture to 16 bit and mipmap
  832. gld_UploadAndMip32BitTexture( gltexture->buffer_width, gltexture->buffer_height, buffer);
  833. #else
  834. {
  835. if (gl_paletted_texture) {
  836. gld_SetTexturePalette(GL_TEXTURE_2D);
  837. glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT,
  838. gltexture->buffer_width, gltexture->buffer_height,
  839. 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, buffer);
  840. } else {
  841. glTexImage2D( GL_TEXTURE_2D, 0, gl_tex_format,
  842. gltexture->buffer_width, gltexture->buffer_height,
  843. 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  844. }
  845. }
  846. #endif
  847. }
  848. Z_Free(buffer);
  849. W_UnlockLumpNum(gltexture->index);
  850. }
  851. static void gld_CleanTextures(void)
  852. {
  853. int i,j;
  854. if (!gld_GLTextures)
  855. return;
  856. for (i=0; i<numtextures; i++)
  857. {
  858. GLTexture * texture = gld_GLTextures[i];
  859. if (texture)
  860. {
  861. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++) {
  862. GLuint handle = texture->glTexID[j];
  863. glDeleteTextures(1,&handle);
  864. }
  865. Z_Free(texture);
  866. gld_GLTextures[i] = NULL;
  867. }
  868. }
  869. Z_Free( gld_GLTextures );
  870. gld_GLTextures = NULL;
  871. numtextures = 0;
  872. }
  873. static void gld_CleanPatchTextures(void)
  874. {
  875. int i,j;
  876. if (!gld_GLPatchTextures)
  877. return;
  878. for (i=0; i<numlumps; i++)
  879. {
  880. if (gld_GLPatchTextures[i])
  881. {
  882. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  883. glDeleteTextures(1,&(gld_GLPatchTextures[i]->glTexID[j]));
  884. Z_Free(gld_GLPatchTextures[i]);
  885. gld_GLPatchTextures[i] = NULL;
  886. }
  887. }
  888. Z_Free( gld_GLPatchTextures );
  889. gld_GLPatchTextures = NULL;
  890. }
  891. void DrawEmptyTriangleToForceTextureLoad() { // JDC
  892. // The iPhone OpenGL driver (and many others), don't
  893. // do all the texture loading work until it is actually
  894. // used to draw something. If you want to avoid all
  895. // hitches during gameplay, call this after binding
  896. // during the precache.
  897. glBegin( GL_TRIANGLES );
  898. glVertex2f( 0, 0 );
  899. glVertex2f( 0, 0 );
  900. glVertex2f( 0, 0 );
  901. glEnd();
  902. }
  903. void gld_Precache(void)
  904. {
  905. int i, j, k;
  906. byte *flatHitlist = alloca( numflats );
  907. byte *wallHitlist = alloca( numtextures );
  908. byte *spriteHitlist = alloca( numsprites );
  909. // JDC: significant rework here to also take over the
  910. // work of gld_CleanMemory() and avoid freeing and reloading
  911. // things that are still needed, making respawning many times
  912. // faster.
  913. // this updates the spinning wheel icon as we load textures
  914. void iphonePacifierUpdate();
  915. // JDC if (demoplayback)
  916. // JDC return;
  917. //-----------------------------------------
  918. // find everything we will need before loading anything
  919. //-----------------------------------------
  920. // find flats
  921. memset(flatHitlist, 0, numflats);
  922. for (i = numsectors; --i >= 0; ) {
  923. // JDC: todo: get animated flats
  924. assert( (unsigned)sectors[i].floorpic < numflats );
  925. assert( (unsigned)sectors[i].ceilingpic < numflats );
  926. flatHitlist[sectors[i].floorpic] = 1;
  927. flatHitlist[sectors[i].ceilingpic] = 1;
  928. }
  929. // find walls
  930. memset(wallHitlist, 0, numtextures);
  931. for (i = numsides; --i >= 0;) {
  932. assert( (unsigned)sides[i].bottomtexture < numtextures );
  933. assert( (unsigned)sides[i].toptexture < numtextures );
  934. assert( (unsigned)sides[i].midtexture < numtextures );
  935. wallHitlist[sides[i].bottomtexture] = 1;
  936. wallHitlist[sides[i].toptexture] = 1;
  937. wallHitlist[sides[i].midtexture] = 1;
  938. }
  939. // Sky texture is always present.
  940. // Note that F_SKY1 is the name used to
  941. // indicate a sky floor/ceiling as a flat,
  942. // while the sky texture is stored like
  943. // a wall texture, with an episode dependend
  944. // name.
  945. wallHitlist[skytexture] = 1;
  946. // find sprites
  947. memset(spriteHitlist, 0, numsprites);
  948. for ( i = 0 ; i < numsectors ; i++ ) {
  949. for ( mobj_t *thing = sectors[i].thinglist; thing; thing = thing->snext) {
  950. assert( (unsigned)thing->sprite < numsprites );
  951. spriteHitlist[thing->sprite] = 1;
  952. }
  953. }
  954. //-----------------------------------------
  955. // free textures not used
  956. //-----------------------------------------
  957. if ( gld_GLPatchTextures ) {
  958. for (i = numflats; --i >= 0; ) {
  959. if (!flatHitlist[i]) {
  960. int patchNum = firstflat + i;
  961. if ( gld_GLPatchTextures[patchNum] ) {
  962. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  963. glDeleteTextures(1,(GLuint *)&(gld_GLPatchTextures[patchNum]->glTexID[j]));
  964. Z_Free(gld_GLPatchTextures[patchNum]);
  965. gld_GLPatchTextures[patchNum] = NULL;
  966. }
  967. }
  968. }
  969. }
  970. if ( gld_GLTextures ) {
  971. for (i = numtextures; --i >= 0; ) {
  972. if ( !wallHitlist[i] ) {
  973. if (gld_GLTextures[i]) {
  974. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  975. glDeleteTextures(1,(GLuint *)&(gld_GLTextures[i]->glTexID[j]));
  976. Z_Free(gld_GLTextures[i]);
  977. gld_GLTextures[i] = NULL;
  978. }
  979. }
  980. }
  981. }
  982. if ( gld_GLPatchTextures ) {
  983. for (i=numsprites; --i >= 0;) {
  984. if ( !spriteHitlist[i] ) {
  985. for (j = 0 ; j < sprites[i].numframes ; j++ ) {
  986. short *sflump = sprites[i].spriteframes[j].lump;
  987. for ( k = 0 ; k < 7 ; k++ ) {
  988. int patchNum = firstspritelump + sflump[k];
  989. if ( gld_GLPatchTextures[patchNum] ) {
  990. for (j=0; j<(CR_LIMIT+MAXPLAYERS); j++)
  991. glDeleteTextures(1,(GLuint *)&(gld_GLPatchTextures[patchNum]->glTexID[j]));
  992. Z_Free(gld_GLPatchTextures[patchNum]);
  993. gld_GLPatchTextures[patchNum] = NULL;
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. //-----------------------------------------
  1001. // now load everything that isn't already in memory
  1002. //-----------------------------------------
  1003. // flats
  1004. for (i = numflats; --i >= 0; )
  1005. if (flatHitlist[i]) {
  1006. gld_BindFlat(gld_RegisterFlat(i,true));
  1007. DrawEmptyTriangleToForceTextureLoad(); // JDC
  1008. iphonePacifierUpdate();
  1009. }
  1010. // wall textures
  1011. for (i = numtextures; --i >= 0; )
  1012. if (wallHitlist[i]) {
  1013. gld_BindTexture(gld_RegisterTexture(i,true,false));
  1014. DrawEmptyTriangleToForceTextureLoad(); // JDC
  1015. iphonePacifierUpdate();
  1016. }
  1017. // sprites
  1018. for (i=numsprites; --i >= 0;)
  1019. if (spriteHitlist[i])
  1020. {
  1021. j = sprites[i].numframes;
  1022. while (--j >= 0)
  1023. {
  1024. short *sflump = sprites[i].spriteframes[j].lump;
  1025. k = 7;
  1026. do {
  1027. // JDC: changed from CR_DEFAULT to CR_LIMIT to match game behavior
  1028. gld_BindPatch(gld_RegisterPatch(firstspritelump + sflump[k],CR_LIMIT),CR_LIMIT);
  1029. DrawEmptyTriangleToForceTextureLoad();
  1030. iphonePacifierUpdate();
  1031. } while (--k >= 0);
  1032. }
  1033. }
  1034. }
  1035. void gld_CleanMemory(void)
  1036. {
  1037. gld_CleanTextures();
  1038. gld_CleanPatchTextures();
  1039. }