2001-10-23 17:20:56 +00:00
|
|
|
/*
|
|
|
|
gl_mod_sprite.c
|
|
|
|
|
2003-03-20 19:58:18 +00:00
|
|
|
sprite model rendering
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2003-03-20 19:58:18 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-12-21 21:52:03 +00:00
|
|
|
#include "QF/model.h"
|
2001-10-23 17:20:56 +00:00
|
|
|
#include "QF/render.h"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
|
|
|
|
2003-03-20 19:58:18 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2003-03-20 19:58:18 +00:00
|
|
|
#include "varrays.h"
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
static int sVAsize;
|
|
|
|
static int *sVAindices;
|
|
|
|
varray_t2f_c4ub_v3f_t *gl_spriteVertexArray;
|
2003-03-20 19:58:18 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
void (*gl_R_DrawSpriteModel) (struct entity_s *ent);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
R_DrawSpriteModel_f (entity_t *e)
|
2001-10-23 17:20:56 +00:00
|
|
|
{
|
2002-06-05 06:46:21 +00:00
|
|
|
float modelalpha, color[4];
|
2021-12-10 05:34:04 +00:00
|
|
|
vec4f_t cameravec = {};
|
|
|
|
vec4f_t up = {}, right = {}, pn = {};
|
2021-03-10 09:35:35 +00:00
|
|
|
vec4f_t origin, point;
|
2021-12-10 05:34:04 +00:00
|
|
|
msprite_t *sprite = e->renderer.model->cache.data;
|
2001-10-23 17:20:56 +00:00
|
|
|
mspriteframe_t *frame;
|
|
|
|
|
2021-12-10 05:34:04 +00:00
|
|
|
origin = Transform_GetWorldPosition (e->transform);
|
[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
|
|
|
cameravec = r_refdef.frame.position - origin;
|
2021-12-10 05:34:04 +00:00
|
|
|
|
2001-12-19 18:32:26 +00:00
|
|
|
// don't bother culling, it's just a single polygon without a surface cache
|
2021-12-14 16:18:02 +00:00
|
|
|
frame = R_GetSpriteFrame (sprite, &e->animation);
|
2021-12-10 05:34:04 +00:00
|
|
|
|
|
|
|
if (!R_BillboardFrame (e, sprite->type, &cameravec[0],
|
|
|
|
&up[0], &right[0], &pn[0])) {
|
|
|
|
// the orientation is undefined so can't draw the sprite
|
|
|
|
return;
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
2002-06-05 06:46:21 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
VectorCopy (e->renderer.colormod, color);
|
|
|
|
modelalpha = color[3] = e->renderer.colormod[3];
|
2002-06-05 06:46:21 +00:00
|
|
|
if (modelalpha < 1.0)
|
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
|
|
|
|
|
|
|
|
qfglBegin (GL_QUADS);
|
|
|
|
|
2002-06-05 05:56:13 +00:00
|
|
|
qfglColor4fv (color);
|
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->down * up + frame->left * right;
|
2021-03-09 14:52:40 +00:00
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglTexCoord2f (0, 1);
|
2021-03-10 09:35:35 +00:00
|
|
|
qfglVertex3fv (&point[0]);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->up * up + frame->left * right;
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglTexCoord2f (0, 0);
|
2021-03-10 09:35:35 +00:00
|
|
|
qfglVertex3fv (&point[0]);
|
2021-03-09 14:52:40 +00:00
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->up * up + frame->right * right;
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
qfglTexCoord2f (1, 0);
|
2021-03-10 09:35:35 +00:00
|
|
|
qfglVertex3fv (&point[0]);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->down * up + frame->right * right;
|
2001-10-23 17:20:56 +00:00
|
|
|
qfglTexCoord2f (1, 1);
|
2021-03-10 09:35:35 +00:00
|
|
|
qfglVertex3fv (&point[0]);
|
2001-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
qfglEnd ();
|
2002-06-05 06:46:21 +00:00
|
|
|
|
|
|
|
if (modelalpha < 1.0)
|
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-10-23 17:20:56 +00:00
|
|
|
}
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
R_DrawSpriteModel_VA_f (entity_t *e)
|
|
|
|
{
|
|
|
|
unsigned char modelalpha, color[4];
|
2021-03-09 14:52:40 +00:00
|
|
|
vec4f_t up = {}, right = {};
|
2021-03-10 09:35:35 +00:00
|
|
|
vec4f_t origin, point;
|
2003-03-20 19:58:18 +00:00
|
|
|
int i;
|
|
|
|
// unsigned int vacount;
|
2021-12-14 16:18:02 +00:00
|
|
|
msprite_t *psprite = e->renderer.model->cache.data;
|
2003-03-20 19:58:18 +00:00
|
|
|
mspriteframe_t *frame;
|
|
|
|
varray_t2f_c4ub_v3f_t *VA;
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
VA = gl_spriteVertexArray; // FIXME: Despair
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
// don't bother culling, it's just a single polygon without a surface cache
|
2021-12-14 16:18:02 +00:00
|
|
|
frame = R_GetSpriteFrame (psprite, &e->animation);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum); // FIXME: DESPAIR
|
|
|
|
|
|
|
|
if (psprite->type == SPR_ORIENTED) { // bullet marks on walls
|
2021-03-09 14:52:40 +00:00
|
|
|
up = Transform_Up (e->transform);
|
|
|
|
right = Transform_Right (e->transform);
|
2003-03-20 19:58:18 +00:00
|
|
|
} else if (psprite->type == SPR_VP_PARALLEL_UPRIGHT) {
|
2021-03-09 14:52:40 +00:00
|
|
|
up = (vec4f_t) { 0, 0, 1, 0 };
|
[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
|
|
|
VectorCopy (r_refdef.frame.right, right);
|
2003-03-20 19:58:18 +00:00
|
|
|
} else { // normal sprite
|
[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
|
|
|
VectorCopy (r_refdef.frame.up, up);
|
|
|
|
VectorCopy (r_refdef.frame.right, right);
|
2003-03-20 19:58:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
color[i] = e->renderer.colormod[i] * 255;
|
|
|
|
}
|
2003-03-20 19:58:18 +00:00
|
|
|
memcpy (VA[0].color, color, 4);
|
2021-03-09 14:52:40 +00:00
|
|
|
memcpy (VA[1].color, color, 4);
|
|
|
|
memcpy (VA[2].color, color, 4);
|
|
|
|
memcpy (VA[3].color, color, 4);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
modelalpha = color[3];
|
|
|
|
if (modelalpha < 255)
|
|
|
|
qfglDepthMask (GL_FALSE);
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
origin = Transform_GetWorldPosition (e->transform);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->down * up + frame->left * right;
|
|
|
|
VectorCopy (point, VA[0].vertex);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
2021-03-10 09:35:35 +00:00
|
|
|
point = origin + frame->up * up + frame->left * right;
|
|
|
|
VectorCopy (point, VA[1].vertex);
|
|
|
|
|
|
|
|
point = origin + frame->up * up + frame->right * right;
|
|
|
|
VectorCopy (point, VA[2].vertex);
|
|
|
|
|
|
|
|
point = origin + frame->down * up + frame->right * right;
|
|
|
|
VectorCopy (point, VA[3].vertex);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
// VA += 4;
|
|
|
|
// vacount += 4;
|
|
|
|
// if (vacount + 4 > sVAsize) {
|
|
|
|
// qfglDrawElements (GL_QUADS, vacount, GL_UNSIGNED_INT, sVAindices);
|
|
|
|
qfglDrawElements (GL_QUADS, 4, GL_UNSIGNED_INT, sVAindices);
|
|
|
|
// vacount = 0;
|
2012-02-17 09:33:07 +00:00
|
|
|
// VA = gl_spriteVertexArray;
|
2003-03-20 19:58:18 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
if (modelalpha < 255)
|
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_InitSprites (void)
|
2003-03-20 19:58:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (r_init) {
|
2021-03-10 09:35:35 +00:00
|
|
|
if (gl_va_capable) {
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawSpriteModel = R_DrawSpriteModel_VA_f;
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (vaelements > 3)
|
|
|
|
sVAsize = min (vaelements - (vaelements % 4), 512);
|
|
|
|
else
|
|
|
|
sVAsize = 512;
|
|
|
|
#else
|
|
|
|
sVAsize = 4;
|
|
|
|
#endif
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Sprites: %i maximum vertex elements.\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
sVAsize);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_spriteVertexArray)
|
|
|
|
free (gl_spriteVertexArray);
|
|
|
|
gl_spriteVertexArray = (varray_t2f_c4ub_v3f_t *)
|
2003-03-20 19:58:18 +00:00
|
|
|
calloc (sVAsize, sizeof (varray_t2f_c4ub_v3f_t));
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, gl_spriteVertexArray);
|
2003-03-20 19:58:18 +00:00
|
|
|
|
|
|
|
if (sVAindices)
|
|
|
|
free (sVAindices);
|
|
|
|
sVAindices = (int *) calloc (sVAsize, sizeof (int));
|
|
|
|
for (i = 0; i < sVAsize; i++)
|
|
|
|
sVAindices[i] = i;
|
|
|
|
for (i = 0; i < sVAsize / 4; i++) {
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_spriteVertexArray[i * 4].texcoord[0] = 0.0;
|
|
|
|
gl_spriteVertexArray[i * 4].texcoord[1] = 1.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 1].texcoord[0] = 0.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 1].texcoord[1] = 0.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 2].texcoord[0] = 1.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 2].texcoord[1] = 0.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 3].texcoord[0] = 1.0;
|
|
|
|
gl_spriteVertexArray[i * 4 + 3].texcoord[1] = 1.0;
|
2003-03-20 19:58:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawSpriteModel = R_DrawSpriteModel_f;
|
2003-03-20 19:58:18 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_spriteVertexArray) {
|
|
|
|
free (gl_spriteVertexArray);
|
|
|
|
gl_spriteVertexArray = 0;
|
2003-03-20 19:58:18 +00:00
|
|
|
}
|
|
|
|
if (sVAindices) {
|
|
|
|
free (sVAindices);
|
|
|
|
sVAindices = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|