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
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
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
|
|
|
|
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"
|
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"
|
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"
|
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 };
|
|
|
|
proj[2] = (vec4f_t) { 0, 0, (fard + neard) / (neard - fard), -1 };
|
|
|
|
proj[3] = (vec4f_t) { 0, 0, (2 * fard * neard) / (neard - fard), 0 };
|
2011-12-30 12:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_SetupFrame (void)
|
2011-12-30 12:10:24 +00:00
|
|
|
{
|
2012-01-05 13:37:02 +00:00
|
|
|
R_AnimateLight ();
|
2011-12-30 12:10:24 +00:00
|
|
|
R_ClearEnts ();
|
|
|
|
r_framecount++;
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (r_refdef.viewposition, r_origin);
|
|
|
|
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn);
|
|
|
|
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright);
|
|
|
|
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup);
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
|
2012-07-03 06:57:33 +00:00
|
|
|
R_SetFrustum ();
|
2012-01-03 14:20:01 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.renderer.model);
|
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 = {
|
|
|
|
{ 0, 0, -1, 0},
|
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 0, 1},
|
2011-12-30 12:10:24 +00:00
|
|
|
};
|
2021-03-09 14:52:40 +00:00
|
|
|
vec4f_t offset = { 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
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
mat4fquat (glsl_view, qconjf (r_refdef.viewrotation));
|
2021-03-09 14:52:40 +00:00
|
|
|
mmulf (glsl_view, z_up, glsl_view);
|
2021-03-19 11:18:45 +00:00
|
|
|
offset = -r_refdef.viewposition;
|
|
|
|
offset[3] = 1;
|
2021-03-09 14:52:40 +00:00
|
|
|
glsl_view[3] = mvmulf (glsl_view, offset);
|
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
|
|
|
|
|
|
|
static void
|
|
|
|
R_RenderEntities (void)
|
|
|
|
{
|
|
|
|
entity_t *ent;
|
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; \
|
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) { \
|
2021-03-09 14:52:40 +00:00
|
|
|
if (ent->renderer.model->type != mod_##type_name) \
|
2012-07-03 09:20:32 +00:00
|
|
|
continue; \
|
|
|
|
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
|
|
|
{
|
2012-02-01 21:07:39 +00:00
|
|
|
double t[10] = {};
|
2012-01-28 05:10:47 +00:00
|
|
|
int speeds = r_speeds->int_val;
|
|
|
|
|
2021-12-02 09:30:57 +00:00
|
|
|
if (!r_worldentity.renderer.model) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[0] = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_SetupFrame ();
|
2011-12-30 12:10:24 +00:00
|
|
|
R_SetupView ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[1] = Sys_DoubleTime ();
|
2012-01-03 14:20:01 +00:00
|
|
|
R_MarkLeaves ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[2] = Sys_DoubleTime ();
|
2012-01-05 13:37:02 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[3] = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawWorld ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[4] = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawSky ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[5] = Sys_DoubleTime ();
|
2011-12-30 12:11:59 +00:00
|
|
|
R_RenderEntities ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[6] = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawWaterSurfaces ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[7] = Sys_DoubleTime ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_DrawParticles ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[8] = Sys_DoubleTime ();
|
2012-01-14 11:07:43 +00:00
|
|
|
R_DrawViewModel ();
|
2012-01-28 05:10:47 +00:00
|
|
|
if (speeds)
|
|
|
|
t[9] = Sys_DoubleTime ();
|
|
|
|
if (speeds) {
|
|
|
|
Sys_Printf ("frame: %g, setup: %g, mark: %g, pushdl: %g, world: %g,"
|
|
|
|
" sky: %g, ents: %g, water: %g, part: %g, view: %g\n",
|
|
|
|
(t[9] - t[0]) * 1000, (t[1] - t[0]) * 1000,
|
|
|
|
(t[2] - t[1]) * 1000, (t[3] - t[2]) * 1000,
|
|
|
|
(t[4] - t[3]) * 1000, (t[5] - t[4]) * 1000,
|
|
|
|
(t[6] - t[5]) * 1000, (t[7] - t[6]) * 1000,
|
|
|
|
(t[8] - t[7]) * 1000, (t[9] - t[8]) * 1000);
|
|
|
|
}
|
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_Init (void)
|
2011-12-23 03:19:50 +00:00
|
|
|
{
|
2012-09-12 00:54:24 +00:00
|
|
|
Cmd_AddCommand ("pointfile", glsl_R_ReadPointFile_f,
|
2013-02-18 04:57:45 +00:00
|
|
|
"Load a pointfile to determine map leaks.");
|
|
|
|
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 ();
|
|
|
|
glsl_Fog_Init ();
|
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
|
|
|
|
|
2011-12-25 03:57:23 +00:00
|
|
|
memset (&r_worldentity, 0, sizeof (r_worldentity));
|
2021-03-09 14:52:40 +00:00
|
|
|
r_worldentity.renderer.model = worldmodel;
|
2011-12-25 03:57:23 +00:00
|
|
|
|
2012-01-29 07:09:35 +00:00
|
|
|
// Force a vis update
|
|
|
|
r_viewleaf = NULL;
|
|
|
|
R_MarkLeaves ();
|
|
|
|
|
2011-12-25 03:57:23 +00:00
|
|
|
R_FreeAllEntities ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_ClearParticles ();
|
|
|
|
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
|
|
|
{
|
2021-12-02 09:30:57 +00:00
|
|
|
r_worldentity.renderer.model = 0;
|
2011-12-23 03:52:55 +00:00
|
|
|
R_ClearEfrags ();
|
|
|
|
R_ClearDlights ();
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_R_ClearParticles ();
|
2011-12-23 03:52:55 +00:00
|
|
|
}
|
2013-02-18 04:57:45 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
glsl_R_TimeRefresh_f (void)
|
|
|
|
{
|
2021-03-19 11:18:45 +00:00
|
|
|
/* FIXME update for simd
|
2013-02-18 04:57:45 +00:00
|
|
|
double start, stop, time;
|
|
|
|
int i;
|
|
|
|
|
2019-07-08 16:00:47 +00:00
|
|
|
glsl_ctx->end_rendering ();
|
2013-02-18 04:57:45 +00:00
|
|
|
|
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
r_refdef.viewangles[1] = i * (360.0 / 128.0);
|
|
|
|
glsl_R_RenderView ();
|
2019-07-08 16:00:47 +00:00
|
|
|
glsl_ctx->end_rendering ();
|
2013-02-18 04:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop = Sys_DoubleTime ();
|
|
|
|
time = stop - start;
|
|
|
|
Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time);
|
2021-03-19 11:18:45 +00:00
|
|
|
*/
|
2013-02-18 04:57:45 +00:00
|
|
|
}
|