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
|
|
|
|
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
|
|
|
|
2013-01-22 05:09:41 +00:00
|
|
|
#include "qfalloca.h"
|
|
|
|
|
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"
|
2021-07-24 05:19:52 +00:00
|
|
|
|
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
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"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2022-03-07 14:32:44 +00:00
|
|
|
#include "vid_gl.h"
|
2001-08-02 02:18:04 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
static instsurf_t *waterchain = NULL;
|
|
|
|
static instsurf_t **waterchain_tail = &waterchain;
|
|
|
|
static instsurf_t *sky_chain;
|
|
|
|
static instsurf_t **sky_chain_tail;
|
2001-11-05 06:20:35 +00:00
|
|
|
|
2021-07-22 06:39:28 +00:00
|
|
|
typedef struct glbspctx_s {
|
|
|
|
mod_brush_t *brush;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
animation_t *animation;
|
|
|
|
vec4f_t *transform;
|
2021-07-22 06:39:28 +00:00
|
|
|
float *color;
|
|
|
|
} glbspctx_t;
|
|
|
|
|
2011-12-17 12:45:52 +00:00
|
|
|
#define CHAIN_SURF_F2B(surf,chain) \
|
2021-07-13 07:02:47 +00:00
|
|
|
({ \
|
2011-12-17 12:45:52 +00:00
|
|
|
instsurf_t *inst = (surf)->instsurf; \
|
2012-01-19 19:44:26 +00:00
|
|
|
if (__builtin_expect(!inst, 1)) \
|
2021-07-13 07:02:47 +00:00
|
|
|
inst = get_instsurf (); \
|
2011-12-17 12:45:52 +00:00
|
|
|
inst->surface = (surf); \
|
|
|
|
*(chain##_tail) = inst; \
|
|
|
|
(chain##_tail) = &inst->tex_chain; \
|
|
|
|
*(chain##_tail) = 0; \
|
2021-07-13 07:02:47 +00:00
|
|
|
inst; \
|
|
|
|
})
|
2001-11-05 06:20:35 +00:00
|
|
|
|
2011-12-17 12:45:52 +00:00
|
|
|
#define CHAIN_SURF_B2F(surf,chain) \
|
2021-07-13 07:02:47 +00:00
|
|
|
({ \
|
2011-12-17 12:45:52 +00:00
|
|
|
instsurf_t *inst = (surf)->instsurf; \
|
2012-01-19 19:44:26 +00:00
|
|
|
if (__builtin_expect(!inst, 1)) \
|
2021-07-13 07:02:47 +00:00
|
|
|
inst = get_instsurf (); \
|
2011-12-17 12:45:52 +00:00
|
|
|
inst->surface = (surf); \
|
|
|
|
inst->tex_chain = (chain); \
|
|
|
|
(chain) = inst; \
|
2021-07-13 07:02:47 +00:00
|
|
|
inst; \
|
|
|
|
})
|
2001-11-05 06:20:35 +00:00
|
|
|
|
2021-01-19 04:05:39 +00:00
|
|
|
static gltex_t **r_texture_chains;
|
2011-12-17 10:14:14 +00:00
|
|
|
static int r_num_texture_chains;
|
|
|
|
static int max_texture_chains;
|
2011-12-17 10:42:19 +00:00
|
|
|
|
2011-12-17 10:14:14 +00:00
|
|
|
static instsurf_t *static_chains;
|
2011-12-17 10:42:19 +00:00
|
|
|
static instsurf_t *free_instsurfs;
|
|
|
|
static instsurf_t *alloced_instsurfs;
|
|
|
|
static instsurf_t **alloced_instsurfs_tail = &alloced_instsurfs;
|
|
|
|
#define NUM_INSTSURFS (64 * 6) // most brush models are simple boxes.
|
|
|
|
|
|
|
|
static inline instsurf_t *
|
|
|
|
get_instsurf (void)
|
|
|
|
{
|
|
|
|
instsurf_t *instsurf;
|
|
|
|
|
|
|
|
if (!free_instsurfs) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
free_instsurfs = calloc (NUM_INSTSURFS, sizeof (instsurf_t));
|
|
|
|
for (i = 0; i < NUM_INSTSURFS - 1; i++)
|
2012-01-08 01:29:38 +00:00
|
|
|
free_instsurfs[i]._next = &free_instsurfs[i + 1];
|
2011-12-17 10:42:19 +00:00
|
|
|
}
|
|
|
|
instsurf = free_instsurfs;
|
2012-01-08 01:29:38 +00:00
|
|
|
free_instsurfs = instsurf->_next;
|
|
|
|
instsurf->_next = 0;
|
2011-12-17 10:42:19 +00:00
|
|
|
//build the chain of allocated instance surfaces so they can all be freed
|
|
|
|
//in one go
|
|
|
|
*alloced_instsurfs_tail = instsurf;
|
2012-01-08 01:29:38 +00:00
|
|
|
alloced_instsurfs_tail = &instsurf->_next;
|
2011-12-17 10:42:19 +00:00
|
|
|
return instsurf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
release_instsurfs (void)
|
|
|
|
{
|
|
|
|
if (alloced_instsurfs) {
|
|
|
|
*alloced_instsurfs_tail = free_instsurfs;
|
|
|
|
free_instsurfs = alloced_instsurfs;
|
|
|
|
alloced_instsurfs = 0;
|
|
|
|
alloced_instsurfs_tail = &alloced_instsurfs;
|
|
|
|
}
|
|
|
|
}
|
2011-12-17 10:14:14 +00:00
|
|
|
|
|
|
|
void
|
2021-01-19 04:05:39 +00:00
|
|
|
gl_R_AddTexture (texture_t *tx)
|
2011-12-17 10:14:14 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (r_num_texture_chains == max_texture_chains) {
|
|
|
|
max_texture_chains += 64;
|
|
|
|
r_texture_chains = realloc (r_texture_chains,
|
2021-01-19 04:05:39 +00:00
|
|
|
max_texture_chains * sizeof (gltex_t *));
|
2011-12-17 10:14:14 +00:00
|
|
|
for (i = r_num_texture_chains; i < max_texture_chains; i++)
|
|
|
|
r_texture_chains[i] = 0;
|
|
|
|
}
|
2021-01-19 04:05:39 +00:00
|
|
|
gltex_t *tex = tx->render;
|
2011-12-17 10:14:14 +00:00
|
|
|
r_texture_chains[r_num_texture_chains++] = tex;
|
|
|
|
tex->tex_chain = NULL;
|
|
|
|
tex->tex_chain_tail = &tex->tex_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-02-01 10:31:11 +00:00
|
|
|
gl_R_InitSurfaceChains (mod_brush_t *brush)
|
2011-12-17 10:14:14 +00:00
|
|
|
{
|
|
|
|
if (static_chains)
|
|
|
|
free (static_chains);
|
2021-02-01 10:31:11 +00:00
|
|
|
static_chains = calloc (brush->nummodelsurfaces, sizeof (instsurf_t));
|
2021-08-01 12:54:05 +00:00
|
|
|
for (unsigned i = 0; i < brush->nummodelsurfaces; i++)
|
2021-02-01 10:31:11 +00:00
|
|
|
brush->surfaces[i].instsurf = static_chains + i;
|
2011-12-17 10:14:14 +00:00
|
|
|
|
2011-12-17 10:42:19 +00:00
|
|
|
release_instsurfs ();
|
2011-12-17 10:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_ClearTextures (void)
|
2011-12-17 10:14:14 +00:00
|
|
|
{
|
|
|
|
r_num_texture_chains = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
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;
|
2011-12-17 12:45:52 +00:00
|
|
|
instsurf_t *sc;
|
2021-01-19 04:05:39 +00:00
|
|
|
gltex_t *tex;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-12-17 12:45:52 +00:00
|
|
|
for (i = 0; i < r_num_texture_chains; i++) {
|
|
|
|
if (!(tex = r_texture_chains[i]) || !tex->gl_fb_texturenum)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2011-12-17 12:45:52 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_fb_texturenum);
|
|
|
|
for (sc = tex->tex_chain; sc; sc = sc->tex_chain) {
|
|
|
|
if (sc->transform) {
|
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
qfglLoadMatrixf ((vec_t*)&sc->transform[0]);//FIXME
|
2011-12-17 12:45:52 +00:00
|
|
|
}
|
|
|
|
if (sc->color)
|
|
|
|
qfglColor4fv (sc->color);
|
|
|
|
for (p = sc->surface->polys; p; p = p->next) {
|
|
|
|
qfglBegin (GL_POLYGON);
|
|
|
|
for (j = 0, v = p->verts[0]; j < p->numverts;
|
|
|
|
j++, v += VERTEXSIZE)
|
|
|
|
{
|
|
|
|
qfglTexCoord2fv (&v[3]);
|
|
|
|
qfglVertex3fv (v);
|
|
|
|
}
|
|
|
|
qfglEnd ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2011-12-17 12:45:52 +00:00
|
|
|
if (sc->transform)
|
|
|
|
qfglPopMatrix ();
|
|
|
|
if (sc->color)
|
|
|
|
qfglColor3ubv (color_white);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-22 06:00:15 +00:00
|
|
|
static inline void
|
2021-07-15 12:38:12 +00:00
|
|
|
R_RenderBrushPoly_3 (msurface_t *surf)
|
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
|
|
|
|
2022-03-07 14:32:44 +00:00
|
|
|
gl_ctx->brush_polys++;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2021-07-15 12:38:12 +00:00
|
|
|
v = surf->polys->verts[0];
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
2004-02-22 06:00:15 +00:00
|
|
|
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
|
2021-07-15 12:38:12 +00:00
|
|
|
R_RenderBrushPoly_2 (msurface_t *surf)
|
2004-02-22 06:00:15 +00:00
|
|
|
{
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
2022-03-07 14:32:44 +00:00
|
|
|
gl_ctx->brush_polys++;
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
qfglBegin (GL_POLYGON);
|
2021-07-15 12:38:12 +00:00
|
|
|
v = surf->polys->verts[0];
|
2004-02-22 06:00:15 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
2004-02-22 06:00:15 +00:00
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 0, &v[3]);
|
|
|
|
qglMultiTexCoord2fv (gl_mtex_enum + 1, &v[5]);
|
|
|
|
qfglVertex3fv (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2021-07-15 12:38:12 +00:00
|
|
|
R_RenderBrushPoly_1 (msurface_t *surf)
|
2004-02-22 06:00:15 +00:00
|
|
|
{
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
|
2022-03-07 14:32:44 +00:00
|
|
|
gl_ctx->brush_polys++;
|
2004-02-22 06:00:15 +00:00
|
|
|
|
|
|
|
qfglBegin (GL_POLYGON);
|
2021-07-15 12:38:12 +00:00
|
|
|
v = surf->polys->verts[0];
|
2004-02-22 06:00:15 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
for (i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE) {
|
2004-02-22 06:00:15 +00:00
|
|
|
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
|
2021-07-22 06:39:28 +00:00
|
|
|
R_AddToLightmapChain (glbspctx_t *bctx, msurface_t *surf, instsurf_t *sc)
|
2004-02-14 05:10:29 +00:00
|
|
|
{
|
2022-05-10 15:27:55 +00:00
|
|
|
int maps;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// add the poly to the proper lightmap chain
|
2022-05-10 15:27:55 +00:00
|
|
|
sc->lm_chain = gl_lightmap_polys;
|
|
|
|
gl_lightmap_polys = sc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// check for lightmap modification
|
2021-07-15 12:38:12 +00:00
|
|
|
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
|
|
|
if (d_lightstylevalue[surf->styles[maps]] != surf->cached_light[maps])
|
2001-02-19 21:15:25 +00:00
|
|
|
goto dynamic;
|
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
if ((surf->dlightframe == r_framecount) || surf->cached_dlight) {
|
2001-02-26 06:48:02 +00:00
|
|
|
dynamic:
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (r_dynamic) {
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
gl_R_BuildLightMap (bctx->transform, bctx->brush, surf);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawWaterSurfaces (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2011-12-17 10:14:14 +00:00
|
|
|
instsurf_t *s;
|
2021-07-15 12:38:12 +00:00
|
|
|
msurface_t *surf;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
float wateralpha = max (vr_data.min_wateralpha, r_wateralpha);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!waterchain)
|
|
|
|
return;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
if (wateralpha < 1.0) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthMask (GL_FALSE);
|
2012-02-14 08:28:09 +00:00
|
|
|
color_white[3] = 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;
|
2011-12-17 10:14:14 +00:00
|
|
|
for (s = waterchain; s; s = s->tex_chain) {
|
2021-01-19 04:05:39 +00:00
|
|
|
gltex_t *tex;
|
2021-07-15 12:38:12 +00:00
|
|
|
surf = s->surface;
|
2022-03-14 05:31:23 +00:00
|
|
|
if (s->transform) {
|
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
|
2022-03-14 05:31:23 +00:00
|
|
|
}
|
2021-07-15 12:38:12 +00:00
|
|
|
tex = surf->texinfo->texture->render;
|
2021-01-19 04:05:39 +00:00
|
|
|
if (i != tex->gl_texturenum) {
|
|
|
|
i = tex->gl_texturenum;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, i);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2021-07-15 12:38:12 +00:00
|
|
|
GL_EmitWaterPolys (surf);
|
2022-03-14 05:31:23 +00:00
|
|
|
if (s->transform) {
|
|
|
|
qfglPopMatrix ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
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
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
if (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
|
|
|
}
|
|
|
|
|
2012-01-19 19:44:26 +00:00
|
|
|
static void
|
2011-12-12 05:35:53 +00:00
|
|
|
DrawTextureChains (int disable_blend, int do_bind)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2004-02-22 06:00:15 +00:00
|
|
|
int i;
|
2011-12-17 10:14:14 +00:00
|
|
|
instsurf_t *s;
|
2021-07-15 12:38:12 +00:00
|
|
|
msurface_t *surf;
|
2021-01-19 04:05:39 +00:00
|
|
|
gltex_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);
|
2022-05-10 15:27:55 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, gl_R_LightmapTexture ());
|
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
|
|
|
|
2011-12-17 12:45:52 +00:00
|
|
|
for (i = 0; i < r_num_texture_chains; i++) {
|
|
|
|
tex = r_texture_chains[i];
|
2004-02-22 06:00:15 +00:00
|
|
|
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
|
|
|
|
2011-12-17 10:14:14 +00:00
|
|
|
for (s = tex->tex_chain; s; s = s->tex_chain) {
|
2021-07-15 12:38:12 +00:00
|
|
|
surf = s->surface;
|
2011-12-17 10:14:14 +00:00
|
|
|
if (s->transform) {
|
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
|
2011-12-17 10:14:14 +00:00
|
|
|
}
|
|
|
|
if (s->color && do_bind)
|
|
|
|
qfglColor4fv (s->color);
|
2011-12-17 12:45:52 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
R_RenderBrushPoly_3 (surf);
|
2011-12-17 12:45:52 +00:00
|
|
|
|
2011-12-17 10:14:14 +00:00
|
|
|
if (s->transform)
|
|
|
|
qfglPopMatrix ();
|
|
|
|
if (s->color && do_bind)
|
|
|
|
qfglColor3ubv (color_white);
|
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 {
|
2011-12-17 10:14:14 +00:00
|
|
|
for (s = tex->tex_chain; s; s = s->tex_chain) {
|
2021-07-15 12:38:12 +00:00
|
|
|
surf = s->surface;
|
2011-12-17 10:14:14 +00:00
|
|
|
|
|
|
|
if (s->transform) {
|
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
|
2011-12-17 10:14:14 +00:00
|
|
|
}
|
|
|
|
if (s->color && do_bind)
|
|
|
|
qfglColor4fv (s->color);
|
2021-07-15 12:38:12 +00:00
|
|
|
R_RenderBrushPoly_2 (surf);
|
2011-12-17 10:14:14 +00:00
|
|
|
|
|
|
|
if (s->transform)
|
|
|
|
qfglPopMatrix ();
|
|
|
|
if (s->color && do_bind)
|
|
|
|
qfglColor3ubv (color_white);
|
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);
|
|
|
|
}
|
|
|
|
}
|
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 {
|
2011-12-12 05:35:53 +00:00
|
|
|
if (disable_blend)
|
|
|
|
qfglDisable (GL_BLEND);
|
2011-12-17 12:45:52 +00:00
|
|
|
for (i = 0; i < r_num_texture_chains; i++) {
|
|
|
|
tex = r_texture_chains[i];
|
2004-02-22 06:00:15 +00:00
|
|
|
if (!tex)
|
|
|
|
continue;
|
2011-12-12 05:35:53 +00:00
|
|
|
if (do_bind)
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-22 06:00:15 +00:00
|
|
|
|
2011-12-17 10:14:14 +00:00
|
|
|
for (s = tex->tex_chain; s; s = s->tex_chain) {
|
|
|
|
if (s->transform) {
|
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
qfglLoadMatrixf ((vec_t*)&s->transform[0]);//FIXME
|
2011-12-17 10:14:14 +00:00
|
|
|
}
|
|
|
|
R_RenderBrushPoly_1 (s->surface);
|
|
|
|
|
|
|
|
if (s->transform)
|
|
|
|
qfglPopMatrix ();
|
|
|
|
if (s->color && do_bind)
|
|
|
|
qfglColor3ubv (color_white);
|
|
|
|
}
|
2004-02-22 06:00:15 +00:00
|
|
|
}
|
2011-12-12 05:35:53 +00:00
|
|
|
if (disable_blend)
|
|
|
|
qfglEnable (GL_BLEND);
|
2004-02-14 05:10:29 +00:00
|
|
|
}
|
2011-12-12 05:35:53 +00:00
|
|
|
}
|
2004-02-22 06:00:15 +00:00
|
|
|
|
2011-12-12 05:35:53 +00:00
|
|
|
static void
|
|
|
|
clear_texture_chains (void)
|
|
|
|
{
|
|
|
|
int i;
|
2021-01-19 04:05:39 +00:00
|
|
|
gltex_t *tex;
|
2011-12-12 05:35:53 +00:00
|
|
|
|
2011-12-15 06:07:01 +00:00
|
|
|
for (i = 0; i < r_num_texture_chains; i++) {
|
|
|
|
tex = r_texture_chains[i];
|
2011-12-12 05:35:53 +00:00
|
|
|
if (!tex)
|
|
|
|
continue;
|
2011-12-17 10:14:14 +00:00
|
|
|
tex->tex_chain = NULL;
|
|
|
|
tex->tex_chain_tail = &tex->tex_chain;
|
2011-12-12 05:35:53 +00:00
|
|
|
}
|
2021-01-19 04:05:39 +00:00
|
|
|
tex = r_notexture_mip->render;
|
2011-12-17 10:14:14 +00:00
|
|
|
tex->tex_chain = NULL;
|
|
|
|
tex->tex_chain_tail = &tex->tex_chain;
|
2011-12-17 10:42:19 +00:00
|
|
|
release_instsurfs ();
|
2011-12-17 12:45:52 +00:00
|
|
|
|
2022-05-10 15:27:55 +00:00
|
|
|
gl_lightmap_polys = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 04:49:53 +00:00
|
|
|
static inline void
|
2021-07-22 06:39:28 +00:00
|
|
|
chain_surface (glbspctx_t *bctx, msurface_t *surf)
|
2011-12-15 04:49:53 +00:00
|
|
|
{
|
2011-12-17 12:45:52 +00:00
|
|
|
instsurf_t *sc;
|
|
|
|
|
2011-12-15 04:49:53 +00:00
|
|
|
if (surf->flags & SURF_DRAWTURB) {
|
2021-07-13 07:02:47 +00:00
|
|
|
sc = CHAIN_SURF_B2F (surf, waterchain);
|
2011-12-15 04:49:53 +00:00
|
|
|
} else if (surf->flags & SURF_DRAWSKY) {
|
2021-07-13 07:02:47 +00:00
|
|
|
sc = CHAIN_SURF_F2B (surf, sky_chain);
|
2011-12-15 04:49:53 +00:00
|
|
|
} else {
|
2021-01-19 04:05:39 +00:00
|
|
|
texture_t *tx;
|
|
|
|
gltex_t *tex;
|
2011-12-15 04:49:53 +00:00
|
|
|
|
|
|
|
if (!surf->texinfo->texture->anim_total)
|
2021-01-19 04:05:39 +00:00
|
|
|
tx = surf->texinfo->texture;
|
2011-12-15 04:49:53 +00:00
|
|
|
else
|
2022-10-25 10:36:09 +00:00
|
|
|
tx = R_TextureAnimation (bctx->animation->frame, surf);
|
2021-01-19 04:05:39 +00:00
|
|
|
tex = tx->render;
|
2021-07-13 07:02:47 +00:00
|
|
|
sc = CHAIN_SURF_F2B (surf, tex->tex_chain);
|
2011-12-17 12:45:52 +00:00
|
|
|
|
2021-07-22 06:39:28 +00:00
|
|
|
R_AddToLightmapChain (bctx, surf, sc);
|
2011-12-15 04:49:53 +00:00
|
|
|
}
|
2021-07-22 06:39:28 +00:00
|
|
|
sc->transform = bctx->transform;
|
|
|
|
sc->color = bctx->color;
|
2011-12-15 04:49:53 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
gl_R_DrawBrushModel (entity_t e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-23 21:14:43 +00:00
|
|
|
float dot, radius;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
transform_t transform = Entity_Transform (e);
|
2021-07-15 12:38:12 +00:00
|
|
|
msurface_t *surf;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool rotated;
|
2001-09-01 08:57:04 +00:00
|
|
|
vec3_t mins, maxs;
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t worldMatrix;
|
2022-10-25 03:53:30 +00:00
|
|
|
renderer_t *renderer = Ent_GetComponent (e.id, scene_renderer, e.reg);
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
model_t *model = renderer->model;
|
2021-07-22 06:39:28 +00:00
|
|
|
mod_brush_t *brush = &model->brush;
|
|
|
|
glbspctx_t bspctx = {
|
|
|
|
brush,
|
2022-10-25 03:53:30 +00:00
|
|
|
Ent_GetComponent (e.id, scene_animation, e.reg),
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
renderer->full_transform,
|
|
|
|
renderer->colormod,
|
2021-07-22 06:39:28 +00:00
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_GetWorldMatrix (transform, worldMatrix);
|
2021-03-09 14:52:40 +00:00
|
|
|
if (worldMatrix[0][0] != 1 || worldMatrix[1][1] != 1
|
|
|
|
|| worldMatrix[2][2] != 1) {
|
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
|
2022-03-30 15:07:20 +00:00
|
|
|
if (R_CullSphere (r_refdef.frustum, (vec_t*)&worldMatrix[3], radius)) {//FIXME
|
2002-08-23 21:14:43 +00:00
|
|
|
return;
|
2021-03-19 11:18:45 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
rotated = false;
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorAdd (worldMatrix[3], model->mins, mins);
|
|
|
|
VectorAdd (worldMatrix[3], 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
|
2022-03-19 03:33:12 +00:00
|
|
|
if (R_CullBox (r_refdef.frustum, mins, maxs))
|
2002-08-23 21:14:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
vec4f_t relviewpos = r_refdef.frame.position - worldMatrix[3];
|
2001-02-26 06:48:02 +00:00
|
|
|
if (rotated) {
|
2022-03-07 18:47:36 +00:00
|
|
|
vec4f_t temp = relviewpos;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-07 18:47:36 +00:00
|
|
|
relviewpos[0] = dotf (temp, worldMatrix[0])[0];
|
|
|
|
relviewpos[1] = dotf (temp, worldMatrix[1])[0];
|
|
|
|
relviewpos[2] = dotf (temp, worldMatrix[2])[0];
|
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
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (brush->firstmodelsurface != 0 && r_dlight_lightmap) {
|
2021-08-01 12:54:05 +00:00
|
|
|
for (unsigned k = 0; k < r_maxdlights; k++) {
|
2012-02-14 08:28:09 +00:00
|
|
|
if ((r_dlights[k].die < vr_data.realtime)
|
|
|
|
|| (!r_dlights[k].radius))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
vec4f_t lightorigin;
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_dlights[k].origin, worldMatrix[3], lightorigin);
|
2022-05-22 02:18:32 +00:00
|
|
|
lightorigin[3] = 1;
|
2021-02-01 10:31:11 +00:00
|
|
|
R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k,
|
2022-05-22 02:18:32 +00:00
|
|
|
brush->hulls[0].firstclipnode);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglPushMatrix ();
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
gl_R_RotateForEntity (Transform_GetWorldMatrixPtr (transform));
|
|
|
|
qfglGetFloatv (GL_MODELVIEW_MATRIX, (vec_t*)&renderer->full_transform[0]);
|
2011-12-17 12:45:52 +00:00
|
|
|
qfglPopMatrix ();
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
surf = &brush->surfaces[brush->firstmodelsurface];
|
2004-02-14 05:10:29 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// draw texture
|
2021-08-01 12:54:05 +00:00
|
|
|
for (unsigned i = 0; i < brush->nummodelsurfaces; i++, surf++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// find which side of the node we are on
|
2021-07-15 12:38:12 +00:00
|
|
|
plane_t *plane = surf->plane;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-07 18:47:36 +00:00
|
|
|
dot = DotProduct (relviewpos, plane->normal) - plane->dist;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// draw the polygon
|
2021-07-15 12:38:12 +00:00
|
|
|
if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
|
|
|
(!(surf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
|
2021-07-22 06:39:28 +00:00
|
|
|
chain_surface (&bspctx, surf);
|
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
|
[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
|
|
|
vec4f_t org = r_refdef.frame.position;
|
2004-02-15 03:46:55 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
return dotf (org, node->plane)[0] < 0;
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-23 04:46:55 +00:00
|
|
|
static inline void
|
2021-07-22 06:39:28 +00:00
|
|
|
visit_node (glbspctx_t *bctx, mnode_t *node, int side)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
|
|
|
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)) {
|
2022-05-22 07:31:24 +00:00
|
|
|
int surf_id = node->firstsurface;
|
|
|
|
surf = bctx->brush->surfaces + surf_id;
|
|
|
|
for (; c; c--, surf++, surf_id++) {
|
2023-06-28 14:44:38 +00:00
|
|
|
if (r_visstate.face_visframes[surf_id] != r_visstate.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
|
|
|
|
2021-07-22 06:39:28 +00:00
|
|
|
chain_surface (bctx, surf);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2022-05-22 02:18:32 +00:00
|
|
|
test_node (glbspctx_t *bctx, int node_id)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
2022-05-22 02:18:32 +00:00
|
|
|
if (node_id < 0)
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
2023-06-28 14:44:38 +00:00
|
|
|
if (r_visstate.node_visframes[node_id] != r_visstate.visframecount)
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
2022-05-22 02:18:32 +00:00
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2022-03-19 03:33:12 +00:00
|
|
|
if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3))
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-22 06:39:28 +00:00
|
|
|
R_VisitWorldNodes (glbspctx_t *bctx)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
2012-11-28 12:29:03 +00:00
|
|
|
typedef struct {
|
2022-05-22 02:18:32 +00:00
|
|
|
int node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
int side;
|
2012-11-28 12:29:03 +00:00
|
|
|
} rstack_t;
|
2021-07-22 06:39:28 +00:00
|
|
|
mod_brush_t *brush = bctx->brush;
|
2012-11-28 12:29:03 +00:00
|
|
|
rstack_t *node_ptr;
|
|
|
|
rstack_t *node_stack;
|
2022-05-22 02:18:32 +00:00
|
|
|
int node_id;
|
|
|
|
int front;
|
2004-02-15 03:46:55 +00:00
|
|
|
int side;
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = 0;
|
2012-11-28 12:29:03 +00:00
|
|
|
// +2 for paranoia
|
2021-02-01 10:31:11 +00:00
|
|
|
node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
|
2004-02-15 03:46:55 +00:00
|
|
|
node_ptr = node_stack;
|
|
|
|
|
|
|
|
while (1) {
|
2022-05-22 02:18:32 +00:00
|
|
|
while (test_node (bctx, node_id)) {
|
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
side = get_side (node);
|
|
|
|
front = node->children[side];
|
2022-05-22 02:18:32 +00:00
|
|
|
if (test_node (bctx, front)) {
|
|
|
|
node_ptr->node_id = node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
node_ptr->side = side;
|
|
|
|
node_ptr++;
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = front;
|
2004-02-15 03:46:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-22 02:18:32 +00:00
|
|
|
if (front < 0) {
|
|
|
|
mleaf_t *leaf = bctx->brush->leafs + ~front;
|
|
|
|
if (leaf->contents != CONTENTS_SOLID) {
|
|
|
|
visit_leaf (leaf);
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 06:39:28 +00:00
|
|
|
visit_node (bctx, node, side);
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node->children[side ^ 1];
|
|
|
|
}
|
|
|
|
if (node_id < 0) {
|
|
|
|
mleaf_t *leaf = bctx->brush->leafs + ~node_id;
|
|
|
|
if (leaf->contents != CONTENTS_SOLID) {
|
|
|
|
visit_leaf (leaf);
|
|
|
|
}
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
if (node_ptr != node_stack) {
|
|
|
|
node_ptr--;
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node_ptr->node_id;
|
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
side = node_ptr->side;
|
2021-07-22 06:39:28 +00:00
|
|
|
visit_node (bctx, node, side);
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node->children[side ^ 1];
|
2004-02-15 03:46:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawWorld (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
animation_t animation = {};
|
2021-07-22 06:39:28 +00:00
|
|
|
glbspctx_t bctx = { };
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-10-03 02:51:30 +00:00
|
|
|
sky_chain = 0;
|
2001-11-05 06:20:35 +00:00
|
|
|
sky_chain_tail = &sky_chain;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (!gl_sky_clip) {
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawSky ();
|
2001-05-13 00:28:50 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
bctx.brush = &r_refdef.worldmodel->brush;
|
|
|
|
bctx.animation = &animation;
|
2021-07-22 06:39:28 +00:00
|
|
|
|
|
|
|
R_VisitWorldNodes (&bctx);
|
2022-03-06 23:40:39 +00:00
|
|
|
|
|
|
|
gl_R_DrawSkyChain (sky_chain);
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (r_drawentities) {
|
2022-03-04 16:48:10 +00:00
|
|
|
for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) { \
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
entity_t ent = r_ent_queue->ent_queues[mod_brush].a[i]; \
|
2021-07-22 06:39:28 +00:00
|
|
|
gl_R_DrawBrushModel (ent);
|
2011-12-17 12:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-05-10 15:27:55 +00:00
|
|
|
gl_R_FlushLightmaps ();
|
2022-05-10 08:04:57 +00:00
|
|
|
|
2022-03-07 17:10:47 +00:00
|
|
|
if (!Fog_GetDensity ()
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
|| (gl_fb_bmodels && gl_mtex_fullbright)
|
2011-12-12 05:35:53 +00:00
|
|
|
|| gl_mtex_active_tmus > 1) {
|
|
|
|
// we have enough active TMUs to render everything in one go
|
|
|
|
// or we're not doing fog
|
|
|
|
DrawTextureChains (1, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-12-16 00:21:39 +00:00
|
|
|
if (gl_mtex_active_tmus <= 1)
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_BlendLightmaps ();
|
2011-12-16 00:21:39 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (gl_fb_bmodels && !gl_mtex_fullbright)
|
2011-12-12 05:35:53 +00:00
|
|
|
R_RenderFullbrights ();
|
|
|
|
} else {
|
|
|
|
if (gl_mtex_active_tmus > 1) {
|
|
|
|
// textures and lightmaps in one pass
|
|
|
|
// black fog
|
|
|
|
// no blending
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_StartAdditive ();
|
2011-12-12 05:35:53 +00:00
|
|
|
DrawTextureChains (1, 1);
|
|
|
|
// buf = fTL + (1-f)0
|
|
|
|
// = fTL
|
|
|
|
} else {
|
|
|
|
// texture pass + lightmap pass
|
|
|
|
// no fog
|
|
|
|
// no blending
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_DisableGFog ();
|
2011-12-12 05:35:53 +00:00
|
|
|
DrawTextureChains (1, 1);
|
|
|
|
// buf = T
|
|
|
|
// black fog
|
|
|
|
// blend: buf = zero, src (non-overbright)
|
|
|
|
// FIXME overbright broken?
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_EnableGFog ();
|
|
|
|
gl_Fog_StartAdditive ();
|
|
|
|
gl_R_BlendLightmaps (); //leaves blending as As, 1-As
|
2011-12-12 05:35:53 +00:00
|
|
|
// buf = I*0 + buf*I
|
|
|
|
// = T*C
|
|
|
|
// = T(fL + (1-f)0)
|
|
|
|
// = fTL
|
|
|
|
}
|
|
|
|
// fullbright pass
|
|
|
|
// fog is still black
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RenderFullbrights ();
|
2011-12-12 05:35:53 +00:00
|
|
|
// buf = aI + (1-a)buf
|
|
|
|
// = aC + (1-a)fTL
|
|
|
|
// = a(fG + (1-f)0) + (1-a)fTL
|
|
|
|
// = afG + (1-a)fTL
|
|
|
|
// = f((1-a)TL + aG)
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_StopAdditive (); // use fog color
|
2011-12-12 05:35:53 +00:00
|
|
|
qfglDepthMask (GL_FALSE); // don't write Z
|
|
|
|
qfglBlendFunc (GL_ONE, GL_ONE);
|
|
|
|
// draw black polys
|
|
|
|
qfglColor4f (0, 0, 0, 1);
|
|
|
|
DrawTextureChains (0, 0);
|
|
|
|
// buf = I + buf
|
|
|
|
// = C + f((1-a)TL + aG)
|
|
|
|
// = (f0 + (1-f)F) + f((1-a)TL + aG)
|
|
|
|
// = (1-f)F + f((1-a)TL + aG)
|
|
|
|
// = f((1-a)TL + aG) + (1-f)F
|
|
|
|
// restore state
|
|
|
|
qfglColor4ubv (color_white);
|
|
|
|
qfglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_texture_chains ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
model_t *gl_currentmodel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-07-23 19:57:47 +00:00
|
|
|
void
|
2022-03-17 04:09:20 +00:00
|
|
|
GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf)
|
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;
|
2022-03-17 04:09:20 +00:00
|
|
|
mvertex_t *vertex_base = brush->vertexes;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
// reconstruct the polygon
|
2021-02-01 10:31:11 +00:00
|
|
|
pedges = gl_currentmodel->brush.edges;
|
2021-07-15 12:38:12 +00:00
|
|
|
lnumverts = surf->numedges;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// draw texture
|
2021-07-28 06:01:45 +00:00
|
|
|
poly = Hunk_Alloc (0, sizeof (glpoly_t) + (lnumverts - 4) *
|
2001-05-13 00:28:50 +00:00
|
|
|
VERTEXSIZE * sizeof (float));
|
2021-07-15 12:38:12 +00:00
|
|
|
poly->next = surf->polys;
|
|
|
|
poly->flags = surf->flags;
|
|
|
|
surf->polys = poly;
|
2001-02-19 21:15:25 +00:00
|
|
|
poly->numverts = lnumverts;
|
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
mtexinfo_t *texinfo = surf->texinfo;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnumverts; i++) {
|
2021-07-15 12:38:12 +00:00
|
|
|
lindex = gl_currentmodel->brush.surfedges[surf->firstedge + i];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lindex > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &pedges[lindex];
|
2022-03-17 04:09:20 +00:00
|
|
|
vec = vertex_base[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];
|
2022-03-17 04:09:20 +00:00
|
|
|
vec = vertex_base[r_pedge->v[1]].position;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2021-07-15 12:38:12 +00:00
|
|
|
s = DotProduct (vec, texinfo->vecs[0]) + texinfo->vecs[0][3];
|
|
|
|
s /= texinfo->texture->width;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-15 12:38:12 +00:00
|
|
|
t = DotProduct (vec, texinfo->vecs[1]) + texinfo->vecs[1][3];
|
|
|
|
t /= texinfo->texture->height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (vec, poly->verts[i]);
|
|
|
|
poly->verts[i][3] = s;
|
|
|
|
poly->verts[i][4] = t;
|
|
|
|
|
|
|
|
// lightmap texture coordinates
|
2021-07-15 12:38:12 +00:00
|
|
|
s = DotProduct (vec, texinfo->vecs[0]) + texinfo->vecs[0][3];
|
|
|
|
t = DotProduct (vec, texinfo->vecs[1]) + texinfo->vecs[1][3];
|
2022-05-10 15:27:55 +00:00
|
|
|
s -= surf->texturemins[0];
|
2021-07-15 12:38:12 +00:00
|
|
|
t -= surf->texturemins[1];
|
2022-05-10 15:27:55 +00:00
|
|
|
s += surf->lightpic->rect->x * 16 + 8;
|
|
|
|
t += surf->lightpic->rect->y * 16 + 8;
|
|
|
|
s /= 16;
|
|
|
|
t /= 16;
|
|
|
|
poly->verts[i][5] = s * surf->lightpic->size;
|
|
|
|
poly->verts[i][6] = t * surf->lightpic->size;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove co-linear points - Ed
|
2022-05-22 14:38:18 +00:00
|
|
|
if (!gl_keeptjunctions) {
|
2001-02-26 06:48:02 +00:00
|
|
|
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;
|
|
|
|
// retry next vertex next time, which is now current vertex
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
poly->numverts = lnumverts;
|
|
|
|
}
|