2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_rsurf.c
|
|
|
|
|
|
|
|
surface-related refresh code
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2000 Joseph Carter <knghtbrd@debian.org>
|
|
|
|
|
|
|
|
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
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
2001-05-11 20:50:16 +00:00
|
|
|
#include <stdio.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-21 03:39:41 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-21 23:09:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2002-07-23 19:57:47 +00:00
|
|
|
#include "QF/GL/qf_lightmap.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_rmain.h"
|
2002-11-05 19:12:51 +00:00
|
|
|
#include "QF/GL/qf_rsurf.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_sky.h"
|
2001-09-01 08:57:04 +00:00
|
|
|
#include "QF/GL/qf_textures.h"
|
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
|
2001-08-02 02:18:04 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "r_cvar.h"
|
|
|
|
#include "r_local.h"
|
|
|
|
#include "r_shared.h"
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
int skytexturenum;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
glpoly_t *fullbright_polys[MAX_GLTEXTURES];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
msurface_t *waterchain = NULL;
|
2001-11-05 06:20:35 +00:00
|
|
|
msurface_t **waterchain_tail = &waterchain;
|
2001-09-01 08:57:04 +00:00
|
|
|
msurface_t *sky_chain;
|
2001-11-05 06:20:35 +00:00
|
|
|
msurface_t **sky_chain_tail;
|
|
|
|
|
|
|
|
#define CHAIN_SURF_F2B(surf,chain) \
|
|
|
|
do { \
|
|
|
|
*(chain##_tail) = (surf); \
|
|
|
|
(chain##_tail) = &(surf)->texturechain; \
|
|
|
|
*(chain##_tail) = 0; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CHAIN_SURF_B2F(surf,chain) \
|
|
|
|
do { \
|
|
|
|
(surf)->texturechain = (chain); \
|
|
|
|
(chain) = (surf); \
|
|
|
|
} while (0)
|
|
|
|
|
2002-07-23 19:57:47 +00:00
|
|
|
extern int lightmap_textures;
|
|
|
|
extern qboolean lightmap_modified[MAX_LIGHTMAPS];
|
|
|
|
extern glpoly_t *lightmap_polys[MAX_LIGHTMAPS];
|
|
|
|
extern glRect_t lightmap_rectchange[MAX_LIGHTMAPS];
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2001-08-25 23:23:14 +00:00
|
|
|
R_TextureAnimation
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-25 23:23:14 +00:00
|
|
|
Returns the proper texture for a given time and base texture
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
texture_t *
|
2002-03-16 09:25:06 +00:00
|
|
|
R_TextureAnimation (msurface_t *surf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-03-16 09:25:06 +00:00
|
|
|
texture_t *base = surf->texinfo->texture;
|
2001-09-01 08:57:04 +00:00
|
|
|
int count, relative;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (currententity->frame) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (base->alternate_anims)
|
|
|
|
base = base->alternate_anims;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-20 03:54:55 +00:00
|
|
|
relative = (int) (r_realtime * 10) % base->anim_total;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
count = 0;
|
|
|
|
while (base->anim_min > relative || base->anim_max <= relative) {
|
2001-02-19 21:15:25 +00:00
|
|
|
base = base->anim_next;
|
|
|
|
if (!base)
|
|
|
|
Sys_Error ("R_TextureAnimation: broken cycle");
|
|
|
|
if (++count > 100)
|
|
|
|
Sys_Error ("R_TextureAnimation: infinite cycle");
|
|
|
|
}
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2002-07-07 06:15:36 +00:00
|
|
|
// BRUSH MODELS ===============================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RenderFullbrights (void)
|
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
float *v;
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j;
|
|
|
|
glpoly_t *p;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 1; i < MAX_GLTEXTURES; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!fullbright_polys[i])
|
|
|
|
continue;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, i);
|
2001-02-26 06:48:02 +00:00
|
|
|
for (p = fullbright_polys[i]; p; p = p->fb_chain) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-09-01 08:57:04 +00:00
|
|
|
for (j = 0, v = p->verts[0]; j < p->numverts; j++, v += VERTEXSIZE)
|
|
|
|
{
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2fv (&v[3]);
|
|
|
|
qfglVertex3fv (v);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
static inline void
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_3 (msurface_t *fa)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float *v;
|
2004-02-21 05:36:19 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
c_brush_polys++;
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-02-19 21:15:25 +00:00
|
|
|
v = fa->polys->verts[0];
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
for (i = 0; i < fa->polys->numverts; i++, v += VERTEXSIZE) {
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 0, &v[3]);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 1, &v[5]);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 2, &v[3]);
|
|
|
|
qfglVertex3fv (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_2 (msurface_t *fa)
|
2004-02-22 06:00:15 +00:00
|
|
|
{
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
c_brush_polys++;
|
|
|
|
|
|
|
|
qfglBegin (GL_POLYGON);
|
|
|
|
v = fa->polys->verts[0];
|
|
|
|
|
|
|
|
for (i = 0; i < fa->polys->numverts; i++, v += VERTEXSIZE) {
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 0, &v[3]);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 1, &v[5]);
|
|
|
|
qfglVertex3fv (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_1 (msurface_t *fa)
|
2004-02-22 06:00:15 +00:00
|
|
|
{
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
c_brush_polys++;
|
|
|
|
|
|
|
|
qfglBegin (GL_POLYGON);
|
|
|
|
v = fa->polys->verts[0];
|
|
|
|
|
|
|
|
for (i = 0; i < fa->polys->numverts; i++, v += VERTEXSIZE) {
|
|
|
|
qfglTexCoord2fv (&v[3]);
|
|
|
|
qfglVertex3fv (v);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2004-02-14 05:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
R_AddToLightmapChain (msurface_t *fa)
|
|
|
|
{
|
|
|
|
int maps, smax, tmax;
|
|
|
|
glRect_t *theRect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// add the poly to the proper lightmap chain
|
|
|
|
|
|
|
|
fa->polys->chain = lightmap_polys[fa->lightmaptexturenum];
|
|
|
|
lightmap_polys[fa->lightmaptexturenum] = fa->polys;
|
|
|
|
|
|
|
|
// check for lightmap modification
|
2001-02-26 06:48:02 +00:00
|
|
|
for (maps = 0; maps < MAXLIGHTMAPS && fa->styles[maps] != 255; maps++)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
|
|
|
|
goto dynamic;
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if ((fa->dlightframe == r_framecount) || fa->cached_dlight) {
|
2001-02-26 06:48:02 +00:00
|
|
|
dynamic:
|
2004-02-14 08:36:08 +00:00
|
|
|
if (r_dynamic->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lightmap_modified[fa->lightmaptexturenum] = true;
|
|
|
|
theRect = &lightmap_rectchange[fa->lightmaptexturenum];
|
|
|
|
if (fa->light_t < theRect->t) {
|
|
|
|
if (theRect->h)
|
|
|
|
theRect->h += theRect->t - fa->light_t;
|
|
|
|
theRect->t = fa->light_t;
|
|
|
|
}
|
|
|
|
if (fa->light_s < theRect->l) {
|
|
|
|
if (theRect->w)
|
|
|
|
theRect->w += theRect->l - fa->light_s;
|
|
|
|
theRect->l = fa->light_s;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
smax = (fa->extents[0] >> 4) + 1;
|
|
|
|
tmax = (fa->extents[1] >> 4) + 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((theRect->w + theRect->l) < (fa->light_s + smax))
|
2001-02-26 06:48:02 +00:00
|
|
|
theRect->w = (fa->light_s - theRect->l) + smax;
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((theRect->h + theRect->t) < (fa->light_t + tmax))
|
2001-02-26 06:48:02 +00:00
|
|
|
theRect->h = (fa->light_t - theRect->t) + tmax;
|
2002-05-28 00:04:01 +00:00
|
|
|
R_BuildLightMap (fa);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawWaterSurfaces (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
msurface_t *s;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!waterchain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// go back to the world matrix
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglLoadMatrixf (r_world_matrix);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-04-25 12:51:04 +00:00
|
|
|
if (cl_wateralpha < 1.0) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2002-04-25 12:51:04 +00:00
|
|
|
color_white[3] = cl_wateralpha * 255;
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor4ubv (color_white);
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
i = -1;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (s = waterchain; s; s = s->texturechain) {
|
|
|
|
if (i != s->texinfo->texture->gl_texturenum) {
|
2001-02-19 21:15:25 +00:00
|
|
|
i = s->texinfo->texture->gl_texturenum;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, i);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
EmitWaterPolys (s);
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
waterchain = NULL;
|
2001-11-05 06:20:35 +00:00
|
|
|
waterchain_tail = &waterchain;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-04-25 12:51:04 +00:00
|
|
|
if (cl_wateralpha < 1.0) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
static inline void
|
2001-02-26 06:48:02 +00:00
|
|
|
DrawTextureChains (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2004-02-22 06:00:15 +00:00
|
|
|
int i;
|
2001-02-26 06:48:02 +00:00
|
|
|
msurface_t *s;
|
2002-08-09 06:07:25 +00:00
|
|
|
texture_t *tex;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) {
|
2004-02-15 00:02:04 +00:00
|
|
|
// Lightmaps
|
2004-02-21 05:36:19 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2004-02-15 00:02:04 +00:00
|
|
|
|
2004-02-21 05:36:19 +00:00
|
|
|
// Base Texture
|
2004-02-14 05:10:29 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
for (i = 0; i < r_worldentity.model->numtextures; i++) {
|
|
|
|
tex = r_worldentity.model->textures[i];
|
|
|
|
if (!tex)
|
|
|
|
continue;
|
2004-02-21 05:36:19 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (tex->gl_fb_texturenum && gl_mtex_fullbright) {
|
2004-02-21 05:36:19 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 2);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_fb_texturenum);
|
2004-02-15 00:02:04 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
for (s = tex->texturechain; s; s = s->texturechain) {
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures +
|
|
|
|
s->lightmaptexturenum);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_3 (s);
|
2004-02-22 06:00:15 +00:00
|
|
|
}
|
2004-02-21 05:36:19 +00:00
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 2);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
} else {
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
for (s = tex->texturechain; s; s = s->texturechain) {
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures +
|
|
|
|
s->lightmaptexturenum);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_2 (s);
|
2004-02-22 06:00:15 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
|
|
|
tex->texturechain = NULL;
|
|
|
|
tex->texturechain_tail = &tex->texturechain;
|
|
|
|
}
|
2004-02-15 00:02:04 +00:00
|
|
|
// Turn off lightmaps for other entities
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
|
2004-02-21 05:36:19 +00:00
|
|
|
// Reset mode for default TMU
|
2004-02-14 05:10:29 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2004-02-22 06:00:15 +00:00
|
|
|
} else {
|
|
|
|
qfglDisable (GL_BLEND);
|
|
|
|
for (i = 0; i < r_worldentity.model->numtextures; i++) {
|
|
|
|
tex = r_worldentity.model->textures[i];
|
|
|
|
if (!tex)
|
|
|
|
continue;
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
|
|
|
|
|
|
|
for (s = tex->texturechain; s; s = s->texturechain)
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_1 (s);
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
tex->texturechain = NULL;
|
|
|
|
tex->texturechain_tail = &tex->texturechain;
|
|
|
|
}
|
|
|
|
qfglEnable (GL_BLEND);
|
2004-02-14 05:10:29 +00:00
|
|
|
}
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
tex = r_notexture_mip;
|
|
|
|
tex->texturechain = NULL;
|
|
|
|
tex->texturechain_tail = &tex->texturechain;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawBrushModel (entity_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-23 21:14:43 +00:00
|
|
|
float dot, radius;
|
2004-02-22 06:00:15 +00:00
|
|
|
float color[4], watercolor[4];
|
2003-04-17 00:01:48 +00:00
|
|
|
int i;
|
|
|
|
unsigned int k;
|
2002-08-20 00:48:59 +00:00
|
|
|
model_t *model;
|
2001-09-01 08:57:04 +00:00
|
|
|
mplane_t *pplane;
|
|
|
|
msurface_t *psurf;
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean rotated;
|
2001-09-01 08:57:04 +00:00
|
|
|
vec3_t mins, maxs;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-20 00:48:59 +00:00
|
|
|
model = e->model;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (e->angles[0] || e->angles[1] || e->angles[2]) {
|
2001-02-19 21:15:25 +00:00
|
|
|
rotated = true;
|
2002-08-23 21:14:43 +00:00
|
|
|
radius = model->radius;
|
|
|
|
#if 0 //QSG FIXME
|
|
|
|
if (e->scale != 1.0)
|
|
|
|
radius *= e->scale;
|
|
|
|
#endif
|
|
|
|
if (R_CullSphere (e->origin, radius))
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
rotated = false;
|
2002-08-20 00:48:59 +00:00
|
|
|
VectorAdd (e->origin, model->mins, mins);
|
|
|
|
VectorAdd (e->origin, model->maxs, maxs);
|
2002-07-07 06:15:36 +00:00
|
|
|
#if 0 // QSG FIXME
|
2002-08-23 21:14:43 +00:00
|
|
|
if (e->scale != 1.0) {
|
|
|
|
VectorScale (mins, e->scale, mins);
|
|
|
|
VectorScale (maxs, e->scale, maxs);
|
|
|
|
}
|
2002-07-07 06:15:36 +00:00
|
|
|
#endif
|
2002-08-23 21:14:43 +00:00
|
|
|
if (R_CullBox (mins, maxs))
|
|
|
|
return;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-07 06:15:36 +00:00
|
|
|
VectorCopy (e->colormod, color);
|
2004-02-22 06:00:15 +00:00
|
|
|
VectorCopy (color, watercolor);
|
2002-07-07 06:15:36 +00:00
|
|
|
color[3] = e->colormod[3];
|
2004-02-22 06:00:15 +00:00
|
|
|
qfglColor4fv (color);
|
|
|
|
if (color[3] < 1.0)
|
|
|
|
qfglDepthMask (GL_FALSE);
|
2002-07-07 06:15:36 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (lightmap_polys, 0, sizeof (lightmap_polys));
|
|
|
|
memset (fullbright_polys, 0, sizeof (fullbright_polys));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorSubtract (r_refdef.vieworg, e->origin, modelorg);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (rotated) {
|
2002-08-25 05:55:28 +00:00
|
|
|
vec3_t temp, forward, right, up;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (modelorg, temp);
|
|
|
|
AngleVectors (e->angles, forward, right, up);
|
|
|
|
modelorg[0] = DotProduct (temp, forward);
|
|
|
|
modelorg[1] = -DotProduct (temp, right);
|
|
|
|
modelorg[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
|
2002-08-20 00:48:59 +00:00
|
|
|
psurf = &model->surfaces[model->firstmodelsurface];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// calculate dynamic lighting for bmodel if it's not an instanced model
|
2002-08-20 00:48:59 +00:00
|
|
|
if (model->firstmodelsurface != 0 && r_dlight_lightmap->int_val) {
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t lightorigin;
|
|
|
|
|
2001-10-09 20:35:17 +00:00
|
|
|
for (k = 0; k < r_maxdlights; k++) {
|
2001-05-20 05:42:52 +00:00
|
|
|
if ((r_dlights[k].die < r_realtime) || (!r_dlights[k].radius))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
2001-05-20 05:42:52 +00:00
|
|
|
VectorSubtract (r_dlights[k].origin, e->origin, lightorigin);
|
2001-08-05 05:07:49 +00:00
|
|
|
R_RecursiveMarkLights (lightorigin, &r_dlights[k], 1 << k,
|
2002-08-20 00:48:59 +00:00
|
|
|
model->nodes + model->hulls[0].firstclipnode);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglPushMatrix ();
|
2001-02-26 06:48:02 +00:00
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RotateForEntity (e);
|
2001-02-26 06:48:02 +00:00
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-14 05:10:29 +00:00
|
|
|
// Build lightmap chains
|
2004-02-15 19:56:28 +00:00
|
|
|
for (i = 0; i < model->nummodelsurfaces; i++, psurf++) {
|
|
|
|
if (psurf->flags & (SURF_DRAWTURB | SURF_DRAWSKY))
|
|
|
|
continue;
|
|
|
|
R_AddToLightmapChain (psurf);
|
|
|
|
}
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2)
|
2004-02-15 00:02:04 +00:00
|
|
|
R_CalcLightmaps ();
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
psurf = &model->surfaces[model->firstmodelsurface];
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// draw texture
|
2002-08-20 00:48:59 +00:00
|
|
|
for (i = 0; i < model->nummodelsurfaces; i++, psurf++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// find which side of the node we are on
|
|
|
|
pplane = psurf->plane;
|
|
|
|
|
|
|
|
dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
|
|
|
|
|
|
|
|
// draw the polygon
|
|
|
|
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
|
2001-05-13 00:28:50 +00:00
|
|
|
if (psurf->flags & SURF_DRAWTURB) {
|
2002-07-07 06:15:36 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D,
|
|
|
|
psurf->texinfo->texture->gl_texturenum);
|
|
|
|
if (cl_wateralpha < 1.0) {
|
2004-02-22 06:00:15 +00:00
|
|
|
if (color[3] >= 1.0)
|
|
|
|
qfglDepthMask (GL_FALSE);
|
|
|
|
watercolor[3] = color[3] * cl_wateralpha;
|
|
|
|
qfglColor4fv (watercolor);
|
2002-07-07 06:15:36 +00:00
|
|
|
EmitWaterPolys (psurf);
|
|
|
|
qfglColor4fv (color);
|
2004-02-22 06:00:15 +00:00
|
|
|
if (color[3] >= 1.0)
|
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
} else {
|
2002-07-07 06:15:36 +00:00
|
|
|
EmitWaterPolys (psurf);
|
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
} else if (psurf->flags & SURF_DRAWSKY) {
|
2002-08-25 05:55:28 +00:00
|
|
|
// QSG FIXME: add modelalpha support for sky brushes
|
2003-03-25 07:25:22 +00:00
|
|
|
CHAIN_SURF_F2B (psurf, sky_chain);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else {
|
2002-04-15 03:26:08 +00:00
|
|
|
texture_t *tex;
|
2002-07-07 06:15:36 +00:00
|
|
|
|
2002-04-15 03:26:08 +00:00
|
|
|
if (!psurf->texinfo->texture->anim_total)
|
|
|
|
tex = psurf->texinfo->texture;
|
|
|
|
else
|
|
|
|
tex = R_TextureAnimation (psurf);
|
2004-02-15 00:02:04 +00:00
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) {
|
|
|
|
if (tex->gl_fb_texturenum && gl_mtex_fullbright) {
|
2004-02-21 05:36:19 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 2);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_fb_texturenum);
|
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures +
|
|
|
|
psurf->lightmaptexturenum);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_3 (psurf);
|
2004-02-21 05:36:19 +00:00
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 2);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
} else {
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures +
|
|
|
|
psurf->lightmaptexturenum);
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_2 (psurf);
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-23 04:25:53 +00:00
|
|
|
R_RenderBrushPoly_1 (psurf);
|
2004-02-22 06:00:15 +00:00
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (tex->gl_fb_texturenum && gl_mtex_fullbright) {
|
2004-02-22 06:00:15 +00:00
|
|
|
psurf->polys->fb_chain =
|
|
|
|
fullbright_polys[tex->gl_fb_texturenum];
|
|
|
|
fullbright_polys[tex->gl_fb_texturenum] = psurf->polys;
|
|
|
|
}
|
2004-02-14 05:10:29 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) {
|
2004-02-21 05:36:19 +00:00
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2004-02-15 00:02:04 +00:00
|
|
|
} else {
|
|
|
|
R_CalcAndBlendLightmaps ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-14 05:10:29 +00:00
|
|
|
if (gl_fb_bmodels->int_val && !gl_mtex_fullbright)
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RenderFullbrights ();
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglPopMatrix ();
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
if (color[3] < 1.0)
|
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
qfglColor3ubv (color_white);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 06:15:36 +00:00
|
|
|
// WORLD MODEL ================================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-15 03:46:55 +00:00
|
|
|
static inline void
|
|
|
|
visit_leaf (mleaf_t *leaf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2004-02-15 03:46:55 +00:00
|
|
|
// deal with model fragments in this leaf
|
|
|
|
if (leaf->efrags)
|
2010-12-03 04:28:58 +00:00
|
|
|
R_StoreEfrags (leaf->efrags);
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-15 03:46:55 +00:00
|
|
|
static inline int
|
|
|
|
get_side (mnode_t *node)
|
|
|
|
{
|
2001-05-13 00:28:50 +00:00
|
|
|
// find which side of the node we are on
|
2004-02-15 03:46:55 +00:00
|
|
|
mplane_t *plane = node->plane;
|
|
|
|
|
2001-09-07 21:15:08 +00:00
|
|
|
if (plane->type < 3)
|
2004-02-15 03:46:55 +00:00
|
|
|
return (modelorg[plane->type] - plane->dist) < 0;
|
|
|
|
return (DotProduct (modelorg, plane->normal) - plane->dist) < 0;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-23 04:46:55 +00:00
|
|
|
static inline void
|
2004-02-15 03:46:55 +00:00
|
|
|
visit_node (mnode_t *node, int side)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
msurface_t *surf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-07 21:15:08 +00:00
|
|
|
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
|
2004-02-15 03:46:55 +00:00
|
|
|
side = (~side + 1) & SURF_PLANEBACK;
|
2001-05-13 00:28:50 +00:00
|
|
|
// draw stuff
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((c = node->numsurfaces)) {
|
2001-05-20 04:25:36 +00:00
|
|
|
surf = r_worldentity.model->surfaces + node->firstsurface;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; c; c--, surf++) {
|
2001-08-05 04:01:45 +00:00
|
|
|
if (surf->visframe != r_visframecount)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
2001-09-07 21:15:08 +00:00
|
|
|
// side is either 0 or SURF_PLANEBACK
|
|
|
|
if (side ^ (surf->flags & SURF_PLANEBACK))
|
2001-02-26 06:48:02 +00:00
|
|
|
continue; // wrong side
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (surf->flags & SURF_DRAWTURB) {
|
2003-03-25 07:25:22 +00:00
|
|
|
CHAIN_SURF_B2F (surf, waterchain);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else if (surf->flags & SURF_DRAWSKY) {
|
2003-03-25 07:25:22 +00:00
|
|
|
CHAIN_SURF_F2B (surf, sky_chain);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else {
|
2002-04-15 03:26:08 +00:00
|
|
|
texture_t *tex;
|
2002-08-25 05:55:28 +00:00
|
|
|
|
2004-02-14 05:10:29 +00:00
|
|
|
R_AddToLightmapChain (surf);
|
|
|
|
|
2002-04-15 03:26:08 +00:00
|
|
|
if (!surf->texinfo->texture->anim_total)
|
|
|
|
tex = surf->texinfo->texture;
|
2003-03-25 07:25:22 +00:00
|
|
|
else
|
2002-04-15 03:26:08 +00:00
|
|
|
tex = R_TextureAnimation (surf);
|
2004-02-22 06:00:15 +00:00
|
|
|
if (gl_fb_bmodels->int_val && tex->gl_fb_texturenum
|
|
|
|
&& !gl_mtex_fullbright) {
|
|
|
|
surf->polys->fb_chain =
|
|
|
|
fullbright_polys[tex->gl_fb_texturenum];
|
2002-04-15 03:26:08 +00:00
|
|
|
fullbright_polys[tex->gl_fb_texturenum] = surf->polys;
|
|
|
|
}
|
2003-03-25 07:25:22 +00:00
|
|
|
CHAIN_SURF_F2B (surf, tex->texturechain);
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
test_node (mnode_t *node)
|
|
|
|
{
|
|
|
|
if (node->contents < 0)
|
|
|
|
return 0;
|
|
|
|
if (node->visframe != r_visframecount)
|
|
|
|
return 0;
|
|
|
|
if (R_CullBox (node->minmaxs, node->minmaxs + 3))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
// FIXME: R_IterativeWorldNode
|
2004-02-15 03:46:55 +00:00
|
|
|
static void
|
|
|
|
R_RecursiveWorldNode (mnode_t *node)
|
|
|
|
{
|
2010-12-10 12:40:36 +00:00
|
|
|
#define NODE_STACK 1024
|
2004-02-15 03:46:55 +00:00
|
|
|
struct {
|
|
|
|
mnode_t *node;
|
|
|
|
int side;
|
2010-12-10 12:40:36 +00:00
|
|
|
} *node_ptr, node_stack[NODE_STACK];
|
2004-02-15 03:46:55 +00:00
|
|
|
mnode_t *front;
|
|
|
|
int side;
|
|
|
|
|
|
|
|
node_ptr = node_stack;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
while (test_node (node)) {
|
|
|
|
side = get_side (node);
|
|
|
|
front = node->children[side];
|
|
|
|
if (test_node (front)) {
|
2010-12-10 12:40:36 +00:00
|
|
|
if (node_ptr - node_stack == NODE_STACK)
|
2004-02-15 03:46:55 +00:00
|
|
|
Sys_Error ("node_stack overflow");
|
|
|
|
node_ptr->node = node;
|
|
|
|
node_ptr->side = side;
|
|
|
|
node_ptr++;
|
|
|
|
node = front;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (front->contents < 0 && front->contents != CONTENTS_SOLID)
|
|
|
|
visit_leaf ((mleaf_t *) front);
|
|
|
|
visit_node (node, side);
|
|
|
|
node = node->children[!side];
|
|
|
|
}
|
|
|
|
if (node->contents < 0 && node->contents != CONTENTS_SOLID)
|
|
|
|
visit_leaf ((mleaf_t *) node);
|
|
|
|
if (node_ptr != node_stack) {
|
|
|
|
node_ptr--;
|
|
|
|
node = node_ptr->node;
|
|
|
|
side = node_ptr->side;
|
|
|
|
visit_node (node, side);
|
|
|
|
node = node->children[!side];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (node->contents < 0 && node->contents != CONTENTS_SOLID)
|
|
|
|
visit_leaf ((mleaf_t *) node);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawWorld (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
entity_t ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&ent, 0, sizeof (ent));
|
2001-05-20 04:25:36 +00:00
|
|
|
ent.model = r_worldentity.model;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (r_refdef.vieworg, modelorg);
|
|
|
|
|
|
|
|
currententity = &ent;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (lightmap_polys, 0, sizeof (lightmap_polys));
|
|
|
|
memset (fullbright_polys, 0, sizeof (fullbright_polys));
|
2001-10-03 02:51:30 +00:00
|
|
|
|
|
|
|
sky_chain = 0;
|
2001-11-05 06:20:35 +00:00
|
|
|
sky_chain_tail = &sky_chain;
|
2001-10-03 02:51:30 +00:00
|
|
|
if (!gl_sky_clip->int_val) {
|
2001-05-13 00:28:50 +00:00
|
|
|
R_DrawSky ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-20 04:25:36 +00:00
|
|
|
R_RecursiveWorldNode (r_worldentity.model->nodes);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-14 05:10:29 +00:00
|
|
|
R_CalcLightmaps ();
|
|
|
|
|
2001-10-03 02:51:30 +00:00
|
|
|
R_DrawSkyChain (sky_chain);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
DrawTextureChains ();
|
|
|
|
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus <= 1)
|
2004-02-14 05:10:29 +00:00
|
|
|
R_BlendLightmaps ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-14 05:10:29 +00:00
|
|
|
if (gl_fb_bmodels->int_val && !gl_mtex_fullbright)
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RenderFullbrights ();
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_MarkLeaves (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
byte solid[4096];
|
|
|
|
byte *vis;
|
2001-11-06 05:06:37 +00:00
|
|
|
int c;
|
|
|
|
unsigned int i;
|
2001-09-01 08:57:04 +00:00
|
|
|
mleaf_t *leaf;
|
|
|
|
mnode_t *node;
|
2001-08-08 22:20:57 +00:00
|
|
|
msurface_t **mark;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (r_oldviewleaf == r_viewleaf && !r_novis->int_val)
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
r_visframecount++;
|
|
|
|
r_oldviewleaf = r_viewleaf;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (r_novis->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
vis = solid;
|
2001-05-20 04:25:36 +00:00
|
|
|
memset (solid, 0xff, (r_worldentity.model->numleafs + 7) >> 3);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-05-20 04:25:36 +00:00
|
|
|
vis = Mod_LeafPVS (r_viewleaf, r_worldentity.model);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2003-04-17 00:01:48 +00:00
|
|
|
for (i = 0; (int) i < r_worldentity.model->numleafs; i++) {
|
2001-02-26 06:48:02 +00:00
|
|
|
if (vis[i >> 3] & (1 << (i & 7))) {
|
2001-08-08 22:20:57 +00:00
|
|
|
leaf = &r_worldentity.model->leafs[i + 1];
|
|
|
|
if ((c = leaf->nummarksurfaces)) {
|
|
|
|
mark = leaf->firstmarksurface;
|
|
|
|
do {
|
|
|
|
(*mark)->visframe = r_visframecount;
|
|
|
|
mark++;
|
|
|
|
} while (--c);
|
|
|
|
}
|
|
|
|
node = (mnode_t *) leaf;
|
2001-02-26 06:48:02 +00:00
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (node->visframe == r_visframecount)
|
|
|
|
break;
|
|
|
|
node->visframe = r_visframecount;
|
|
|
|
node = node->parent;
|
|
|
|
} while (node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int nColinElim;
|
2001-09-01 08:57:04 +00:00
|
|
|
model_t *currentmodel;
|
|
|
|
mvertex_t *r_pcurrentvertbase;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-23 19:57:47 +00:00
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
BuildSurfaceDisplayList (msurface_t *fa)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float s, t;
|
2001-09-01 08:57:04 +00:00
|
|
|
float *vec;
|
2011-06-19 01:48:02 +00:00
|
|
|
int lindex, lnumverts, i;
|
2001-02-26 06:48:02 +00:00
|
|
|
glpoly_t *poly;
|
2001-09-01 08:57:04 +00:00
|
|
|
medge_t *pedges, *r_pedge;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// reconstruct the polygon
|
2001-02-19 21:15:25 +00:00
|
|
|
pedges = currentmodel->edges;
|
|
|
|
lnumverts = fa->numedges;
|
|
|
|
|
|
|
|
// draw texture
|
2001-05-13 00:28:50 +00:00
|
|
|
poly = Hunk_Alloc (sizeof (glpoly_t) + (lnumverts - 4) *
|
|
|
|
VERTEXSIZE * sizeof (float));
|
2001-02-19 21:15:25 +00:00
|
|
|
poly->next = fa->polys;
|
|
|
|
poly->flags = fa->flags;
|
|
|
|
fa->polys = poly;
|
|
|
|
poly->numverts = lnumverts;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnumverts; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lindex = currentmodel->surfedges[fa->firstedge + i];
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lindex > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &pedges[lindex];
|
|
|
|
vec = r_pcurrentvertbase[r_pedge->v[0]].position;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &pedges[-lindex];
|
|
|
|
vec = r_pcurrentvertbase[r_pedge->v[1]].position;
|
|
|
|
}
|
|
|
|
s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
|
|
|
|
s /= fa->texinfo->texture->width;
|
|
|
|
|
|
|
|
t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
|
|
|
|
t /= fa->texinfo->texture->height;
|
|
|
|
|
|
|
|
VectorCopy (vec, poly->verts[i]);
|
|
|
|
poly->verts[i][3] = s;
|
|
|
|
poly->verts[i][4] = t;
|
|
|
|
|
|
|
|
// lightmap texture coordinates
|
|
|
|
s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
|
|
|
|
s -= fa->texturemins[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
s += fa->light_s * 16;
|
2001-02-19 21:15:25 +00:00
|
|
|
s += 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
s /= BLOCK_WIDTH * 16; // fa->texinfo->texture->width;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
|
|
|
|
t -= fa->texturemins[1];
|
2001-02-26 06:48:02 +00:00
|
|
|
t += fa->light_t * 16;
|
2001-02-19 21:15:25 +00:00
|
|
|
t += 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
t /= BLOCK_HEIGHT * 16; // fa->texinfo->texture->height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
poly->verts[i][5] = s;
|
|
|
|
poly->verts[i][6] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove co-linear points - Ed
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!gl_keeptjunctions->int_val && !(fa->flags & SURF_UNDERWATER)) {
|
|
|
|
for (i = 0; i < lnumverts; ++i) {
|
|
|
|
vec3_t v1, v2;
|
|
|
|
float *prev, *this, *next;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
prev = poly->verts[(i + lnumverts - 1) % lnumverts];
|
|
|
|
this = poly->verts[i];
|
|
|
|
next = poly->verts[(i + 1) % lnumverts];
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
VectorSubtract (this, prev, v1);
|
|
|
|
VectorNormalize (v1);
|
|
|
|
VectorSubtract (next, prev, v2);
|
|
|
|
VectorNormalize (v2);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// skip co-linear points
|
|
|
|
# define COLINEAR_EPSILON 0.001
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((fabs (v1[0] - v2[0]) <= COLINEAR_EPSILON) &&
|
|
|
|
(fabs (v1[1] - v2[1]) <= COLINEAR_EPSILON) &&
|
|
|
|
(fabs (v1[2] - v2[2]) <= COLINEAR_EPSILON)) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = i + 1; j < lnumverts; ++j) {
|
|
|
|
int k;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
for (k = 0; k < VERTEXSIZE; ++k)
|
|
|
|
poly->verts[j - 1][k] = poly->verts[j][k];
|
|
|
|
}
|
|
|
|
--lnumverts;
|
|
|
|
++nColinElim;
|
|
|
|
// retry next vertex next time, which is now current vertex
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
poly->numverts = lnumverts;
|
|
|
|
}
|