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
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
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"
|
|
|
|
#include "QF/GL/qf_rmain.h"
|
|
|
|
#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-06-24 09:25:55 +00:00
|
|
|
void EmitWaterPolys (msurface_t *fa);
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
int active_lightmaps;
|
|
|
|
int dlightdivtable[8192];
|
|
|
|
int gl_internalformat;
|
|
|
|
int lightmap_bytes; // 1, 3, or 4
|
|
|
|
int lightmap_textures;
|
|
|
|
int skytexturenum;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// LordHavoc: since lightmaps are now allocated only as needed, allow a ridiculous number :)
|
|
|
|
#define MAX_LIGHTMAPS 1024
|
2001-08-02 02:18:04 +00:00
|
|
|
#define BLOCK_WIDTH 128 // 256
|
|
|
|
#define BLOCK_HEIGHT 128 // 256
|
|
|
|
|
|
|
|
// keep lightmap texture data in main memory so texsubimage can update properly
|
|
|
|
// LordHavoc: changed to be allocated at runtime (typically lower memory usage)
|
2001-09-01 08:57:04 +00:00
|
|
|
byte *lightmaps[MAX_LIGHTMAPS];
|
2001-08-02 02:18:04 +00:00
|
|
|
|
|
|
|
// unsigned int blocklights[BLOCK_WIDTH * BLOCK_HEIGHT * 3];
|
|
|
|
unsigned int blocklights[18 * 18 * 3];
|
2001-09-01 08:57:04 +00:00
|
|
|
int allocated[MAX_LIGHTMAPS][BLOCK_WIDTH];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
typedef struct glRect_s {
|
2001-08-02 02:18:04 +00:00
|
|
|
unsigned short l, t, w, h;
|
2001-02-19 21:15:25 +00:00
|
|
|
} glRect_t;
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
glpoly_t *fullbright_polys[MAX_GLTEXTURES];
|
|
|
|
qboolean lightmap_modified[MAX_LIGHTMAPS];
|
|
|
|
glpoly_t *lightmap_polys[MAX_LIGHTMAPS];
|
|
|
|
glRect_t lightmap_rectchange[MAX_LIGHTMAPS];
|
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)
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
# define CHAIN_SURF CHAIN_SURF_F2B
|
|
|
|
#else
|
|
|
|
# define CHAIN_SURF CHAIN_SURF_B2F
|
|
|
|
#endif
|
2001-09-01 08:57:04 +00:00
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// LordHavoc: place for gl_rsurf setup code
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-05-13 00:28:50 +00:00
|
|
|
glrsurf_init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-02 02:18:04 +00:00
|
|
|
int s;
|
2001-09-01 08:57:04 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&lightmaps, 0, sizeof (lightmaps));
|
2001-08-02 02:18:04 +00:00
|
|
|
dlightdivtable[0] = 1048576 >> 7;
|
|
|
|
for (s = 1; s < 8192; s++)
|
|
|
|
dlightdivtable[s] = 1048576 / (s << 7);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
static void
|
|
|
|
R_RecursiveLightUpdate (mnode_t *node)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int c;
|
2001-02-19 21:15:25 +00:00
|
|
|
msurface_t *surf;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (node->children[0]->contents >= 0)
|
2001-05-13 00:28:50 +00:00
|
|
|
R_RecursiveLightUpdate (node->children[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (node->children[1]->contents >= 0)
|
2001-05-13 00:28:50 +00:00
|
|
|
R_RecursiveLightUpdate (node->children[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((c = node->numsurfaces))
|
2001-05-20 04:25:36 +00:00
|
|
|
for (surf = r_worldentity.model->surfaces + node->firstsurface; c;
|
2001-02-26 06:48:02 +00:00
|
|
|
c--, surf++) surf->cached_dlight = true;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_AddDynamicLights (msurface_t *surf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-11-06 05:06:37 +00:00
|
|
|
float dist;
|
|
|
|
int lnum, maxdist, maxdist2, maxdist3, red, green, blue, smax,
|
|
|
|
smax3, tmax;
|
|
|
|
unsigned int td, i, j, s, t;
|
|
|
|
unsigned int sdtable[18];
|
|
|
|
unsigned int *bl;
|
|
|
|
vec3_t impact, local;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
smax = (surf->extents[0] >> 4) + 1;
|
2001-11-05 14:59:05 +00:00
|
|
|
smax3 = smax * 3;
|
2001-02-26 06:48:02 +00:00
|
|
|
tmax = (surf->extents[1] >> 4) + 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-10-09 20:35:17 +00:00
|
|
|
for (lnum = 0; lnum < r_maxdlights; lnum++) {
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!(surf->dlightbits & (1 << lnum)))
|
|
|
|
continue; // not lit by this light
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-20 05:42:52 +00:00
|
|
|
VectorSubtract (r_dlights[lnum].origin, currententity->origin, local);
|
2001-02-19 21:15:25 +00:00
|
|
|
dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
|
2001-11-09 18:51:33 +00:00
|
|
|
VectorMA (r_dlights[lnum].origin, -dist, surf->plane->normal, impact);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-11-04 11:20:35 +00:00
|
|
|
i = DotProduct (impact, surf->texinfo->vecs[0]) +
|
2001-05-13 00:28:50 +00:00
|
|
|
surf->texinfo->vecs[0][3] - surf->texturemins[0];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// reduce calculations
|
2001-02-26 06:48:02 +00:00
|
|
|
t = dist * dist;
|
|
|
|
for (s = 0; s < smax; s++, i -= 16)
|
|
|
|
sdtable[s] = i * i + t;
|
|
|
|
|
2001-11-04 11:20:35 +00:00
|
|
|
i = DotProduct (impact, surf->texinfo->vecs[1]) +
|
2001-05-13 00:28:50 +00:00
|
|
|
surf->texinfo->vecs[1][3] - surf->texturemins[1];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-11 20:50:16 +00:00
|
|
|
// for comparisons to minimum acceptable light
|
2001-08-22 11:00:25 +00:00
|
|
|
maxdist = (int) ((r_dlights[lnum].radius * r_dlights[lnum].radius) *
|
|
|
|
0.75);
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// clamp radius to avoid exceeding 8192 entry division table
|
|
|
|
if (maxdist > 1048576)
|
|
|
|
maxdist = 1048576;
|
2001-08-22 11:00:25 +00:00
|
|
|
maxdist3 = maxdist - t;
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// convert to 8.8 blocklights format
|
2001-11-04 11:20:35 +00:00
|
|
|
red = r_dlights[lnum].color[0] * maxdist;
|
|
|
|
green = r_dlights[lnum].color[1] * maxdist;
|
|
|
|
blue = r_dlights[lnum].color[2] * maxdist;
|
2001-02-19 21:15:25 +00:00
|
|
|
bl = blocklights;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (t = 0; t < tmax; t++, i -= 16) {
|
|
|
|
td = i * i;
|
2001-08-22 11:00:25 +00:00
|
|
|
if (td < maxdist3) { // ensure part is visible on this line
|
2001-02-19 21:15:25 +00:00
|
|
|
maxdist2 = maxdist - td;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (s = 0; s < smax; s++) {
|
|
|
|
if (sdtable[s] < maxdist2) {
|
|
|
|
j = dlightdivtable[(sdtable[s] + td) >> 7];
|
2001-11-05 14:59:05 +00:00
|
|
|
*bl++ += (red * j) >> 7;
|
|
|
|
*bl++ += (green * j) >> 7;
|
|
|
|
*bl++ += (blue * j) >> 7;
|
|
|
|
} else {
|
|
|
|
bl += 3;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-11-05 14:59:05 +00:00
|
|
|
bl += smax3; // skip line
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-25 23:23:14 +00:00
|
|
|
R_BuildLightMap
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-25 23:23:14 +00:00
|
|
|
Combine and scale multiple lightmaps.
|
|
|
|
After talking it over with LordHavoc, I've decided to switch to using
|
|
|
|
GL_RGB for colored lights and averaging them out for plain white
|
|
|
|
lighting if needed. Much cleaner that way. --KB
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-11-04 11:20:35 +00:00
|
|
|
byte *lightmap;
|
2001-11-06 05:06:37 +00:00
|
|
|
int maps, shift, size, smax, tmax, i, j;
|
|
|
|
unsigned int scale, t2;
|
2001-11-04 11:20:35 +00:00
|
|
|
unsigned int *bl;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
surf->cached_dlight = (surf->dlightframe == r_framecount);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
smax = (surf->extents[0] >> 4) + 1;
|
|
|
|
tmax = (surf->extents[1] >> 4) + 1;
|
|
|
|
size = smax * tmax;
|
2001-02-19 21:15:25 +00:00
|
|
|
lightmap = surf->samples;
|
|
|
|
|
|
|
|
// set to full bright if no light data
|
2001-05-20 04:25:36 +00:00
|
|
|
if (!r_worldentity.model->lightdata) {
|
2001-08-08 23:32:09 +00:00
|
|
|
memset (&blocklights[0], 0xff, 3 * size * sizeof(int));
|
2001-02-19 21:15:25 +00:00
|
|
|
goto store;
|
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// clear to no light
|
2001-05-13 00:28:50 +00:00
|
|
|
memset (&blocklights[0], 0, 3 * size * sizeof(int));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// add all the lightmaps
|
2001-05-13 00:28:50 +00:00
|
|
|
if (lightmap) {
|
2001-10-11 06:54:29 +00:00
|
|
|
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255;
|
2001-08-22 11:00:25 +00:00
|
|
|
maps++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
scale = d_lightstylevalue[surf->styles[maps]];
|
|
|
|
surf->cached_light[maps] = scale; // 8.8 fraction
|
|
|
|
bl = blocklights;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
*bl++ += *lightmap++ * scale;
|
|
|
|
*bl++ += *lightmap++ * scale;
|
|
|
|
*bl++ += *lightmap++ * scale;
|
|
|
|
}
|
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
// add all the dynamic lights
|
|
|
|
if (surf->dlightframe == r_framecount)
|
|
|
|
R_AddDynamicLights (surf);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
store:
|
2001-02-19 21:15:25 +00:00
|
|
|
// bound and shift
|
2001-05-13 00:28:50 +00:00
|
|
|
stride -= smax * lightmap_bytes;
|
|
|
|
bl = blocklights;
|
|
|
|
|
2001-05-29 21:59:02 +00:00
|
|
|
if (gl_mtex_active) {
|
2001-10-10 05:00:30 +00:00
|
|
|
shift = 7; // 0-1 lightmap range.
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-10-10 05:00:30 +00:00
|
|
|
shift = 8; // 0-2 lightmap range.
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (lightmap_bytes) {
|
|
|
|
case 4:
|
|
|
|
for (i = 0; i < tmax; i++, dest += stride) {
|
|
|
|
for (j = 0; j < smax; j++) {
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
|
|
|
*dest++ = 255;
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
for (i = 0; i < tmax; i++, dest += stride) {
|
|
|
|
for (j = 0; j < smax; j++) {
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (*bl >> shift, 255);
|
2001-11-04 16:57:47 +00:00
|
|
|
bl++;
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
for (i = 0; i < tmax; i++, dest += stride) {
|
|
|
|
for (j = 0; j < smax; j++) {
|
2001-11-04 16:57:47 +00:00
|
|
|
t2 = *bl++;
|
|
|
|
t2 += *bl++;
|
|
|
|
t2 += *bl++;
|
|
|
|
t2 /= 3;
|
2001-11-09 18:51:33 +00:00
|
|
|
*dest++ = min (t2 >> shift, 255);
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
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 *
|
|
|
|
R_TextureAnimation (texture_t *base)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
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-02-19 21:15:25 +00:00
|
|
|
if (!base->anim_total)
|
|
|
|
return base;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
/* BRUSH MODELS */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
GL_UploadLightmap (int i, int x, int y, int w, int h)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-02 02:18:04 +00:00
|
|
|
/* qfglTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h,
|
|
|
|
gl_lightmap_format, GL_UNSIGNED_BYTE,
|
|
|
|
lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
|
2001-05-13 00:28:50 +00:00
|
|
|
*/
|
2001-08-02 02:18:04 +00:00
|
|
|
switch (gl_lightmap_subimage->int_val) {
|
|
|
|
case 2:
|
|
|
|
qfglTexSubImage2D (GL_TEXTURE_2D, 0, x, y, w, h,
|
|
|
|
gl_lightmap_format, GL_UNSIGNED_BYTE,
|
|
|
|
lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
qfglTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h,
|
|
|
|
gl_lightmap_format, GL_UNSIGNED_BYTE,
|
|
|
|
lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_internalformat, BLOCK_WIDTH,
|
|
|
|
BLOCK_HEIGHT, 0, gl_lightmap_format, GL_UNSIGNED_BYTE,
|
|
|
|
lightmaps[i]);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_DrawMultitexturePoly (msurface_t *s)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float *v;
|
2001-09-01 08:57:04 +00:00
|
|
|
int maps, i;
|
2001-02-26 06:48:02 +00:00
|
|
|
texture_t *texture = R_TextureAnimation (s->texinfo->texture);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
c_brush_polys++;
|
|
|
|
|
|
|
|
i = s->lightmaptexturenum;
|
|
|
|
|
|
|
|
// Binds world to texture env 0
|
2001-05-13 00:28:50 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture->gl_texturenum);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2001-02-19 21:15:25 +00:00
|
|
|
// Binds lightmap to texenv 1
|
2001-05-13 00:28:50 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures + i);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// check for lightmap modification
|
2001-02-26 06:48:02 +00:00
|
|
|
if (r_dynamic->int_val) {
|
|
|
|
for (maps = 0; maps < MAXLIGHTMAPS && s->styles[maps] != 255; maps++)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
|
|
|
|
goto dynamic;
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if ((s->dlightframe == r_framecount) || s->cached_dlight) {
|
2001-02-26 06:48:02 +00:00
|
|
|
dynamic:
|
|
|
|
R_BuildLightMap (s,
|
|
|
|
lightmaps[s->lightmaptexturenum] +
|
|
|
|
(s->light_t * BLOCK_WIDTH +
|
|
|
|
s->light_s) * lightmap_bytes,
|
|
|
|
BLOCK_WIDTH * lightmap_bytes);
|
|
|
|
GL_UploadLightmap (i, s->light_s, s->light_t,
|
|
|
|
(s->extents[0] >> 4) + 1,
|
|
|
|
(s->extents[1] >> 4) + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-02-19 21:15:25 +00:00
|
|
|
v = s->polys->verts[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < s->polys->numverts; i++, v += VERTEXSIZE) {
|
2001-05-13 00:28:50 +00:00
|
|
|
qglMultiTexCoord2f (gl_mtex_enum + 0, v[3], v[4]);
|
|
|
|
qglMultiTexCoord2f (gl_mtex_enum + 1, v[5], v[6]);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglVertex3fv (v);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
2001-05-13 00:28:50 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (texture->gl_fb_texturenum > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
s->polys->fb_chain = fullbright_polys[texture->gl_fb_texturenum];
|
|
|
|
fullbright_polys[texture->gl_fb_texturenum] = s->polys;
|
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_BlendLightmaps (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
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-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE); // don't bother writing Z
|
|
|
|
qfglBlendFunc (GL_DST_COLOR, GL_SRC_COLOR);
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < MAX_LIGHTMAPS; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
p = lightmap_polys[i];
|
|
|
|
if (!p)
|
|
|
|
continue;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures + i);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lightmap_modified[i]) {
|
|
|
|
GL_UploadLightmap (i, lightmap_rectchange[i].l,
|
|
|
|
lightmap_rectchange[i].t,
|
|
|
|
lightmap_rectchange[i].w,
|
|
|
|
lightmap_rectchange[i].h);
|
2001-02-19 21:15:25 +00:00
|
|
|
lightmap_modified[i] = false;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; p; p = p->chain) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-02-19 21:15:25 +00:00
|
|
|
v = p->verts[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < p->numverts; j++, v += VERTEXSIZE) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2fv (&v[5]);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return to normal blending --KB
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
qfglDepthMask (GL_TRUE); // back to normal Z buffering
|
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-06-26 02:26:46 +00:00
|
|
|
qfglBlendFunc (GL_ONE, GL_ONE);
|
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
|
|
|
}
|
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_RenderBrushPoly (msurface_t *fa)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *base;
|
|
|
|
float *v;
|
2001-09-01 08:57:04 +00:00
|
|
|
int maps, smax, tmax, i;
|
|
|
|
glRect_t *theRect;
|
2001-02-26 06:48:02 +00:00
|
|
|
texture_t *texture = R_TextureAnimation (fa->texinfo->texture);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
c_brush_polys++;
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, texture->gl_texturenum);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-02-19 21:15:25 +00:00
|
|
|
v = fa->polys->verts[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < fa->polys->numverts; i++, 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
|
|
|
|
|
|
|
// add the poly to the proper lightmap chain
|
|
|
|
|
|
|
|
fa->polys->chain = lightmap_polys[fa->lightmaptexturenum];
|
|
|
|
lightmap_polys[fa->lightmaptexturenum] = fa->polys;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (texture->gl_fb_texturenum > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
fa->polys->fb_chain = fullbright_polys[texture->gl_fb_texturenum];
|
|
|
|
fullbright_polys[texture->gl_fb_texturenum] = 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:
|
|
|
|
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;
|
2001-11-05 14:59:05 +00:00
|
|
|
base = lightmaps[fa->lightmaptexturenum] +
|
2001-05-13 00:28:50 +00:00
|
|
|
(fa->light_t * BLOCK_WIDTH + fa->light_s) * lightmap_bytes;
|
2001-02-26 06:48:02 +00:00
|
|
|
R_BuildLightMap (fa, base, BLOCK_WIDTH * lightmap_bytes);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
GL_WaterSurface (msurface_t *s)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-11-05 14:59:05 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, s->texinfo->texture->gl_texturenum);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (r_wateralpha->value < 1.0) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-08-30 18:24:19 +00:00
|
|
|
color_white[3] = r_wateralpha->value * 255;
|
|
|
|
qfglColor4ubv (color_white);
|
2001-02-19 21:15:25 +00:00
|
|
|
EmitWaterPolys (s);
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_TRUE);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
EmitWaterPolys (s);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (r_wateralpha->value < 1.0) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2001-08-30 18:24:19 +00:00
|
|
|
color_white[3] = r_wateralpha->value * 255;
|
|
|
|
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
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (r_wateralpha->value < 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
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
DrawTextureChains (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
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDisable (GL_BLEND);
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-05-20 04:25:36 +00:00
|
|
|
for (i = 0; i < r_worldentity.model->numtextures; i++) {
|
2001-11-05 06:20:35 +00:00
|
|
|
texture_t *tex = r_worldentity.model->textures[i];
|
|
|
|
if (!tex)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-11-05 06:20:35 +00:00
|
|
|
for (s = tex->texturechain; s; s = s->texturechain)
|
|
|
|
R_RenderBrushPoly (s);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-05 06:20:35 +00:00
|
|
|
tex->texturechain = NULL;
|
|
|
|
tex->texturechain_tail = &tex->texturechain;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnable (GL_BLEND);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-04 07:40:35 +00:00
|
|
|
// FIXME: add modelalpha support?
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_DrawBrushModel (entity_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float dot;
|
2001-09-01 08:57:04 +00:00
|
|
|
int i, k;
|
2001-02-26 06:48:02 +00:00
|
|
|
model_t *clmodel;
|
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
|
|
|
|
|
|
|
clmodel = e->model;
|
|
|
|
|
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;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
mins[i] = e->origin[i] - clmodel->radius;
|
|
|
|
maxs[i] = e->origin[i] + clmodel->radius;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
rotated = false;
|
|
|
|
VectorAdd (e->origin, clmodel->mins, mins);
|
|
|
|
VectorAdd (e->origin, clmodel->maxs, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_CullBox (mins, maxs))
|
|
|
|
return;
|
|
|
|
|
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) {
|
|
|
|
vec3_t temp;
|
|
|
|
vec3_t 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
psurf = &clmodel->surfaces[clmodel->firstmodelsurface];
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// calculate dynamic lighting for bmodel if it's not an instanced model
|
2001-08-25 23:23:14 +00:00
|
|
|
if (clmodel->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,
|
|
|
|
clmodel->nodes + clmodel->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
|
|
|
|
|
|
|
// draw texture
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < clmodel->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) {
|
2001-02-26 06:48:02 +00:00
|
|
|
GL_WaterSurface (psurf);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else if (psurf->flags & SURF_DRAWSKY) {
|
2001-11-05 06:20:35 +00:00
|
|
|
CHAIN_SURF (psurf, sky_chain);
|
2001-05-13 00:28:50 +00:00
|
|
|
return;
|
|
|
|
} else if (gl_mtex_active) {
|
2001-02-19 21:15:25 +00:00
|
|
|
R_DrawMultitexturePoly (psurf);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else {
|
|
|
|
R_RenderBrushPoly (psurf);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (!gl_mtex_active)
|
2001-02-19 21:15:25 +00:00
|
|
|
R_BlendLightmaps ();
|
|
|
|
|
|
|
|
if (gl_fb_bmodels->int_val)
|
|
|
|
R_RenderFullbrights ();
|
|
|
|
|
2001-11-06 05:06:37 +00:00
|
|
|
// if (gl_sky_clip->int_val)
|
|
|
|
// R_DrawSkyChain (sky_chain);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglPopMatrix ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-09-01 08:57:04 +00:00
|
|
|
/* WORLD MODEL */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_RecursiveWorldNode (mnode_t *node)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
double dot;
|
2001-02-26 06:48:02 +00:00
|
|
|
int c, side;
|
2001-09-01 08:57:04 +00:00
|
|
|
mleaf_t *pleaf;
|
2001-02-26 06:48:02 +00:00
|
|
|
mplane_t *plane;
|
2001-08-08 22:20:57 +00:00
|
|
|
msurface_t *surf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (node->contents == CONTENTS_SOLID)
|
2001-05-13 00:28:50 +00:00
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (node->visframe != r_visframecount)
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (R_CullBox (node->minmaxs, node->minmaxs + 3))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// if a leaf node, draw stuff
|
2001-02-26 06:48:02 +00:00
|
|
|
if (node->contents < 0) {
|
|
|
|
pleaf = (mleaf_t *) node;
|
|
|
|
// deal with model fragments in this leaf
|
2001-02-19 21:15:25 +00:00
|
|
|
if (pleaf->efrags)
|
|
|
|
R_StoreEfrags (&pleaf->efrags);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2001-11-20 09:41:15 +00:00
|
|
|
// node is just a decision point, so go down the appropriate sides
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// find which side of the node we are on
|
2001-02-19 21:15:25 +00:00
|
|
|
plane = node->plane;
|
2001-09-07 21:15:08 +00:00
|
|
|
if (plane->type < 3)
|
|
|
|
dot = modelorg[plane->type] - plane->dist;
|
|
|
|
else
|
|
|
|
dot = DotProduct (modelorg, plane->normal) - plane->dist;
|
2001-02-19 21:15:25 +00:00
|
|
|
side = dot < 0;
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// recurse down the children, front side first
|
2001-08-29 03:27:31 +00:00
|
|
|
R_RecursiveWorldNode (node->children[side]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-07 21:15:08 +00:00
|
|
|
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
|
|
|
|
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) {
|
2001-11-24 08:21:07 +00:00
|
|
|
// if (r_wateralpha->value < 1.0) // FIXME: DESPAIR
|
2001-11-05 06:20:35 +00:00
|
|
|
CHAIN_SURF_B2F (surf, waterchain);
|
2001-11-24 08:21:07 +00:00
|
|
|
// else
|
|
|
|
// CHAIN_SURF (surf, waterchain);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else if (surf->flags & SURF_DRAWSKY) {
|
2001-11-05 06:20:35 +00:00
|
|
|
CHAIN_SURF (surf, sky_chain);
|
2001-05-13 00:28:50 +00:00
|
|
|
} else if (gl_mtex_active) {
|
|
|
|
R_DrawMultitexturePoly (surf);
|
|
|
|
} else {
|
2001-11-05 06:20:35 +00:00
|
|
|
CHAIN_SURF (surf, surf->texinfo->texture->texturechain);
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
// recurse down the back side
|
2001-08-29 03:27:31 +00:00
|
|
|
R_RecursiveWorldNode (node->children[!side]);
|
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
|
|
|
|
2001-10-03 02:51:30 +00:00
|
|
|
R_DrawSkyChain (sky_chain);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
DrawTextureChains ();
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (!gl_mtex_active)
|
2001-02-19 21:15:25 +00:00
|
|
|
R_BlendLightmaps ();
|
|
|
|
|
|
|
|
if (gl_fb_bmodels->int_val)
|
|
|
|
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
|
|
|
|
2001-05-20 04:25:36 +00:00
|
|
|
for (i = 0; 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-09-01 08:57:04 +00:00
|
|
|
/* LIGHTMAP ALLOCATION */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// returns a texture number and the position inside it
|
2001-11-20 09:41:15 +00:00
|
|
|
static int
|
2001-02-26 06:48:02 +00:00
|
|
|
AllocBlock (int w, int h, int *x, int *y)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
int best, best2, texnum, i, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (texnum = 0; texnum < MAX_LIGHTMAPS; texnum++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
best = BLOCK_HEIGHT;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < BLOCK_WIDTH - w; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
best2 = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < w; j++) {
|
|
|
|
if (allocated[texnum][i + j] >= best)
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (allocated[texnum][i + j] > best2)
|
|
|
|
best2 = allocated[texnum][i + j];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (j == w) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// this is a valid spot
|
|
|
|
*x = i;
|
|
|
|
*y = best = best2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best + h > BLOCK_HEIGHT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// LordHavoc: allocate lightmaps only as needed
|
|
|
|
if (!lightmaps[texnum])
|
2001-08-02 02:18:04 +00:00
|
|
|
lightmaps[texnum] = calloc (BLOCK_WIDTH * BLOCK_HEIGHT,
|
|
|
|
lightmap_bytes);
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < w; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
allocated[texnum][*x + i] = best + h;
|
|
|
|
|
|
|
|
return texnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Error ("AllocBlock: full");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static 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;
|
|
|
|
int lindex, lnumverts, vertpage, 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;
|
|
|
|
vertpage = 0;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
GL_CreateSurfaceLightmap (msurface_t *surf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *base;
|
2001-09-01 08:57:04 +00:00
|
|
|
int smax, tmax;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (surf->flags & (SURF_DRAWSKY | SURF_DRAWTURB))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
smax = (surf->extents[0] >> 4) + 1;
|
|
|
|
tmax = (surf->extents[1] >> 4) + 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
surf->lightmaptexturenum =
|
|
|
|
AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
|
2001-05-13 00:28:50 +00:00
|
|
|
base = lightmaps[surf->lightmaptexturenum] +
|
|
|
|
(surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes;
|
2001-02-26 06:48:02 +00:00
|
|
|
R_BuildLightMap (surf, base, BLOCK_WIDTH * lightmap_bytes);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-25 23:23:14 +00:00
|
|
|
GL_BuildLightmaps
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-25 23:23:14 +00:00
|
|
|
Builds the lightmap texture with all the surfaces from all brush models
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-05-21 23:09:46 +00:00
|
|
|
GL_BuildLightmaps (model_t **models, int num_models)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j;
|
|
|
|
model_t *m;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (allocated, 0, sizeof (allocated));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r_framecount = 1; // no dlightcache
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!lightmap_textures) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lightmap_textures = texture_extension_number;
|
|
|
|
texture_extension_number += MAX_LIGHTMAPS;
|
|
|
|
}
|
|
|
|
|
2001-08-25 23:23:14 +00:00
|
|
|
switch (r_lightmap_components->int_val) {
|
2001-05-13 00:28:50 +00:00
|
|
|
case 1:
|
2001-05-20 04:36:20 +00:00
|
|
|
gl_internalformat = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
gl_lightmap_format = GL_LUMINANCE;
|
|
|
|
lightmap_bytes = 1;
|
2001-05-13 00:28:50 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2001-05-20 04:36:20 +00:00
|
|
|
gl_internalformat = 3;
|
2001-05-13 00:28:50 +00:00
|
|
|
gl_lightmap_format = GL_RGB;
|
|
|
|
lightmap_bytes = 3;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
default:
|
2001-05-20 04:36:20 +00:00
|
|
|
gl_internalformat = 3;
|
2001-05-13 00:28:50 +00:00
|
|
|
gl_lightmap_format = GL_RGBA;
|
2001-08-02 04:12:26 +00:00
|
|
|
lightmap_bytes = 4;
|
2001-05-13 00:28:50 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-21 23:09:46 +00:00
|
|
|
for (j = 1; j < num_models; j++) {
|
|
|
|
m = models[j];
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!m)
|
|
|
|
break;
|
|
|
|
if (m->name[0] == '*')
|
|
|
|
continue;
|
|
|
|
r_pcurrentvertbase = m->vertexes;
|
|
|
|
currentmodel = m;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < m->numsurfaces; i++) {
|
|
|
|
if (m->surfaces[i].flags & SURF_DRAWTURB)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-08-25 23:23:14 +00:00
|
|
|
if (gl_sky_divide->int_val && (m->surfaces[i].flags &
|
|
|
|
SURF_DRAWSKY))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
GL_CreateSurfaceLightmap (m->surfaces + i);
|
|
|
|
BuildSurfaceDisplayList (m->surfaces + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (gl_mtex_active)
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// upload all lightmaps that were filled
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < MAX_LIGHTMAPS; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!allocated[i][0])
|
2001-02-26 06:48:02 +00:00
|
|
|
break; // no more used
|
2001-02-19 21:15:25 +00:00
|
|
|
lightmap_modified[i] = false;
|
|
|
|
lightmap_rectchange[i].l = BLOCK_WIDTH;
|
|
|
|
lightmap_rectchange[i].t = BLOCK_HEIGHT;
|
|
|
|
lightmap_rectchange[i].w = 0;
|
|
|
|
lightmap_rectchange[i].h = 0;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, lightmap_textures + i);
|
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
qfglTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, BLOCK_WIDTH,
|
2001-02-26 06:48:02 +00:00
|
|
|
BLOCK_HEIGHT, 0, gl_lightmap_format,
|
|
|
|
GL_UNSIGNED_BYTE, lightmaps[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
if (gl_mtex_active)
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|