Quake II RTX doxygen
1.0 dev
part.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 modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(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. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License along
15
with this program; if not, write to the Free Software Foundation, Inc.,
16
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
*/
18
19
#include "
sw.h
"
20
21
typedef
struct
{
22
particle_t *
particle
;
23
fixed8_t
color
[3];
24
int
one_minus_alpha
;
25
vec3_t
right
,
up
, pn;
26
}
partparms_t
;
27
28
static
partparms_t
partparms
;
29
30
/*
31
** R_DrawParticle
32
**
33
** Yes, this is amazingly slow, but it's the C reference
34
** implementation and should be both robust and vaguely
35
** understandable. The only time this path should be
36
** executed is if we're debugging on x86 or if we're
37
** recompiling and deploying on a non-x86 platform.
38
**
39
** To minimize error and improve readability I went the
40
** function pointer route. This exacts some overhead, but
41
** it pays off in clean and easy to understand code.
42
*/
43
static
void
R_DrawParticle
(
void
)
44
{
45
vec3_t local, transformed;
46
float
zi;
47
byte
*pdest;
48
short
*pz;
49
int
i, izi, pix, count, u, v;
50
51
/*
52
** transform the particle
53
*/
54
VectorSubtract(
partparms
.
particle
->origin,
r_origin
, local);
55
56
transformed[0] = DotProduct(local,
partparms
.
right
);
57
transformed[1] = DotProduct(local,
partparms
.
up
);
58
transformed[2] = DotProduct(local,
partparms
.
pn
);
59
60
if
(transformed[2] <
PARTICLE_Z_CLIP
)
61
return
;
62
63
/*
64
** project the point
65
*/
66
// FIXME: preadjust xcenter and ycenter
67
zi = 1.0 / transformed[2];
68
u = (
int
)(
r_refdef
.
xcenter
+ zi * transformed[0] + 0.5);
69
v = (
int
)(
r_refdef
.
ycenter
- zi * transformed[1] + 0.5);
70
71
if
(v >
r_refdef
.
vrectbottom_particle
||
72
u >
r_refdef
.
vrectright_particle
||
73
v <
r_refdef
.
vrect
.y ||
74
u <
r_refdef
.
vrect
.x) {
75
return
;
76
}
77
78
/*
79
** compute addresses of zbuffer, framebuffer, and
80
** compute the Z-buffer reference value.
81
*/
82
pz =
d_zspantable
[v] + u;
83
pdest =
d_spantable
[v] + u *
VID_BYTES
;
84
izi = (
int
)(zi * 0x8000);
85
86
/*
87
** determine the screen area covered by the particle,
88
** which also means clamping to a min and max
89
*/
90
pix = izi >>
r_refdef
.
pix_shift
;
91
if
(pix <
r_refdef
.
pix_min
)
92
pix =
r_refdef
.
pix_min
;
93
else
if
(pix >
r_refdef
.
pix_max
)
94
pix =
r_refdef
.
pix_max
;
95
96
/*
97
** render the appropriate pixels
98
*/
99
for
(count = pix; count; count--, pz +=
d_zwidth
, pdest +=
d_screenrowbytes
) {
100
for
(i = 0; i < pix; i++) {
101
if
(pz[i] <= izi) {
102
pz[i] = izi;
103
pdest[i *
VID_BYTES
+ 0] = (pdest[i *
VID_BYTES
+ 0] *
partparms
.
one_minus_alpha
+
partparms
.
color
[2]) >> 8;
104
pdest[i *
VID_BYTES
+ 1] = (pdest[i *
VID_BYTES
+ 1] *
partparms
.
one_minus_alpha
+
partparms
.
color
[1]) >> 8;
105
pdest[i *
VID_BYTES
+ 2] = (pdest[i *
VID_BYTES
+ 2] *
partparms
.
one_minus_alpha
+
partparms
.
color
[0]) >> 8;
106
}
107
}
108
}
109
}
110
111
/*
112
** R_DrawParticles
113
**
114
** Responsible for drawing all of the particles in the particle list
115
** throughout the world. Doesn't care if we're using the C path or
116
** if we're using the asm path, it simply assigns a function pointer
117
** and goes.
118
*/
119
void
R_DrawParticles
(
void
)
120
{
121
particle_t *p;
122
int
i;
123
int
alpha;
124
125
VectorScale(
vright
,
r_refdef
.
xscaleshrink
,
partparms
.
right
);
126
VectorScale(
vup
,
r_refdef
.
yscaleshrink
,
partparms
.
up
);
127
VectorCopy(
vpn
,
partparms
.
pn
);
128
129
for
(p =
r_newrefdef
.particles, i = 0; i <
r_newrefdef
.num_particles; i++, p++) {
130
partparms
.
particle
= p;
131
132
alpha = 255 * p->alpha;
133
partparms
.
one_minus_alpha
= 255 - alpha;
134
135
if
(p->color == -1) {
136
partparms
.
color
[0] = p->rgba.u8[0] * alpha;
137
partparms
.
color
[1] = p->rgba.u8[1] * alpha;
138
partparms
.
color
[2] = p->rgba.u8[2] * alpha;
139
}
else
{
140
color_t
color
;
141
142
color
.u32 =
d_8to24table
[p->color & 0xff];
143
partparms
.
color
[0] =
color
.u8[0] * alpha;
144
partparms
.
color
[1] =
color
.u8[1] * alpha;
145
partparms
.
color
[2] =
color
.u8[2] * alpha;
146
}
147
148
R_DrawParticle
();
149
}
150
}
151
oldrefdef_t::xcenter
float xcenter
Definition:
sw.h:145
r_origin
vec3_t r_origin
Definition:
main.c:52
R_DrawParticles
void R_DrawParticles(void)
Definition:
part.c:119
r_newrefdef
refdef_t r_newrefdef
Definition:
main.c:28
d_screenrowbytes
int d_screenrowbytes
Definition:
main.c:126
partparms_t::right
vec3_t right
Definition:
part.c:25
R_DrawParticle
static void R_DrawParticle(void)
Definition:
part.c:43
r_refdef
oldrefdef_t r_refdef
Definition:
main.c:57
d_8to24table
uint32_t d_8to24table[256]
Definition:
images.c:654
oldrefdef_t::xscaleshrink
float xscaleshrink
Definition:
sw.h:148
partparms_t::one_minus_alpha
int one_minus_alpha
Definition:
part.c:24
partparms_t
Definition:
part.c:21
oldrefdef_t::vrectright_particle
int vrectright_particle
Definition:
sw.h:152
vup
vec3_t vup
Definition:
main.c:49
partparms_t::particle
particle_t * particle
Definition:
part.c:22
partparms_t::pn
vec3_t pn
Definition:
part.c:25
partparms_t::color
fixed8_t color[3]
Definition:
part.c:23
oldrefdef_t::pix_min
int pix_min
Definition:
sw.h:153
vpn
vec3_t vpn
Definition:
main.c:50
sw.h
PARTICLE_Z_CLIP
#define PARTICLE_Z_CLIP
Definition:
sw.h:67
d_spantable
byte * d_spantable[MAXHEIGHT]
Definition:
main.c:130
d_zwidth
int d_zwidth
Definition:
main.c:129
d_zspantable
short * d_zspantable[MAXHEIGHT]
Definition:
main.c:131
partparms_t::up
vec3_t up
Definition:
part.c:25
VID_BYTES
#define VID_BYTES
Definition:
sw.h:49
oldrefdef_t::vrect
vrect_t vrect
Definition:
sw.h:132
oldrefdef_t::yscaleshrink
float yscaleshrink
Definition:
sw.h:148
right
static vec3_t right
Definition:
p_view.c:27
oldrefdef_t::vrectbottom_particle
int vrectbottom_particle
Definition:
sw.h:152
oldrefdef_t::pix_shift
int pix_shift
Definition:
sw.h:153
oldrefdef_t::pix_max
int pix_max
Definition:
sw.h:153
color
static vec4_t color
Definition:
mesh.c:33
oldrefdef_t::ycenter
float ycenter
Definition:
sw.h:145
int
CONST PIXELFORMATDESCRIPTOR int
Definition:
wgl.c:26
partparms
static partparms_t partparms
Definition:
part.c:28
vright
vec3_t vright
Definition:
main.c:51
src
refresh
sw
part.c
Generated by
1.8.17