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"
|
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
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2021-04-01 10:17:19 +00:00
|
|
|
glsl_R_ViewChanged (void)
|
2011-12-23 03:19:50 +00:00
|
|
|
{
|
2021-04-01 10:17:19 +00:00
|
|
|
float aspect = (float) r_refdef.vrect.width / r_refdef.vrect.height;
|
|
|
|
float f = 1 / tan (r_refdef.fov_y * M_PI / 360);
|
|
|
|
float neard, fard;
|
2021-03-09 14:52:40 +00:00
|
|
|
vec4f_t *proj = glsl_projection;
|
2011-12-30 12:10:24 +00:00
|
|
|
|
|
|
|
neard = r_nearclip->value;
|
|
|
|
fard = r_farclip->value;
|
|
|
|
|
2021-04-01 10:17:19 +00:00
|
|
|
// NOTE columns!
|
|
|
|
proj[0] = (vec4f_t) { f / aspect, 0, 0, 0 };
|
|
|
|
proj[1] = (vec4f_t) { 0, f, 0, 0 };
|
2022-02-25 01:50:53 +00:00
|
|
|
proj[2] = (vec4f_t) { 0, 0, (fard) / (fard - neard), 1 };
|
|
|
|
proj[3] = (vec4f_t) { 0, 0, (fard * neard) / (neard - fard), 0 };
|
|
|
|
|
|
|
|
// convert 0..1 depth buffer range to -1..1
|
|
|
|
static mat4f_t depth_range = {
|
|
|
|
{ 1, 0, 0, 0},
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 2, 0},
|
|
|
|
{ 0, 0,-1, 1},
|
|
|
|
};
|
|
|
|
mmulf (proj, depth_range, proj);
|
2011-12-30 12:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_SetupView (void)
|
|
|
|
{
|
|
|
|
float x, y, w, h;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
x = r_refdef.vrect.x;
|
|
|
|
y = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height));
|
|
|
|
w = r_refdef.vrect.width;
|
|
|
|
h = r_refdef.vrect.height;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglViewport (x, y, w, h);
|
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
|
|
|
|
|
|
|
if (!r_drawentities->int_val)
|
|
|
|
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++) { \
|
2022-03-17 08:50:38 +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)
|
|
|
|
{
|
2021-07-22 06:39:28 +00:00
|
|
|
entity_t *ent = vr_data.view_model;
|
2012-02-14 08:28:09 +00:00
|
|
|
if (vr_data.inhibit_viewmodel
|
2012-01-14 11:07:43 +00:00
|
|
|
|| !r_drawviewmodel->int_val
|
|
|
|
|| !r_drawentities->int_val
|
2021-07-22 06:39:28 +00:00
|
|
|
|| !ent->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;
|
|
|
|
}
|
|
|
|
|
2011-12-30 12:10:24 +00:00
|
|
|
R_SetupView ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawWorld ();
|
|
|
|
glsl_R_DrawSky ();
|
2022-03-02 07:29:40 +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 ();
|
|
|
|
glsl_R_Particles_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-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
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
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-03-14 06:27:43 +00:00
|
|
|
r_refdef.worldmodel = worldmodel;
|
2011-12-25 03:57:23 +00:00
|
|
|
|
2012-01-29 07:09:35 +00:00
|
|
|
// Force a vis update
|
2022-03-14 06:27:43 +00:00
|
|
|
r_refdef.viewleaf = NULL;
|
2012-01-29 07:09:35 +00:00
|
|
|
R_MarkLeaves ();
|
|
|
|
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_RegisterTextures (models, num_models);
|
|
|
|
glsl_R_BuildLightmaps (models, num_models);
|
|
|
|
glsl_R_BuildDisplayLists (models, num_models);
|
2011-12-23 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2021-07-11 01:59:27 +00:00
|
|
|
glsl_R_LineGraph (int x, int y, int *h_vals, int count, int height)
|
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_ClearEfrags ();
|
|
|
|
R_ClearDlights ();
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2011-12-23 03:52:55 +00:00
|
|
|
}
|