2011-12-23 03:19:50 +00:00
|
|
|
/*
|
|
|
|
glsl_main.c
|
|
|
|
|
|
|
|
GLSL rendering
|
|
|
|
|
|
|
|
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2011/12/23
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-12-25 03:57:23 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
|
|
|
|
2012-09-12 00:54:24 +00:00
|
|
|
#include "QF/cmd.h"
|
2011-12-23 03:19:50 +00:00
|
|
|
#include "QF/cvar.h"
|
2011-12-25 07:41:14 +00:00
|
|
|
#include "QF/image.h"
|
2011-12-23 03:19:50 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
2011-12-30 12:10:24 +00:00
|
|
|
#include "QF/sys.h"
|
2011-12-23 03:19:50 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2012-01-03 09:08:01 +00:00
|
|
|
#include "QF/GLSL/defines.h"
|
2011-12-30 12:10:24 +00:00
|
|
|
#include "QF/GLSL/funcs.h"
|
2012-01-02 02:18:34 +00:00
|
|
|
#include "QF/GLSL/qf_alias.h"
|
2012-01-08 01:29:38 +00:00
|
|
|
#include "QF/GLSL/qf_bsp.h"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GLSL/qf_draw.h"
|
2022-03-25 03:22:16 +00:00
|
|
|
#include "QF/GLSL/qf_fisheye.h"
|
2012-05-11 03:49:14 +00:00
|
|
|
#include "QF/GLSL/qf_iqm.h"
|
2012-01-07 06:34:31 +00:00
|
|
|
#include "QF/GLSL/qf_lightmap.h"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GLSL/qf_main.h"
|
|
|
|
#include "QF/GLSL/qf_particles.h"
|
2021-07-22 06:39:28 +00:00
|
|
|
#include "QF/GLSL/qf_sprite.h"
|
2011-12-26 07:08:55 +00:00
|
|
|
#include "QF/GLSL/qf_textures.h"
|
2022-03-24 16:24:38 +00:00
|
|
|
#include "QF/GLSL/qf_warp.h"
|
2011-12-23 03:19:50 +00:00
|
|
|
|
2012-04-10 04:27:53 +00:00
|
|
|
#include "mod_internal.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2019-07-08 16:00:47 +00:00
|
|
|
#include "vid_gl.h"
|
2011-12-23 03:19:50 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t glsl_projection;
|
|
|
|
mat4f_t glsl_view;
|
2011-12-23 03:19:50 +00:00
|
|
|
|
2011-12-30 12:10:24 +00:00
|
|
|
static void
|
|
|
|
R_SetupView (void)
|
|
|
|
{
|
2021-03-09 14:52:40 +00:00
|
|
|
static mat4f_t z_up = {
|
2022-02-25 01:50:53 +00:00
|
|
|
{ 0, 0, 1, 0},
|
2021-03-09 14:52:40 +00:00
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 0, 1},
|
2011-12-30 12:10:24 +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
|
|
|
mmulf (glsl_view, z_up, r_refdef.camera_inverse);
|
2012-01-03 09:08:01 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglEnable (GL_CULL_FACE);
|
|
|
|
qfeglEnable (GL_DEPTH_TEST);
|
2011-12-30 12:10:24 +00:00
|
|
|
}
|
2011-12-30 12:11:59 +00:00
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
void
|
|
|
|
glsl_R_RenderEntities (entqueue_t *queue)
|
2011-12-30 12:11:59 +00:00
|
|
|
{
|
2012-07-03 09:20:32 +00:00
|
|
|
int begun;
|
2011-12-30 12:11:59 +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 (!r_drawentities)
|
2011-12-30 12:11:59 +00:00
|
|
|
return;
|
2012-07-03 09:20:32 +00:00
|
|
|
#define RE_LOOP(type_name, Type) \
|
|
|
|
do { \
|
|
|
|
begun = 0; \
|
2022-03-17 08:50:38 +00:00
|
|
|
for (size_t i = 0; i < queue->ent_queues[mod_##type_name].size; \
|
2022-03-04 16:48:10 +00:00
|
|
|
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 = queue->ent_queues[mod_##type_name].a[i]; \
|
2012-07-03 09:20:32 +00:00
|
|
|
if (!begun) { \
|
|
|
|
glsl_R_##Type##Begin (); \
|
|
|
|
begun = 1; \
|
|
|
|
} \
|
2021-07-22 06:39:28 +00:00
|
|
|
glsl_R_Draw##Type (ent); \
|
2012-07-03 09:20:32 +00:00
|
|
|
} \
|
|
|
|
if (begun) \
|
|
|
|
glsl_R_##Type##End (); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
RE_LOOP (alias, Alias);
|
|
|
|
RE_LOOP (iqm, IQM);
|
|
|
|
RE_LOOP (sprite, Sprite);
|
2011-12-23 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-14 11:07:43 +00:00
|
|
|
static void
|
|
|
|
R_DrawViewModel (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
|
|
|
entity_t ent = vr_data.view_model;
|
2022-10-27 03:53:01 +00:00
|
|
|
if (!Entity_Valid (ent)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-25 03:53:30 +00:00
|
|
|
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
|
2012-02-14 08:28:09 +00:00
|
|
|
if (vr_data.inhibit_viewmodel
|
[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
|
|
|
|| !r_drawviewmodel
|
|
|
|
|| !r_drawentities
|
[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->model)
|
2012-01-14 11:07:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// hack the depth range to prevent view model from poking into walls
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthRangef (0, 0.3);
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_AliasBegin ();
|
2021-07-22 06:39:28 +00:00
|
|
|
glsl_R_DrawAlias (ent);
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_AliasEnd ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDepthRangef (0, 1);
|
2012-01-14 11:07:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_RenderView (void)
|
2011-12-23 03:19:50 +00:00
|
|
|
{
|
2022-03-14 06:27:43 +00:00
|
|
|
if (!r_refdef.worldmodel) {
|
2021-12-02 09:30:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-30 05:55:32 +00:00
|
|
|
memcpy (glsl_projection, glsl_ctx->projection, sizeof (mat4f_t));
|
|
|
|
|
2011-12-30 12:10:24 +00:00
|
|
|
R_SetupView ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawWorld ();
|
|
|
|
glsl_R_DrawSky ();
|
[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
|
|
|
if (Entity_Valid (vr_data.view_model)) {
|
2022-04-25 22:22:45 +00:00
|
|
|
R_DrawViewModel ();
|
|
|
|
}
|
2011-12-23 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 05:31:23 +00:00
|
|
|
static void
|
|
|
|
glsl_R_TimeRefresh_f (void)
|
|
|
|
{
|
|
|
|
/* FIXME update for simd
|
|
|
|
double start, stop, time;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
glsl_ctx->end_rendering ();
|
|
|
|
|
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
r_refdef.viewangles[1] = i * (360.0 / 128.0);
|
|
|
|
glsl_R_RenderView ();
|
|
|
|
glsl_ctx->end_rendering ();
|
|
|
|
}
|
|
|
|
|
|
|
|
stop = Sys_DoubleTime ();
|
|
|
|
time = stop - start;
|
|
|
|
Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_Init (void)
|
2011-12-23 03:19:50 +00:00
|
|
|
{
|
2013-02-18 04:57:45 +00:00
|
|
|
Cmd_AddCommand ("timerefresh", glsl_R_TimeRefresh_f,
|
|
|
|
"Test the current refresh rate for the current location.");
|
2012-04-10 04:27:53 +00:00
|
|
|
R_Init_Cvars ();
|
2013-02-19 05:45:50 +00:00
|
|
|
glsl_Draw_Init ();
|
2012-02-01 12:52:47 +00:00
|
|
|
SCR_Init ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_InitBsp ();
|
|
|
|
glsl_R_InitAlias ();
|
2012-05-11 03:49:14 +00:00
|
|
|
glsl_R_InitIQM ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_InitSprites ();
|
|
|
|
glsl_R_InitParticles ();
|
2022-03-25 03:22:16 +00:00
|
|
|
glsl_InitFisheye ();
|
2022-03-24 16:24:38 +00:00
|
|
|
glsl_InitWarp ();
|
2012-04-10 04:27:53 +00:00
|
|
|
Skin_Init ();
|
2011-12-23 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2023-03-05 07:56:09 +00:00
|
|
|
void
|
|
|
|
glsl_R_Shutdown (void)
|
|
|
|
{
|
|
|
|
Skin_Shutdown();
|
|
|
|
|
|
|
|
glsl_R_ShutdownParticles ();
|
|
|
|
glsl_Lightmap_Shutdown ();
|
|
|
|
glsl_R_ShutdownBsp ();
|
|
|
|
SCR_Shutdown ();
|
|
|
|
glsl_Draw_Shutdown ();
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2022-05-05 05:41:46 +00:00
|
|
|
glsl_R_NewScene (scene_t *scene)
|
2011-12-23 03:19:50 +00:00
|
|
|
{
|
2012-01-08 16:26:16 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
d_lightstylevalue[i] = 264; // normal light value
|
|
|
|
|
2022-05-05 05:41:46 +00:00
|
|
|
r_refdef.worldmodel = scene->worldmodel;
|
2011-12-25 03:57:23 +00:00
|
|
|
|
2012-01-29 07:09:35 +00:00
|
|
|
// Force a vis update
|
2022-05-22 07:31:24 +00:00
|
|
|
R_MarkLeaves (0, 0, 0, 0);
|
2012-01-29 07:09:35 +00:00
|
|
|
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2022-05-05 05:41:46 +00:00
|
|
|
glsl_R_RegisterTextures (scene->models, scene->num_models);
|
|
|
|
glsl_R_BuildLightmaps (scene->models, scene->num_models);
|
|
|
|
glsl_R_BuildDisplayLists (scene->models, scene->num_models);
|
2011-12-23 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_ClearState (void)
|
2011-12-23 03:52:55 +00:00
|
|
|
{
|
2022-03-14 06:27:43 +00:00
|
|
|
r_refdef.worldmodel = 0;
|
2011-12-23 03:52:55 +00:00
|
|
|
R_ClearDlights ();
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2011-12-23 03:52:55 +00:00
|
|
|
}
|