icculus quake2 doxygen  1.0 dev
r_part.c File Reference
#include "r_local.h"

Go to the source code of this file.

Classes

struct  partparms_t
 

Macros

#define PARTICLE_33   0
 
#define PARTICLE_66   1
 
#define PARTICLE_OPAQUE   2
 

Functions

static byte BlendParticle33 (int pcolor, int dstcolor)
 
static byte BlendParticle66 (int pcolor, int dstcolor)
 
static byte BlendParticle100 (int pcolor, int dstcolor)
 
void R_DrawParticle (void)
 
void R_DrawParticles (void)
 

Variables

vec3_t r_pright
 
vec3_t r_pup
 
vec3_t r_ppn
 
static partparms_t partparms
 

Macro Definition Documentation

◆ PARTICLE_33

#define PARTICLE_33   0

Definition at line 24 of file r_part.c.

◆ PARTICLE_66

#define PARTICLE_66   1

Definition at line 25 of file r_part.c.

◆ PARTICLE_OPAQUE

#define PARTICLE_OPAQUE   2

Definition at line 26 of file r_part.c.

Function Documentation

◆ BlendParticle100()

static byte BlendParticle100 ( int  pcolor,
int  dstcolor 
)
static

Definition at line 448 of file r_part.c.

449 {
450  dstcolor = dstcolor;
451  return pcolor;
452 }

Referenced by R_DrawParticle().

◆ BlendParticle33()

static byte BlendParticle33 ( int  pcolor,
int  dstcolor 
)
static

Definition at line 438 of file r_part.c.

439 {
440  return vid.alphamap[pcolor + dstcolor*256];
441 }

Referenced by R_DrawParticle().

◆ BlendParticle66()

static byte BlendParticle66 ( int  pcolor,
int  dstcolor 
)
static

Definition at line 443 of file r_part.c.

444 {
445  return vid.alphamap[pcolor*256+dstcolor];
446 }

Referenced by R_DrawParticle().

◆ R_DrawParticle()

void R_DrawParticle ( void  )

Definition at line 467 of file r_part.c.

468 {
469  particle_t *pparticle = partparms.particle;
470  int level = partparms.level;
471  vec3_t local, transformed;
472  float zi;
473  byte *pdest;
474  short *pz;
475  int color = pparticle->color;
476  int i, izi, pix, count, u, v;
477  byte (*blendparticle)( int, int );
478 
479  /*
480  ** transform the particle
481  */
482  VectorSubtract (pparticle->origin, r_origin, local);
483 
484  transformed[0] = DotProduct(local, r_pright);
485  transformed[1] = DotProduct(local, r_pup);
486  transformed[2] = DotProduct(local, r_ppn);
487 
488  if (transformed[2] < PARTICLE_Z_CLIP)
489  return;
490 
491  /*
492  ** bind the blend function pointer to the appropriate blender
493  */
494  if ( level == PARTICLE_33 )
495  blendparticle = BlendParticle33;
496  else if ( level == PARTICLE_66 )
497  blendparticle = BlendParticle66;
498  else
499  blendparticle = BlendParticle100;
500 
501  /*
502  ** project the point
503  */
504  // FIXME: preadjust xcenter and ycenter
505  zi = 1.0 / transformed[2];
506  u = (int)(xcenter + zi * transformed[0] + 0.5);
507  v = (int)(ycenter - zi * transformed[1] + 0.5);
508 
509  if ((v > d_vrectbottom_particle) ||
510  (u > d_vrectright_particle) ||
511  (v < d_vrecty) ||
512  (u < d_vrectx))
513  {
514  return;
515  }
516 
517  /*
518  ** compute addresses of zbuffer, framebuffer, and
519  ** compute the Z-buffer reference value.
520  */
521  pz = d_pzbuffer + (d_zwidth * v) + u;
522  pdest = d_viewbuffer + d_scantable[v] + u;
523  izi = (int)(zi * 0x8000);
524 
525  /*
526  ** determine the screen area covered by the particle,
527  ** which also means clamping to a min and max
528  */
529  pix = izi >> d_pix_shift;
530  if (pix < d_pix_min)
531  pix = d_pix_min;
532  else if (pix > d_pix_max)
533  pix = d_pix_max;
534 
535  /*
536  ** render the appropriate pixels
537  */
538  count = pix;
539 
540  switch (level) {
541  case PARTICLE_33 :
542  for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
543  {
544 //FIXME--do it in blocks of 8?
545  for (i=0 ; i<pix ; i++)
546  {
547  if (pz[i] <= izi)
548  {
549  pz[i] = izi;
550  pdest[i] = vid.alphamap[color + ((int)pdest[i]<<8)];
551  }
552  }
553  }
554  break;
555 
556  case PARTICLE_66 :
557  for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
558  {
559  for (i=0 ; i<pix ; i++)
560  {
561  if (pz[i] <= izi)
562  {
563  pz[i] = izi;
564  pdest[i] = vid.alphamap[(color<<8) + (int)pdest[i]];
565  }
566  }
567  }
568  break;
569 
570  default: //100
571  for ( ; count ; count--, pz += d_zwidth, pdest += r_screenwidth)
572  {
573  for (i=0 ; i<pix ; i++)
574  {
575  if (pz[i] <= izi)
576  {
577  pz[i] = izi;
578  pdest[i] = color;
579  }
580  }
581  }
582  break;
583  }
584 }

Referenced by R_DrawParticles().

◆ R_DrawParticles()

void R_DrawParticles ( void  )

Definition at line 596 of file r_part.c.

