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
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
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"
|
2001-10-09 20:35:17 +00:00
|
|
|
#include "QF/GL/qf_explosions.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
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_InitParticles (void)
|
2001-12-19 04:03:57 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
if (r_psystem.maxparticles && r_init) {
|
2011-12-16 11:09:05 +00:00
|
|
|
if (vaelements) {
|
|
|
|
partUseVA = 0;
|
2021-12-19 05:47:25 +00:00
|
|
|
pVAsize = r_psystem.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)),
|
2021-12-19 05:47:25 +00:00
|
|
|
r_psystem.maxparticles * 4);
|
2011-12-16 11:09:05 +00:00
|
|
|
else if (vaelements >= 0)
|
2021-12-19 05:47:25 +00:00
|
|
|
pVAsize = r_psystem.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawParticles (void)
|
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
|
|
|
|
2001-09-05 02:04:02 +00:00
|
|
|
if (!r_particles->int_val)
|
|
|
|
return;
|
|
|
|
|
2021-12-19 04:38:50 +00:00
|
|
|
R_RunParticles (vr_data.frametime);
|
|
|
|
|
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,
|
|
|
|
r_refdef.frame.forward) +
|
2002-06-26 22:20:12 +00:00
|
|
|
r_particles_nearclip->value;
|
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
|
|
|
|
2012-04-11 13:45:23 +00:00
|
|
|
static void
|
|
|
|
r_particles_nearclip_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value,
|
|
|
|
r_farclip->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
r_particles_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
R_MaxParticlesCheck (var, r_particles_max);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
r_particles_max_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
R_MaxParticlesCheck (r_particles, var);
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_Particles_Init_Cvars (void)
|
2001-12-11 22:37:30 +00:00
|
|
|
{
|
2012-04-11 13:45:23 +00:00
|
|
|
r_particles = Cvar_Get ("r_particles", "1", CVAR_ARCHIVE, r_particles_f,
|
|
|
|
"Toggles drawing of particles.");
|
|
|
|
r_particles_max = Cvar_Get ("r_particles_max", "2048", CVAR_ARCHIVE,
|
|
|
|
r_particles_max_f, "Maximum amount of "
|
|
|
|
"particles to display. No maximum, minimum "
|
|
|
|
"is 0.");
|
|
|
|
r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32",
|
|
|
|
CVAR_ARCHIVE, r_particles_nearclip_f,
|
|
|
|
"Distance of the particle near clipping "
|
|
|
|
"plane from the player.");
|
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;
|
|
|
|
}
|