vkQuake2 doxygen  1.0 dev
r_surf.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 // r_surf.c: surface-related refresh code
21 
22 #include "r_local.h"
23 
25 
29 unsigned blockdivmask;
31 unsigned char *pbasesource;
32 int surfrowbytes; // used by ASM files
33 //unsigned *r_lightptr;
34 int *r_lightptr; // leilei - colored lighting
38 unsigned char *r_source, *r_sourcemax;
39 
40 void R_DrawSurfaceBlock8_mip0 (void);
41 void R_DrawSurfaceBlock8_mip1 (void);
42 void R_DrawSurfaceBlock8_mip2 (void);
43 void R_DrawSurfaceBlock8_mip3 (void);
44 
45 static void (*surfmiptable[4])(void) = {
50 };
51 
52 
53 
54 // leilei - Colored Lights - Begin
55 
56 // leilei - Colored Lights
57 
58 
62 
63 // Macros
64 
65 // Macros for initiating the RGB light deltas.
66 #define MakeLightDelta() { light[0] = lightrighta[0]; light[1] = lightrighta[1]; light[2] = lightrighta[2];};
67 #define PushLightDelta() { light[0] += lightdelta[0]; light[1] += lightdelta[1]; light[2] += lightdelta[2]; };
68 #define FinishLightDelta() { psource += sourcetstep; lightrighta[0] += lightrightstepa[0];lightlefta[0] += lightleftstepa[0];lightdelta[0] += lightdeltastep[0]; lightrighta[1] += lightrightstepa[1];lightlefta[1] += lightleftstepa[1];lightdelta[1] += lightdeltastep[1]; lightrighta[2] += lightrightstepa[2];lightlefta[2] += lightleftstepa[2];lightdelta[2] += lightdeltastep[2]; prowdest += surfrowbytes;}
69 
70 // High Colored Light Quality //qb: preserve alphatest
71 #define MIP8RGBX(i) { pix = psource[i]; if(pix == 255) prowdest[i] = 255; else{pix24 = (unsigned char *)&d_8to24table[pix]; \
72  trans[0] = (pix24[0] * (light[0])) >> 17; trans[1] = (pix24[1] * (light[1])) >> 17; trans[2] = (pix24[2] * (light[2])) >> 17; \
73 if (trans[0] & ~63) trans[0] = 63; if (trans[1] & ~63) trans[1] = 63; if (trans[2] & ~63) trans[2] = 63; prowdest[i] = palmap2[trans[0]][trans[1]][trans[2]]; }}
74 
75 #define Mip0Stuff(i) { MakeLightDelta(); i(15); PushLightDelta(); i(14); PushLightDelta(); PushLightDelta(); i(13); PushLightDelta(); i(12); PushLightDelta(); i(11); PushLightDelta(); i(10); PushLightDelta(); i(9); PushLightDelta(); i(8); PushLightDelta(); i(7); PushLightDelta(); i(6); PushLightDelta(); i(5); PushLightDelta(); i(4); PushLightDelta(); i(3); PushLightDelta(); i(2); PushLightDelta(); i(1); PushLightDelta(); i(0); FinishLightDelta();}
76 #define Mip1Stuff(i) { MakeLightDelta(); i(7); PushLightDelta(); i(6); PushLightDelta(); i(5); PushLightDelta(); i(4); PushLightDelta(); i(3); PushLightDelta(); i(2); PushLightDelta(); i(1); PushLightDelta(); i(0); FinishLightDelta();}
77 #define Mip2Stuff(i) { MakeLightDelta();i(3); PushLightDelta(); i(2); PushLightDelta(); i(1); PushLightDelta(); i(0); FinishLightDelta();}
78 #define Mip3Stuff(i) { MakeLightDelta(); i(1); PushLightDelta(); i(0); FinishLightDelta();}
79 
80 // o^_^o
81 
82 static void R_DrawSurfaceBlock8RGBX_mip0(void);
83 static void R_DrawSurfaceBlock8RGBX_mip1(void);
84 static void R_DrawSurfaceBlock8RGBX_mip2(void);
85 static void R_DrawSurfaceBlock8RGBX_mip3(void);
86 
87 
88 static void (*surfmiptable8RGB[4])(void) =
89 {
94 };
95 
96 //extern int host_fullbrights; // for preserving fullbrights in color operations
97 //extern byte *lmmap;
98 extern byte palmap2[64][64][64]; // Colored Lighting Lookup Table
99 
100 
101 
102 // leilei - Colored Lights - End
103 
104 void R_BuildLightMap (void);
105 //extern unsigned blocklights[1024]; // allow some very large lightmaps
106 //extern unsigned blocklights[1024*3]; // leilei - colored lights
107 extern unsigned blocklights[18*18*3]; // leilei - colored lights
108 
109 float surfscale;
110 qboolean r_cache_thrash; // set if surface cache is thrashing
111 
114 
115 /*
116 ===============
117 R_TextureAnimation
118 
119 Returns the proper texture for a given time and base texture
120 ===============
121 */
123 {
124  int c;
125 
126  if (!tex->next)
127  return tex->image;
128 
129  c = currententity->frame % tex->numframes;
130  while (c)
131  {
132  tex = tex->next;
133  c--;
134  }
135 
136  return tex->image;
137 }
138 
139 
140 /*
141 ===============
142 R_DrawSurface
143 ===============
144 */
145 void R_DrawSurface (void)
146 {
147  unsigned char *basetptr;
148  int smax, tmax, twidth;
149  int u;
150  int soffset, basetoffset, texwidth;
151  int horzblockstep;
152  unsigned char *pcolumndest;
153  void (*pblockdrawer)(void);
154  image_t *mt;
155 
157 
158  mt = r_drawsurf.image;
159 
161 
162 // the fractional light values should range from 0 to (VID_GRADES - 1) << 16
163 // from a source range of 0 - 255
164 
165  texwidth = mt->width >> r_drawsurf.surfmip;
166 
167  blocksize = 16 >> r_drawsurf.surfmip;
169  blockdivmask = (1 << blockdivshift) - 1;
170 
171  r_lightwidth = (r_drawsurf.surf->extents[0]>>4)+1;
172 
175 
176 //==============================
177  if (coloredlights)
178  pblockdrawer = surfmiptable8RGB[r_drawsurf.surfmip]; // leilei - colored lights
179  else
180  pblockdrawer = surfmiptable[r_drawsurf.surfmip];
181 
182 // TODO: only needs to be set when there is a display settings change
183  horzblockstep = blocksize;
184 
185  smax = mt->width >> r_drawsurf.surfmip;
186  twidth = texwidth;
187  tmax = mt->height >> r_drawsurf.surfmip;
188  sourcetstep = texwidth;
189  r_stepback = tmax * twidth;
190 
191  r_sourcemax = r_source + (tmax * smax);
192 
193  soffset = r_drawsurf.surf->texturemins[0];
194  basetoffset = r_drawsurf.surf->texturemins[1];
195 
196 // << 16 components are to guarantee positive values for %
197  soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax;
198  basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip)
199  + (tmax << 16)) % tmax) * twidth)];
200 
201  pcolumndest = r_drawsurf.surfdat;
202 
203  for (u=0 ; u<r_numhblocks; u++)
204  {
205  // leilei - colored lights
206  if (coloredlights)
207  r_lightptr = (int*)blocklights + u * 3;
208  else
209  // o^_^o
210  r_lightptr = (int*)blocklights + u;
211 
212  prowdestbase = pcolumndest;
213 
214  pbasesource = basetptr + soffset;
215 
216  (*pblockdrawer)();
217 
218  soffset = soffset + blocksize;
219  if (soffset >= smax)
220  soffset = 0;
221 
222  pcolumndest += horzblockstep;
223  }
224 }
225 
226 
227 //=============================================================================
228 
229 #if !id386
230 
231 /*
232 ================
233 R_DrawSurfaceBlock8_mip0
234 ================
235 */
237 {
238  int v, i, b, lightstep, lighttemp, light;
239  unsigned char pix, *psource, *prowdest;
240 
241  psource = pbasesource;
242  prowdest = prowdestbase;
243 
244  for (v=0 ; v<r_numvblocks ; v++)
245  {
246  // FIXME: make these locals?
247  // FIXME: use delta rather than both right and left, like ASM?
248  lightleft = r_lightptr[0];
249  lightright = r_lightptr[1];
251  lightleftstep = (r_lightptr[0] - lightleft) >> 4;
252  lightrightstep = (r_lightptr[1] - lightright) >> 4;
253 
254  for (i=0 ; i<16 ; i++)
255  {
256  lighttemp = lightleft - lightright;
257  lightstep = lighttemp >> 4;
258 
259  light = lightright;
260 
261  for (b=15; b>=0; b--)
262  {
263  pix = psource[b];
264  prowdest[b] = ((unsigned char *)vid.colormap)
265  [(light & 0xFF00) + pix];
266  light += lightstep;
267  }
268 
269  psource += sourcetstep;
272  prowdest += surfrowbytes;
273  }
274 
275  if (psource >= r_sourcemax)
276  psource -= r_stepback;
277  }
278 }
279 
280 
281 /*
282 ================
283 R_DrawSurfaceBlock8_mip1
284 ================
285 */
287 {
288  int v, i, b, lightstep, lighttemp, light;
289  unsigned char pix, *psource, *prowdest;
290 
291  psource = pbasesource;
292  prowdest = prowdestbase;
293 
294  for (v=0 ; v<r_numvblocks ; v++)
295  {
296  // FIXME: make these locals?
297  // FIXME: use delta rather than both right and left, like ASM?
298  lightleft = r_lightptr[0];
299  lightright = r_lightptr[1];
301  lightleftstep = (r_lightptr[0] - lightleft) >> 3;
302  lightrightstep = (r_lightptr[1] - lightright) >> 3;
303 
304  for (i=0 ; i<8 ; i++)
305  {
306  lighttemp = lightleft - lightright;
307  lightstep = lighttemp >> 3;
308 
309  light = lightright;
310 
311  for (b=7; b>=0; b--)
312  {
313  pix = psource[b];
314  prowdest[b] = ((unsigned char *)vid.colormap)
315  [(light & 0xFF00) + pix];
316  light += lightstep;
317  }
318 
319  psource += sourcetstep;
322  prowdest += surfrowbytes;
323  }
324 
325  if (psource >= r_sourcemax)
326  psource -= r_stepback;
327  }
328 }
329 
330 
331 /*
332 ================
333 R_DrawSurfaceBlock8_mip2
334 ================
335 */
337 {
338  int v, i, b, lightstep, lighttemp, light;
339  unsigned char pix, *psource, *prowdest;
340 
341  psource = pbasesource;
342  prowdest = prowdestbase;
343 
344  for (v=0 ; v<r_numvblocks ; v++)
345  {
346  // FIXME: make these locals?
347  // FIXME: use delta rather than both right and left, like ASM?
348  lightleft = r_lightptr[0];
349  lightright = r_lightptr[1];
351  lightleftstep = (r_lightptr[0] - lightleft) >> 2;
352  lightrightstep = (r_lightptr[1] - lightright) >> 2;
353 
354  for (i=0 ; i<4 ; i++)
355  {
356  lighttemp = lightleft - lightright;
357  lightstep = lighttemp >> 2;
358 
359  light = lightright;
360 
361  for (b=3; b>=0; b--)
362  {
363  pix = psource[b];
364  prowdest[b] = ((unsigned char *)vid.colormap)
365  [(light & 0xFF00) + pix];
366  light += lightstep;
367  }
368 
369  psource += sourcetstep;
372  prowdest += surfrowbytes;
373  }
374 
375  if (psource >= r_sourcemax)
376  psource -= r_stepback;
377  }
378 }
379 
380 
381 /*
382 ================
383 R_DrawSurfaceBlock8_mip3
384 ================
385 */
387 {
388  int v, i, b, lightstep, lighttemp, light;
389  unsigned char pix, *psource, *prowdest;
390 
391  psource = pbasesource;
392  prowdest = prowdestbase;
393 
394  for (v=0 ; v<r_numvblocks ; v++)
395  {
396  // FIXME: make these locals?
397  // FIXME: use delta rather than both right and left, like ASM?
398  lightleft = r_lightptr[0];
399  lightright = r_lightptr[1];
401  lightleftstep = (r_lightptr[0] - lightleft) >> 1;
402  lightrightstep = (r_lightptr[1] - lightright) >> 1;
403 
404  for (i=0 ; i<2 ; i++)
405  {
406  lighttemp = lightleft - lightright;
407  lightstep = lighttemp >> 1;
408 
409  light = lightright;
410 
411  for (b=1; b>=0; b--)
412  {
413  pix = psource[b];
414  prowdest[b] = ((unsigned char *)vid.colormap)
415  [(light & 0xFF00) + pix];
416  light += lightstep;
417  }
418 
419  psource += sourcetstep;
422  prowdest += surfrowbytes;
423  }
424 
425  if (psource >= r_sourcemax)
426  psource -= r_stepback;
427  }
428 }
429 
430 #endif
431 
432 
433 //============================================================================
434 
435 
436 /*
437 ================
438 R_InitCaches
439 
440 ================
441 */
442 void R_InitCaches (void)
443 {
444  int size;
445  int pix;
446 
447  // calculate size to allocate
449  {
450  size = sw_surfcacheoverride->value;
451  }
452  else
453  {
455 
456  pix = vid.width*vid.height;
457  if (pix > 64000)
458  size += (pix-64000)*3;
459  }
460 
461  // round up to page size
462  size = (size + 8191) & ~8191;
463 
464  ri.Con_Printf (PRINT_ALL,"%ik surface cache\n", size/1024);
465 
466  sc_size = size;
467  sc_base = (surfcache_t *)malloc(size);
468  sc_rover = sc_base;
469 
470  sc_base->next = NULL;
471  sc_base->owner = NULL;
472  sc_base->size = sc_size;
473 }
474 
475 
476 /*
477 ==================
478 D_FlushCaches
479 ==================
480 */
481 void D_FlushCaches (void)
482 {
483  surfcache_t *c;
484 
485  if (!sc_base)
486  return;
487 
488  for (c = sc_base ; c ; c = c->next)
489  {
490  if (c->owner)
491  *c->owner = NULL;
492  }
493 
494  sc_rover = sc_base;
495  sc_base->next = NULL;
496  sc_base->owner = NULL;
497  sc_base->size = sc_size;
498 }
499 
500 /*
501 =================
502 D_SCAlloc
503 =================
504 */
505 surfcache_t *D_SCAlloc (int width, int size)
506 {
507  surfcache_t *new;
508  qboolean wrapped_this_time;
509 
510  if ((width < 0) || (width > 256))
511  ri.Sys_Error (ERR_FATAL,"D_SCAlloc: bad cache width %d\n", width);
512 
513  if ((size <= 0) || (size > 0x10000))
514  ri.Sys_Error (ERR_FATAL,"D_SCAlloc: bad cache size %d\n", size);
515 
516  size = (intptr_t)&((surfcache_t *)0)->data[size];
517  size = (size + 3) & ~3;
518  if (size > sc_size)
519  ri.Sys_Error (ERR_FATAL,"D_SCAlloc: %i > cache size of %i",size, sc_size);
520 
521 // if there is not size bytes after the rover, reset to the start
522  wrapped_this_time = false;
523 
524  if ( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size)
525  {
526  if (sc_rover)
527  {
528  wrapped_this_time = true;
529  }
530  sc_rover = sc_base;
531  }
532 
533 // colect and free surfcache_t blocks until the rover block is large enough
534  new = sc_rover;
535  if (sc_rover->owner)
536  *sc_rover->owner = NULL;
537 
538  while (new->size < size)
539  {
540  // free another
542  if (!sc_rover)
543  ri.Sys_Error (ERR_FATAL,"D_SCAlloc: hit the end of memory");
544  if (sc_rover->owner)
545  *sc_rover->owner = NULL;
546 
547  new->size += sc_rover->size;
548  new->next = sc_rover->next;
549  }
550 
551 // create a fragment out of any leftovers
552  if (new->size - size > 256)
553  {
554  sc_rover = (surfcache_t *)( (byte *)new + size);
555  sc_rover->size = new->size - size;
556  sc_rover->next = new->next;
557  sc_rover->width = 0;
558  sc_rover->owner = NULL;
559  new->next = sc_rover;
560  new->size = size;
561  }
562  else
563  sc_rover = new->next;
564 
565  new->width = width;
566 // DEBUG
567  if (width > 0)
568  new->height = (size - sizeof(*new) + sizeof(new->data)) / width;
569 
570  new->owner = NULL; // should be set properly after return
571 
572  if (d_roverwrapped)
573  {
574  if (wrapped_this_time || (sc_rover >= d_initial_rover))
575  r_cache_thrash = true;
576  }
577  else if (wrapped_this_time)
578  {
579  d_roverwrapped = true;
580  }
581 
582  return new;
583 }
584 
585 
586 /*
587 =================
588 D_SCDump
589 =================
590 */
591 void D_SCDump (void)
592 {
593  surfcache_t *test;
594 
595  for (test = sc_base ; test ; test = test->next)
596  {
597  if (test == sc_rover)
598  ri.Con_Printf (PRINT_ALL,"ROVER:\n");
599  ri.Con_Printf (PRINT_ALL,"%p : %i bytes %i width\n",test, test->size, test->width);
600  }
601 }
602 
603 //=============================================================================
604 
605 // if the num is not a power of 2, assume it will not repeat
606 
607 int MaskForNum (int num)
608 {
609  if (num==128)
610  return 127;
611  if (num==64)
612  return 63;
613  if (num==32)
614  return 31;
615  if (num==16)
616  return 15;
617  return 255;
618 }
619 
620 int D_log2 (int num)
621 {
622  int c;
623 
624  c = 0;
625 
626  while (num>>=1)
627  c++;
628  return c;
629 }
630 
631 //=============================================================================
632 void R_BuildLightMapRGB (void);
633 /*
634 ================
635 D_CacheSurface
636 ================
637 */
639 {
640  surfcache_t *cache;
641 
642 //
643 // if the surface is animating or flashing, flush the cache
644 //
646  r_drawsurf.lightadj[0] = r_newrefdef.lightstyles[surface->styles[0]].white*128;
647  r_drawsurf.lightadj[1] = r_newrefdef.lightstyles[surface->styles[1]].white*128;
648  r_drawsurf.lightadj[2] = r_newrefdef.lightstyles[surface->styles[2]].white*128;
649  r_drawsurf.lightadj[3] = r_newrefdef.lightstyles[surface->styles[3]].white*128;
650 
651 //
652 // see if the cache holds apropriate data
653 //
654  cache = surface->cachespots[miplevel];
655 
656  if (cache && !cache->dlight && surface->dlightframe != r_framecount
657  && cache->image == r_drawsurf.image
658  && cache->lightadj[0] == r_drawsurf.lightadj[0]
659  && cache->lightadj[1] == r_drawsurf.lightadj[1]
660  && cache->lightadj[2] == r_drawsurf.lightadj[2]
661  && cache->lightadj[3] == r_drawsurf.lightadj[3] )
662  return cache;
663 
664 //
665 // determine shape of surface
666 //
667  surfscale = 1.0 / (1<<miplevel);
669  r_drawsurf.surfwidth = surface->extents[0] >> miplevel;
671  r_drawsurf.surfheight = surface->extents[1] >> miplevel;
672 
673 //
674 // allocate memory if needed
675 //
676  if (!cache) // if a texture just animated, don't reallocate it
677  {
678  cache = D_SCAlloc (r_drawsurf.surfwidth,
680  surface->cachespots[miplevel] = cache;
681  cache->owner = &surface->cachespots[miplevel];
682  cache->mipscale = surfscale;
683  }
684 
685  if (surface->dlightframe == r_framecount)
686  cache->dlight = 1;
687  else
688  cache->dlight = 0;
689 
690  r_drawsurf.surfdat = (pixel_t *)cache->data;
691 
692  cache->image = r_drawsurf.image;
693  cache->lightadj[0] = r_drawsurf.lightadj[0];
694  cache->lightadj[1] = r_drawsurf.lightadj[1];
695  cache->lightadj[2] = r_drawsurf.lightadj[2];
696  cache->lightadj[3] = r_drawsurf.lightadj[3];
697 
698 //
699 // draw and light the surface texture
700 //
701  r_drawsurf.surf = surface;
702 
703  c_surf++;
704 
705  // calculate the lightings
706  if (coloredlights)
707  R_BuildLightMapRGB(); // leilei - colored lights
708  else
709  R_BuildLightMap();
710 
711  // rasterize the surface into the cache
712  R_DrawSurface ();
713 
714  return cache;
715 }
716 
717 
718 
719 
720 // leilei
721 // here it comes
722 
723 
725 {
726  unsigned int v, i;
727  unsigned int light[3];
728  unsigned int lightdelta[3], lightdeltastep[3];
729  unsigned char pix, *psource, *prowdest;
730  unsigned char *pix24;
731  unsigned trans[3];
732  psource = pbasesource;
733  prowdest = prowdestbase;
734 
735 #pragma loop(hint_parallel(8)) //qb: try this
736  for (v=0 ; v<r_numvblocks ; v++)
737  {
738  lightlefta[0] = r_lightptr[0];
739  lightrighta[0] = r_lightptr[3];
740  lightlefta[1] = r_lightptr[0+1];
741  lightrighta[1] = r_lightptr[3+1];
742  lightlefta[2] = r_lightptr[0+2];
743  lightrighta[2] = r_lightptr[3+2];
744 
745  lightdelta[0] = (lightlefta[0] - lightrighta[0]) >> 4;
746  lightdelta[1] = (lightlefta[1] - lightrighta[1]) >> 4;
747  lightdelta[2] = (lightlefta[2] - lightrighta[2]) >> 4;
748 
749 
750  r_lightptr += r_lightwidth * 3;
751 
752  lightleftstepa[0] = (r_lightptr[0] - lightlefta[0]) >> 4;
753  lightrightstepa[0] = (r_lightptr[3] - lightrighta[0]) >> 4;
754 
755  lightleftstepa[1] = (r_lightptr[0+1] - lightlefta[1]) >> 4;
756  lightrightstepa[1] = (r_lightptr[3+1] - lightrighta[1]) >> 4;
757 
758  lightleftstepa[2] = (r_lightptr[0+2] - lightlefta[2]) >> 4;
759  lightrightstepa[2] = (r_lightptr[3+2] - lightrighta[2]) >> 4;
760 
761  lightdeltastep[0] = (lightleftstepa[0] - lightrightstepa[0]) >> 4;
762  lightdeltastep[1] = (lightleftstepa[1] - lightrightstepa[1]) >> 4;
763  lightdeltastep[2] = (lightleftstepa[2] - lightrightstepa[2]) >> 4;
764 
765 
766  for (i=0 ; i<16 ; i++)
767  {
769 
770  }
771 
772  if (psource >= r_sourcemax)
773  psource -= r_stepback;
774 
775  }
776 }
777 
778 
779 
780 
782 {
783  unsigned int v, i;
784  unsigned int light[3];
785  unsigned int lightdelta[3], lightdeltastep[3];
786  unsigned char pix, *psource, *prowdest;
787  unsigned char *pix24;
788  unsigned trans[3];
789  psource = pbasesource;
790 
791  prowdest = prowdestbase;
792 
793 #pragma loop(hint_parallel(8)) //qb: try this
794  for (v=0 ; v<r_numvblocks ; v++)
795  {
796  lightlefta[0] = r_lightptr[0];
797  lightrighta[0] = r_lightptr[3];
798  lightlefta[1] = r_lightptr[0+1];
799  lightrighta[1] = r_lightptr[3+1];
800  lightlefta[2] = r_lightptr[0+2];
801  lightrighta[2] = r_lightptr[3+2];
802 
803  lightdelta[0] = (lightlefta[0] - lightrighta[0]) >> 3;
804  lightdelta[1] = (lightlefta[1] - lightrighta[1]) >> 3;
805  lightdelta[2] = (lightlefta[2] - lightrighta[2]) >> 3;
806 
807 
808  r_lightptr += r_lightwidth * 3;
809 
810  lightleftstepa[0] = (r_lightptr[0] - lightlefta[0]) >> 3;
811  lightrightstepa[0] = (r_lightptr[3] - lightrighta[0]) >> 3;
812 
813  lightleftstepa[1] = (r_lightptr[0+1] - lightlefta[1]) >> 3;
814  lightrightstepa[1] = (r_lightptr[3+1] - lightrighta[1]) >> 3;
815 
816  lightleftstepa[2] = (r_lightptr[0+2] - lightlefta[2]) >> 3;
817  lightrightstepa[2] = (r_lightptr[3+2] - lightrighta[2]) >> 3;
818 
819  lightdeltastep[0] = (lightleftstepa[0] - lightrightstepa[0]) >> 3;
820  lightdeltastep[1] = (lightleftstepa[1] - lightrightstepa[1]) >> 3;
821  lightdeltastep[2] = (lightleftstepa[2] - lightrightstepa[2]) >> 3;
822 
823  for (i=0 ; i<8 ; i++)
824  {
826 
827 
828  }
829 
830  if (psource >= r_sourcemax)
831  psource -= r_stepback;
832 
833  }
834 }
835 
836 
837 
839 {
840  unsigned int v, i;
841  unsigned int light[3];
842  unsigned int lightdelta[3], lightdeltastep[3];
843  unsigned char pix, *psource, *prowdest;
844  unsigned char *pix24;
845  unsigned trans[3];
846  psource = pbasesource;
847 
848  prowdest = prowdestbase;
849 
850 #pragma loop(hint_parallel(8)) //qb: try this
851  for (v=0 ; v<r_numvblocks ; v++)
852  {
853  lightlefta[0] = r_lightptr[0];
854  lightrighta[0] = r_lightptr[3];
855  lightlefta[1] = r_lightptr[0+1];
856  lightrighta[1] = r_lightptr[3+1];
857  lightlefta[2] = r_lightptr[0+2];
858  lightrighta[2] = r_lightptr[3+2];
859 
860  lightdelta[0] = (lightlefta[0] - lightrighta[0]) >> 2;
861  lightdelta[1] = (lightlefta[1] - lightrighta[1]) >> 2;
862  lightdelta[2] = (lightlefta[2] - lightrighta[2]) >> 2;
863 
864 
865  r_lightptr += r_lightwidth * 3;
866 
867  lightleftstepa[0] = (r_lightptr[0] - lightlefta[0]) >> 2;
868  lightrightstepa[0] = (r_lightptr[3] - lightrighta[0]) >> 2;
869 
870  lightleftstepa[1] = (r_lightptr[0+1] - lightlefta[1]) >> 2;
871  lightrightstepa[1] = (r_lightptr[3+1] - lightrighta[1]) >> 2;
872 
873  lightleftstepa[2] = (r_lightptr[0+2] - lightlefta[2]) >> 2;
874  lightrightstepa[2] = (r_lightptr[3+2] - lightrighta[2]) >> 2;
875 
876  lightdeltastep[0] = (lightleftstepa[0] - lightrightstepa[0]) >> 2;
877  lightdeltastep[1] = (lightleftstepa[1] - lightrightstepa[1]) >> 2;
878  lightdeltastep[2] = (lightleftstepa[2] - lightrightstepa[2]) >> 2;
879 
880  for (i=0 ; i<4 ; i++)
881  {
883 
884 
885  }
886 
887  if (psource >= r_sourcemax)
888  psource -= r_stepback;
889 
890  }
891 }
892 
893 
895 {
896  unsigned int v, i;
897  unsigned int light[3];
898  unsigned int lightdelta[3], lightdeltastep[3];
899  unsigned char pix, *psource, *prowdest;
900  unsigned char *pix24;
901  unsigned trans[3];
902  psource = pbasesource;
903 
904  prowdest = prowdestbase;
905 
906 #pragma loop(hint_parallel(8)) //qb: try this
907  for (v=0 ; v<r_numvblocks ; v++)
908  {
909  lightlefta[0] = r_lightptr[0];
910  lightrighta[0] = r_lightptr[3];
911  lightlefta[1] = r_lightptr[0+1];
912  lightrighta[1] = r_lightptr[3+1];
913  lightlefta[2] = r_lightptr[0+2];
914  lightrighta[2] = r_lightptr[3+2];
915 
916  lightdelta[0] = (lightlefta[0] - lightrighta[0]) >> 1;
917  lightdelta[1] = (lightlefta[1] - lightrighta[1]) >> 1;
918  lightdelta[2] = (lightlefta[2] - lightrighta[2]) >> 1;
919 
920 
921  r_lightptr += r_lightwidth * 3;
922 
923  lightleftstepa[0] = (r_lightptr[0] - lightlefta[0]) >> 1;
924  lightrightstepa[0] = (r_lightptr[3] - lightrighta[0]) >> 1;
925 
926  lightleftstepa[1] = (r_lightptr[0+1] - lightlefta[1]) >> 1;
927  lightrightstepa[1] = (r_lightptr[3+1] - lightrighta[1]) >> 1;
928 
929  lightleftstepa[2] = (r_lightptr[0+2] - lightlefta[2]) >> 1;
930  lightrightstepa[2] = (r_lightptr[3+2] - lightrighta[2]) >> 1;
931 
932  lightdeltastep[0] = (lightleftstepa[0] - lightrightstepa[0]) >> 1;
933  lightdeltastep[1] = (lightleftstepa[1] - lightrightstepa[1]) >> 1;
934  lightdeltastep[2] = (lightleftstepa[2] - lightrightstepa[2]) >> 1;
935 
936  for (i=0 ; i<2 ; i++)
937  {
939 
940 
941  }
942 
943  if (psource >= r_sourcemax)
944  psource -= r_stepback;
945 
946  }
947 }
948 
949 
950 
951 
952 
953 
r_cache_thrash
qboolean r_cache_thrash
Definition: r_surf.c:110
drawsurf_t::image
image_t * image
Definition: r_local.h:348
R_BuildLightMapRGB
void R_BuildLightMapRGB(void)
Definition: r_light.c:732
surfcache_s::size
int size
Definition: r_local.h:395
c_surf
int c_surf
Definition: r_main.c:64
r_framecount
int r_framecount
Definition: r_main.c:97
MaskForNum
int MaskForNum(int num)
Definition: r_surf.c:607
r_numvblocks
int r_numvblocks
Definition: r_surf.c:37
msurface_s::styles
byte styles[MAXLIGHTMAPS]
Definition: r_model.h:115
mtexinfo_s::numframes
int numframes
Definition: r_model.h:89
R_DrawSurfaceBlock8_mip0
void R_DrawSurfaceBlock8_mip0(void)
Definition: r_surf.c:236
D_SCAlloc
surfcache_t * D_SCAlloc(int width, int size)
Definition: r_surf.c:505
surfcache_s
Definition: r_local.h:389
ri
refimport_t ri
Definition: r_main.c:25
lightrightstep
int lightrightstep
Definition: r_surf.c:28
v
GLdouble v
Definition: qgl_win.c:143
r_stepback
int r_stepback
Definition: r_surf.c:35
mtexinfo_s
Definition: r_model.h:83
pix
static int pix
Definition: r_part.c:472
qboolean
qboolean
Definition: q_shared.h:63
surfcache_s::lightadj
int lightadj[MAXLIGHTMAPS]
Definition: r_local.h:393
sw_surfcacheoverride
cvar_t * sw_surfcacheoverride
Definition: r_main.c:129
i
int i
Definition: q_shared.c:305
msurface_s::dlightframe
int dlightframe
Definition: r_model.h:97
sourcesstep
int sourcesstep
Definition: r_surf.c:26
blockdivshift
int blockdivshift
Definition: r_surf.c:28
sourcetstep
int sourcetstep
Definition: r_surf.c:26
pbasesource
unsigned char * pbasesource
Definition: r_surf.c:31
R_DrawSurfaceBlock8RGBX_mip1
static void R_DrawSurfaceBlock8RGBX_mip1(void)
Definition: r_surf.c:781
r_lightwidth
int r_lightwidth
Definition: r_surf.c:36
width
GLint GLsizei width
Definition: qgl_win.c:115
D_CacheSurface
surfcache_t * D_CacheSurface(msurface_t *surface, int miplevel)
Definition: r_surf.c:638
currententity
entity_t * currententity
Definition: r_bsp.c:28
surfcache_s::image
image_t * image
Definition: r_local.h:399
r_local.h
msurface_s::extents
short extents[2]
Definition: r_model.h:110
r_numhblocks
int r_numhblocks
Definition: r_surf.c:37
R_DrawSurfaceBlock8RGBX_mip3
static void R_DrawSurfaceBlock8RGBX_mip3(void)
Definition: r_surf.c:894
R_DrawSurface
void R_DrawSurface(void)
Definition: r_surf.c:145
sc_rover
surfcache_t * sc_rover
Definition: r_surf.c:113
lightrightstepa
int lightrightstepa[3]
Definition: r_surf.c:61
Mip0Stuff
#define Mip0Stuff(i)
Definition: r_surf.c:75
lightleftstepa
int lightleftstepa[3]
Definition: r_surf.c:61
surfrowbytes
int surfrowbytes
Definition: r_surf.c:32
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
u
static int u
Definition: r_part.c:472
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
R_DrawSurfaceBlock8_mip3
void R_DrawSurfaceBlock8_mip3(void)
Definition: r_surf.c:386
mtexinfo_s::image
image_t * image
Definition: r_model.h:87
prowdestbase
void * prowdestbase
Definition: r_surf.c:30
lightdelta
int lightdelta
Definition: r_surf.c:27
miplevel
static int miplevel
Definition: r_edge.c:77
pix24
static unsigned char * pix24
Definition: r_polyse.c:927
viddef_t::width
unsigned width
Definition: vid.h:29
image_s::height
int height
Definition: r_local.h:75
Mip3Stuff
#define Mip3Stuff(i)
Definition: r_surf.c:78
msurface_s::texinfo
mtexinfo_t * texinfo
Definition: r_model.h:112
drawsurf_t::surfheight
int surfheight
Definition: r_local.h:351
MIP8RGBX
#define MIP8RGBX(i)
Definition: r_surf.c:71
drawsurf_t::rowbytes
int rowbytes
Definition: r_local.h:344
surfcache_s::mipscale
float mipscale
Definition: r_local.h:398
pixel_t
unsigned char pixel_t
Definition: r_local.h:84
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
d_roverwrapped
qboolean d_roverwrapped
Definition: r_misc.c:30
Mip1Stuff
#define Mip1Stuff(i)
Definition: r_surf.c:76
r_newrefdef
refdef_t r_newrefdef
Definition: r_main.c:38
viddef_t::height
unsigned height
Definition: vid.h:29
drawsurf_t::surfmip
int surfmip
Definition: r_local.h:349
D_log2
int D_log2(int num)
Definition: r_surf.c:620
blocklights
unsigned blocklights[18 *18 *3]
Definition: r_light.c:444
surfcache_s::owner
struct surfcache_s ** owner
Definition: r_local.h:392
cvar_s::value
float value
Definition: q_shared.h:331
lightrighta
int lightrighta[3]
Definition: r_surf.c:61
sc_base
surfcache_t * sc_base
Definition: r_surf.c:113
lightleftstep
int lightleftstep
Definition: r_surf.c:28
drawsurf_t::surfdat
byte * surfdat
Definition: r_local.h:343
blocksize
int blocksize
Definition: r_surf.c:26
NULL
#define NULL
Definition: q_shared.h:67
surfmiptable
static void(* surfmiptable[4])(void)
Definition: r_surf.c:45
R_TextureAnimation
image_t * R_TextureAnimation(mtexinfo_t *tex)
Definition: r_surf.c:122
image_s::pixels
byte * pixels[4]
Definition: r_local.h:78
image_s::width
int width
Definition: r_local.h:75
surfmiptable8RGB
static void(* surfmiptable8RGB[4])(void)
Definition: r_surf.c:88
r_sourcemax
unsigned char * r_sourcemax
Definition: r_surf.c:38
coloredlights
int coloredlights
Definition: r_main.c:156
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:743
Mip2Stuff
#define Mip2Stuff(i)
Definition: r_surf.c:77
r_lightptr
int * r_lightptr
Definition: r_surf.c:34
R_DrawSurfaceBlock8_mip2
void R_DrawSurfaceBlock8_mip2(void)
Definition: r_surf.c:336
d_initial_rover
surfcache_t * d_initial_rover
Definition: r_misc.c:29
surfscale
float surfscale
Definition: r_surf.c:109
mtexinfo_s::next
struct mtexinfo_s * next
Definition: r_model.h:90
entity_s::frame
int frame
Definition: ref.h:58
msurface_s::cachespots
struct surfcache_s * cachespots[MIPLEVELS]
Definition: r_model.h:107
refdef_t::lightstyles
lightstyle_t * lightstyles
Definition: ref.h:114
trans
static int trans[3]
Definition: r_polyse.c:928
drawsurf_t::surf
msurface_t * surf
Definition: r_local.h:345
R_BuildLightMap
void R_BuildLightMap(void)
Definition: r_light.c:551
lightleft
int lightleft
Definition: r_surf.c:26
R_DrawSurfaceBlock8RGBX_mip0
static void R_DrawSurfaceBlock8RGBX_mip0(void)
Definition: r_surf.c:724
lightlefta
int lightlefta[3]
Definition: r_surf.c:59
drawsurf_t::lightadj
fixed8_t lightadj[MAXLIGHTMAPS]
Definition: r_local.h:346
surfcache_s::data
byte data[4]
Definition: r_local.h:400
D_SCDump
void D_SCDump(void)
Definition: r_surf.c:591
drawsurf_t
Definition: r_local.h:341
msurface_s
Definition: r_model.h:93
blockdivmask
unsigned blockdivmask
Definition: r_surf.c:29
lightright
int lightright
Definition: r_surf.c:28
surfcache_s::dlight
int dlight
Definition: r_local.h:394
msurface_s::texturemins
short texturemins[2]
Definition: r_model.h:109
surfcache_s::width
unsigned width
Definition: r_local.h:396
lightstyle_t::white
float white
Definition: ref.h:99
R_DrawSurfaceBlock8RGBX_mip2
static void R_DrawSurfaceBlock8RGBX_mip2(void)
Definition: r_surf.c:838
image_s
Definition: r_local.h:71
viddef_t::colormap
pixel_t * colormap
Definition: r_local.h:95
SURFCACHE_SIZE_AT_320X240
#define SURFCACHE_SIZE_AT_320X240
Definition: r_local.h:218
surfcache_s::next
struct surfcache_s * next
Definition: r_local.h:391
R_InitCaches
void R_InitCaches(void)
Definition: r_surf.c:442
r_drawsurf
drawsurf_t r_drawsurf
Definition: r_surf.c:24
r_source
unsigned char * r_source
Definition: r_surf.c:38
drawsurf_t::surfwidth
int surfwidth
Definition: r_local.h:350
palmap2
byte palmap2[64][64][64]
Definition: r_draw.c:91
R_DrawSurfaceBlock8_mip1
void R_DrawSurfaceBlock8_mip1(void)
Definition: r_surf.c:286
lightdeltastep
int lightdeltastep
Definition: r_surf.c:27
void
void(APIENTRY *qglAccum)(GLenum op
D_FlushCaches
void D_FlushCaches(void)
Definition: r_surf.c:481
sc_size
int sc_size
Definition: r_surf.c:112
vid
viddef_t vid
Definition: r_main.c:24