597 {
598  particle_t *p;
599  int i;
600 
601 #if id386 && !defined __linux__ && !defined __FreeBSD__
602  extern unsigned long fpu_sp24_cw, fpu_chop_cw;
603 #endif
604 
607  VectorCopy( vpn, r_ppn );
608 
609 #if id386 && !defined __linux__ && !defined __FreeBSD__
610  __asm fldcw word ptr [fpu_sp24_cw]
611 #endif
612 
613  for (p=r_newrefdef.particles, i=0 ; i<r_newrefdef.num_particles ; i++,p++)
614  {
615 
616  if ( p->alpha > 0.66 )
618  else if ( p->alpha > 0.33 )
620  else
622 
623  partparms.particle = p;
624  partparms.color = p->color;
625 
626 #if id386 && !defined __linux__ && !defined __FreeBSD__
627  if ( i < r_newrefdef.num_particles-1 )
628  s_prefetch_address = ( unsigned int ) ( p + 1 );
629  else
630  s_prefetch_address = ( unsigned int ) r_newrefdef.particles;
631 #endif
632 
633  R_DrawParticle();
634  }
635 
636 #if id386 && !defined __linux__ && !defined __FreeBSD__
637  __asm fldcw word ptr [fpu_chop_cw]
638 #endif
639 
640 }

Variable Documentation

◆ partparms

partparms_t partparms
static

Definition at line 35 of file r_part.c.

Referenced by R_DrawParticle(), and R_DrawParticles().

◆ r_ppn

vec3_t r_ppn

Definition at line 22 of file r_part.c.

Referenced by R_DrawParticle(), and R_DrawParticles().

◆ r_pright

vec3_t r_pright

Definition at line 22 of file r_part.c.

Referenced by R_DrawParticle(), and R_DrawParticles().

◆ r_pup

vec3_t r_pup

Definition at line 22 of file r_part.c.

Referenced by R_DrawParticle(), and R_DrawParticles().

yscaleshrink
float yscaleshrink
Definition: r_local.h:541
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
VectorSubtract
#define VectorSubtract(a, b, c)
Definition: q_shared.h:156
v
GLdouble v
Definition: qgl_win.c:143
vright
vec3_t vright
Definition: r_main.c:68
VectorScale
void VectorScale(vec3_t in, vec_t scale, vec3_t out)
Definition: q_shared.c:782
i
int i
Definition: q_shared.c:305
d_viewbuffer
pixel_t * d_viewbuffer
Definition: r_main.c:181
PARTICLE_66
#define PARTICLE_66
Definition: r_part.c:25
r_origin
vec3_t r_origin
Definition: r_main.c:69
PARTICLE_Z_CLIP
#define PARTICLE_Z_CLIP
Definition: d_ifacea.h:37
r_pright
vec3_t r_pright
Definition: r_part.c:22
vup
vec3_t vup
Definition: r_main.c:66
PARTICLE_OPAQUE
#define PARTICLE_OPAQUE
Definition: r_part.c:26
partparms_t::color
int color
Definition: r_part.c:32
byte
unsigned char byte
Definition: q_shared.h:55
partparms_t::particle
particle_t * particle
Definition: r_part.c:30
d_pix_max
int d_pix_max
Definition: r_local.h:498
xscaleshrink
float xscaleshrink
Definition: r_main.c:78
d_vrectx
int d_vrectx
Definition: r_misc.c:38
BlendParticle33
static byte BlendParticle33(int pcolor, int dstcolor)
Definition: r_part.c:438
particle_t::alpha
float alpha
Definition: ref.h:100
d_pix_shift
int d_pix_shift
Definition: r_local.h:498
partparms_t::level
int level
Definition: r_part.c:31
r_newrefdef
refdef_t r_newrefdef
Definition: r_main.c:36
DotProduct
#define DotProduct(x, y)
Definition: q_shared.h:155
r_pup
vec3_t r_pup
Definition: r_part.c:22
d_scantable
int d_scantable[MAXHEIGHT]
Definition: r_misc.c:42
particle_t
Definition: ref.h:96
refdef_t::num_particles
int num_particles
Definition: ref.h:140
r_screenwidth
int r_screenwidth
Definition: r_main.c:81
ycenter
float ycenter
Definition: r_local.h:538
particle_t::origin
vec3_t origin
Definition: ref.h:98
d_pix_min
int d_pix_min
Definition: r_misc.c:40
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:158
refdef_t::particles
particle_t * particles
Definition: ref.h:141
d_vrectbottom_particle
int d_vrectbottom_particle
Definition: r_local.h:496
level
GLint level
Definition: qgl_win.c:116
d_zwidth
unsigned int d_zwidth
Definition: r_local.h:502
d_vrectright_particle
int d_vrectright_particle
Definition: r_local.h:496
particle_t::color
int color
Definition: ref.h:99
partparms
static partparms_t partparms
Definition: r_part.c:35
d_vrecty
int d_vrecty
Definition: r_local.h:496
BlendParticle100
static byte BlendParticle100(int pcolor, int dstcolor)
Definition: r_part.c:448
R_DrawParticle
void R_DrawParticle(void)
Definition: r_part.c:467
BlendParticle66
static byte BlendParticle66(int pcolor, int dstcolor)
Definition: r_part.c:443
d_pzbuffer
short * d_pzbuffer
Definition: r_main.c:182
r_ppn
vec3_t r_ppn
Definition: r_part.c:22
xcenter
float xcenter
Definition: r_main.c:75
viddef_t::alphamap
pixel_t * alphamap
Definition: r_local.h:90
vpn
vec3_t vpn
Definition: r_main.c:67
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:127
PARTICLE_33
#define PARTICLE_33
Definition: r_part.c:24
count
GLint GLsizei count
Definition: qgl_win.c:128
vid
viddef_t vid
Definition: r_main.c:24