2001-05-09 05:41:34 +00:00
|
|
|
/*
|
|
|
|
gl_dyn_part.c
|
|
|
|
|
|
|
|
OpenGL particle system.
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2013-01-21 11:06:54 +00:00
|
|
|
#include "QF/mersenne.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "QF/qargs.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-05-29 19:43:15 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "QF/sys.h"
|
2010-08-24 07:20:07 +00:00
|
|
|
#include "QF/va.h"
|
2021-07-24 05:19:52 +00:00
|
|
|
|
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GL/qf_particles.h"
|
2001-10-28 04:23:37 +00:00
|
|
|
#include "QF/GL/qf_textures.h"
|
2003-02-06 21:47:33 +00:00
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-06-29 02:43:04 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-06-29 02:43:04 +00:00
|
|
|
#include "varrays.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
static int partUseVA;
|
|
|
|
static int pVAsize;
|
|
|
|
static int *pVAindices;
|
|
|
|
static varray_t2f_c4ub_v3f_t *particleVertexArray;
|
2001-12-19 04:03:57 +00:00
|
|
|
|
2022-03-25 05:48:01 +00:00
|
|
|
static void
|
|
|
|
alloc_arrays (psystem_t *ps)
|
2001-12-19 04:03:57 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-03-25 05:48:01 +00:00
|
|
|
if (ps->maxparticles && r_init) {
|
2011-12-16 11:09:05 +00:00
|
|
|
if (vaelements) {
|
|
|
|
partUseVA = 0;
|
2022-03-25 05:48:01 +00:00
|
|
|
pVAsize = ps->maxparticles * 4;
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev,
|
2011-12-16 11:09:05 +00:00
|
|
|
"Particles: Vertex Array use disabled.\n");
|
|
|
|
} else {
|
|
|
|
if (vaelements > 3)
|
|
|
|
pVAsize = min ((unsigned int) (vaelements - (vaelements % 4)),
|
2022-03-25 05:48:01 +00:00
|
|
|
ps->maxparticles * 4);
|
2011-12-16 11:09:05 +00:00
|
|
|
else if (vaelements >= 0)
|
2022-03-25 05:48:01 +00:00
|
|
|
pVAsize = ps->maxparticles * 4;
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev,
|
2010-11-23 05:09:30 +00:00
|
|
|
"Particles: %i maximum vertex elements.\n",
|
|
|
|
pVAsize);
|
2011-12-16 11:09:05 +00:00
|
|
|
}
|
|
|
|
if (particleVertexArray)
|
|
|
|
free (particleVertexArray);
|
|
|
|
particleVertexArray = (varray_t2f_c4ub_v3f_t *)
|
|
|
|
calloc (pVAsize, sizeof (varray_t2f_c4ub_v3f_t));
|
2003-02-13 21:48:28 +00:00
|
|
|
|
2011-12-16 11:09:05 +00:00
|
|
|
if (partUseVA)
|
2003-02-13 21:48:28 +00:00
|
|
|
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray);
|
|
|
|
|
2011-12-16 11:09:05 +00:00
|
|
|
if (pVAindices)
|
|
|
|
free (pVAindices);
|
|
|
|
pVAindices = (int *) calloc (pVAsize, sizeof (int));
|
|
|
|
for (i = 0; i < pVAsize; i++)
|
|
|
|
pVAindices[i] = i;
|
2001-12-19 04:03:57 +00:00
|
|
|
} else {
|
|
|
|
if (particleVertexArray) {
|
|
|
|
free (particleVertexArray);
|
|
|
|
particleVertexArray = 0;
|
|
|
|
}
|
|
|
|
if (pVAindices) {
|
|
|
|
free (pVAindices);
|
|
|
|
pVAindices = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static void
|
|
|
|
gl_particles_f (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
alloc_arrays (&r_psystem);//FIXME
|
|
|
|
}
|
|
|
|
|
2022-03-25 05:48:01 +00:00
|
|
|
void
|
|
|
|
gl_R_InitParticles (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_AddListener (Cvar_FindVar ("r_particles"), gl_particles_f, 0);
|
|
|
|
Cvar_AddListener (Cvar_FindVar ("r_particles_max"), gl_particles_f, 0);
|
2022-03-25 05:48:01 +00:00
|
|
|
alloc_arrays (&r_psystem);
|
|
|
|
}
|
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
void
|
2022-03-17 08:50:38 +00:00
|
|
|
gl_R_DrawParticles (psystem_t *psystem)
|
2001-05-09 05:41:34 +00:00
|
|
|
{
|
2001-09-14 12:11:54 +00:00
|
|
|
unsigned char *at;
|
2021-12-18 16:21:39 +00:00
|
|
|
int vacount;
|
2006-12-01 07:03:13 +00:00
|
|
|
float minparticledist, scale;
|
2001-09-14 12:11:54 +00:00
|
|
|
vec3_t up_scale, right_scale, up_right_scale, down_right_scale;
|
2003-08-09 04:38:11 +00:00
|
|
|
varray_t2f_c4ub_v3f_t *VA;
|
2001-09-22 02:37:45 +00:00
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
if (!r_psystem.numparticles) {
|
2001-09-05 02:04:02 +00:00
|
|
|
return;
|
2022-03-17 08:50:38 +00:00
|
|
|
}
|
2021-12-19 04:38:50 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_part_tex);
|
2001-05-09 05:41:34 +00:00
|
|
|
// LordHavoc: particles should not affect zbuffer
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2002-06-13 05:24:52 +00:00
|
|
|
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray);
|
2001-05-09 05:41:34 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
minparticledist = DotProduct (r_refdef.frame.position,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
r_refdef.frame.forward)
|
|
|
|
+ r_particles_nearclip;
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-12-19 04:03:57 +00:00
|
|
|
vacount = 0;
|
|
|
|
VA = particleVertexArray;
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
for (unsigned i = 0; i < r_psystem.numparticles; i++) {
|
|
|
|
particle_t *p = &r_psystem.particles[i];
|
2001-05-09 05:41:34 +00:00
|
|
|
// Don't render particles too close to us.
|
|
|
|
// Note, we must still do physics and such on them.
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
if (!(DotProduct (p->pos, r_refdef.frame.forward) < minparticledist)) {
|
2021-12-18 16:21:39 +00:00
|
|
|
at = (byte *) &d_8to24table[(byte) p->icolor];
|
2001-12-19 04:03:57 +00:00
|
|
|
VA[0].color[0] = at[0];
|
|
|
|
VA[0].color[1] = at[1];
|
|
|
|
VA[0].color[2] = at[2];
|
2021-12-18 16:21:39 +00:00
|
|
|
VA[0].color[3] = p->alpha * 255;
|
2003-08-09 04:38:11 +00:00
|
|
|
memcpy (VA[1].color, VA[0].color, sizeof (VA[0].color));
|
|
|
|
memcpy (VA[2].color, VA[0].color, sizeof (VA[0].color));
|
|
|
|
memcpy (VA[3].color, VA[0].color, sizeof (VA[0].color));
|
2001-12-19 04:03:57 +00:00
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
switch (p->tex) {
|
2012-01-19 01:36:10 +00:00
|
|
|
case part_tex_dot:
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[0].texcoord[0] = 0.0;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[0].texcoord[1] = 0.0;
|
|
|
|
VA[1].texcoord[0] = 0.5;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[1].texcoord[1] = 0.0;
|
|
|
|
VA[2].texcoord[0] = 0.5;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[2].texcoord[1] = 0.5;
|
|
|
|
VA[3].texcoord[0] = 0.0;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[3].texcoord[1] = 0.5;
|
|
|
|
break;
|
2012-01-19 01:36:10 +00:00
|
|
|
case part_tex_spark:
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[0].texcoord[0] = 0.5;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[0].texcoord[1] = 0.0;
|
|
|
|
VA[1].texcoord[0] = 1.0;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[1].texcoord[1] = 0.0;
|
|
|
|
VA[2].texcoord[0] = 1.0;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[2].texcoord[1] = 0.5;
|
|
|
|
VA[3].texcoord[0] = 0.5;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[3].texcoord[1] = 0.5;
|
|
|
|
break;
|
2012-01-19 01:36:10 +00:00
|
|
|
case part_tex_smoke:
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[0].texcoord[0] = 0.0;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[0].texcoord[1] = 0.5;
|
|
|
|
VA[1].texcoord[0] = 0.5;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[1].texcoord[1] = 0.5;
|
|
|
|
VA[2].texcoord[0] = 0.5;
|
2002-01-06 22:43:51 +00:00
|
|
|
VA[2].texcoord[1] = 1.0;
|
|
|
|
VA[3].texcoord[0] = 0.0;
|
2002-01-04 03:32:59 +00:00
|
|
|
VA[3].texcoord[1] = 1.0;
|
|
|
|
break;
|
2001-12-19 04:03:57 +00:00
|
|
|
}
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
scale = p->scale;
|
2001-05-09 05:41:34 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorScale (r_refdef.frame.up, scale, up_scale);
|
|
|
|
VectorScale (r_refdef.frame.right, scale, right_scale);
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-12-11 22:37:30 +00:00
|
|
|
VectorAdd (right_scale, up_scale, up_right_scale);
|
2001-08-29 20:19:54 +00:00
|
|
|
VectorSubtract (right_scale, up_scale, down_right_scale);
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2021-12-18 16:21:39 +00:00
|
|
|
VectorAdd (p->pos, down_right_scale, VA[0].vertex);
|
|
|
|
VectorSubtract (p->pos, up_right_scale, VA[1].vertex);
|
|
|
|
VectorSubtract (p->pos, down_right_scale, VA[2].vertex);
|
|
|
|
VectorAdd (p->pos, up_right_scale, VA[3].vertex);
|
2001-12-19 04:03:57 +00:00
|
|
|
|
|
|
|
VA += 4;
|
|
|
|
vacount += 4;
|
|
|
|
if (vacount + 4 > pVAsize) {
|
2011-12-16 11:09:05 +00:00
|
|
|
// never reached if partUseVA is false
|
2001-12-19 04:03:57 +00:00
|
|
|
qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT,
|
|
|
|
pVAindices);
|
|
|
|
vacount = 0;
|
|
|
|
VA = particleVertexArray;
|
|
|
|
}
|
2001-05-09 05:41:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-18 16:21:39 +00:00
|
|
|
|
2011-12-16 11:09:05 +00:00
|
|
|
if (vacount) {
|
|
|
|
if (partUseVA) {
|
|
|
|
qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT, pVAindices);
|
|
|
|
} else {
|
|
|
|
varray_t2f_c4ub_v3f_t *va = particleVertexArray;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
for (i = 0; i < vacount; i++, va++) {
|
|
|
|
qfglTexCoord2fv (va->texcoord);
|
|
|
|
qfglColor4ubv (va->color);
|
|
|
|
qfglVertex3fv (va->vertex);
|
|
|
|
}
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
}
|
2001-12-19 04:03:57 +00:00
|
|
|
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-05-09 05:41:34 +00:00
|
|
|
}
|
2001-12-11 22:37:30 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
psystem_t * __attribute__((const))//FIXME
|
|
|
|
gl_ParticleSystem (void)
|
|
|
|
{
|
|
|
|
return &r_psystem;
|
|
|
|
}
|