2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_rmain.c
|
|
|
|
|
2003-05-09 01:41:56 +00:00
|
|
|
(no description)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2004-05-07 03:54:35 +00:00
|
|
|
#include "QF/draw.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-05-21 00:22:35 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/skin.h"
|
|
|
|
#include "QF/sound.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/vid.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"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GL/qf_alias.h"
|
2012-02-22 12:53:17 +00:00
|
|
|
#include "QF/GL/qf_draw.h"
|
2012-05-17 06:58:29 +00:00
|
|
|
#include "QF/GL/qf_iqm.h"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GL/qf_particles.h"
|
2001-08-26 17:13:33 +00:00
|
|
|
#include "QF/GL/qf_rlight.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/GL/qf_rmain.h"
|
2001-08-26 17:13:33 +00:00
|
|
|
#include "QF/GL/qf_rsurf.h"
|
2022-03-14 05:31:23 +00:00
|
|
|
#include "QF/GL/qf_sprite.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_vid.h"
|
|
|
|
|
2001-08-02 02:18:04 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2003-03-20 19:58:18 +00:00
|
|
|
#include "varrays.h"
|
2022-03-07 17:10:47 +00:00
|
|
|
#include "vid_gl.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
float gl_r_world_matrix[16];
|
2021-03-19 11:18:45 +00:00
|
|
|
//FIXME static float r_base_world_matrix[16];
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
//vec3_t gl_shadecolor; // Ender (Extend) Colormod
|
|
|
|
float gl_modelalpha; // Ender (Extend) Alpha
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
void
|
2001-05-14 06:47:38 +00:00
|
|
|
glrmain_init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-10-02 00:01:05 +00:00
|
|
|
gldepthmin = 0;
|
|
|
|
gldepthmax = 1;
|
|
|
|
qfglDepthFunc (GL_LEQUAL);
|
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2004-03-07 23:51:29 +00:00
|
|
|
if (gl_multitexture)
|
|
|
|
gl_multitexture_f (gl_multitexture);
|
|
|
|
if (gl_overbright)
|
|
|
|
gl_overbright_f (gl_overbright);
|
2001-05-14 06:47:38 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_RotateForEntity (entity_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t mat;
|
|
|
|
Transform_GetWorldMatrix (e->transform, mat);
|
|
|
|
qfglMultMatrixf (&mat[0][0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-05-08 22:16:30 +00:00
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
void
|
|
|
|
gl_R_RenderEntities (entqueue_t *queue)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-04-21 18:26:21 +00:00
|
|
|
if (!r_drawentities->int_val)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// LordHavoc: split into 3 loops to simplify state changes
|
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) {
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
2001-12-19 18:32:26 +00:00
|
|
|
if (gl_affinemodels->int_val)
|
|
|
|
qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
2012-02-22 02:09:09 +00:00
|
|
|
if (gl_tess)
|
2004-01-26 00:13:47 +00:00
|
|
|
qfglEnable (GL_PN_TRIANGLES_ATI);
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglEnable (GL_CULL_FACE);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-05-02 21:21:00 +00:00
|
|
|
if (gl_vector_light->int_val) {
|
|
|
|
qfglEnable (GL_LIGHTING);
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
2012-02-22 02:09:09 +00:00
|
|
|
} else if (gl_tess) {
|
2004-05-02 21:21:00 +00:00
|
|
|
qfglEnable (GL_NORMALIZE);
|
|
|
|
}
|
2012-05-17 06:58:29 +00:00
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
for (size_t i = 0; i < queue->ent_queues[mod_alias].size; i++) { \
|
|
|
|
entity_t *ent = queue->ent_queues[mod_alias].a[i]; \
|
2021-07-22 06:39:28 +00:00
|
|
|
gl_R_DrawAliasModel (ent);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2004-02-21 05:36:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
qfglDisable (GL_NORMALIZE);
|
|
|
|
qfglDisable (GL_LIGHTING);
|
2004-05-02 21:21:00 +00:00
|
|
|
|
2012-02-22 02:09:09 +00:00
|
|
|
if (gl_tess)
|
2004-01-26 00:13:47 +00:00
|
|
|
qfglDisable (GL_PN_TRIANGLES_ATI);
|
2001-12-19 18:32:26 +00:00
|
|
|
if (gl_affinemodels->int_val)
|
|
|
|
qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);
|
2004-02-24 20:50:55 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) { // FIXME: Ugly, but faster than cleaning
|
|
|
|
// up in every R_DrawAliasModel()!
|
2004-02-21 05:36:19 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2004-03-07 23:51:29 +00:00
|
|
|
if (gl_combine_capable && gl_overbright->int_val) {
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
|
2012-02-22 02:09:09 +00:00
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, gl_rgb_scale);
|
2004-02-21 05:36:19 +00:00
|
|
|
} else {
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
for (size_t i = 0; i < queue->ent_queues[mod_iqm].size; i++) { \
|
|
|
|
entity_t *ent = queue->ent_queues[mod_iqm].a[i]; \
|
2021-07-22 06:39:28 +00:00
|
|
|
gl_R_DrawIQMModel (ent);
|
2012-05-17 06:58:29 +00:00
|
|
|
}
|
|
|
|
qfglColor3ubv (color_white);
|
|
|
|
|
|
|
|
qfglDisable (GL_CULL_FACE);
|
2001-10-02 01:48:51 +00:00
|
|
|
qfglEnable (GL_ALPHA_TEST);
|
2003-03-20 19:58:18 +00:00
|
|
|
if (gl_va_capable)
|
2012-02-17 09:33:07 +00:00
|
|
|
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, gl_spriteVertexArray);
|
2022-03-17 08:50:38 +00:00
|
|
|
for (size_t i = 0; i < queue->ent_queues[mod_sprite].size; i++) { \
|
|
|
|
entity_t *ent = queue->ent_queues[mod_sprite].a[i]; \
|
2022-03-14 05:31:23 +00:00
|
|
|
gl_R_DrawSpriteModel (ent);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-10-02 01:48:51 +00:00
|
|
|
qfglDisable (GL_ALPHA_TEST);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_DrawViewModel (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
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
|
2001-05-21 00:22:35 +00:00
|
|
|
|| !r_drawviewmodel->int_val
|
2001-05-15 03:27:55 +00:00
|
|
|
|| !r_drawentities->int_val
|
2021-07-22 06:39:28 +00:00
|
|
|
|| !ent->renderer.model)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2004-04-28 04:07:50 +00:00
|
|
|
// hack the depth range to prevent view model from poking into walls
|
|
|
|
qfglDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));
|
|
|
|
qfglEnable (GL_CULL_FACE);
|
2004-05-02 21:21:00 +00:00
|
|
|
|
|
|
|
if (gl_vector_light->int_val) {
|
|
|
|
qfglEnable (GL_LIGHTING);
|
|
|
|
qfglEnable (GL_NORMALIZE);
|
2012-02-22 02:09:09 +00:00
|
|
|
} else if (gl_tess) {
|
2004-05-02 21:21:00 +00:00
|
|
|
qfglEnable (GL_NORMALIZE);
|
|
|
|
}
|
|
|
|
|
2001-12-19 20:15:38 +00:00
|
|
|
if (gl_affinemodels->int_val)
|
|
|
|
qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
2004-03-15 21:32:19 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) {
|
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
2004-02-21 05:36:19 +00:00
|
|
|
|
2021-07-22 06:39:28 +00:00
|
|
|
gl_R_DrawAliasModel (ent);
|
2004-03-15 21:32:19 +00:00
|
|
|
|
2004-02-21 05:36:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2004-02-27 21:42:52 +00:00
|
|
|
if (gl_mtex_active_tmus >= 2) { // FIXME: Ugly, but faster than cleaning
|
|
|
|
// up in every R_DrawAliasModel()!
|
2004-02-21 05:36:19 +00:00
|
|
|
qglActiveTexture (gl_mtex_enum + 1);
|
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
2004-03-07 23:51:29 +00:00
|
|
|
if (gl_combine_capable && gl_overbright->int_val) {
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
|
2012-02-22 02:09:09 +00:00
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, gl_rgb_scale);
|
2004-02-21 05:36:19 +00:00
|
|
|
} else {
|
|
|
|
qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
qglActiveTexture (gl_mtex_enum + 0);
|
|
|
|
}
|
2001-12-19 20:15:38 +00:00
|
|
|
if (gl_affinemodels->int_val)
|
|
|
|
qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
qfglDisable (GL_NORMALIZE);
|
|
|
|
qfglDisable (GL_LIGHTING);
|
2004-05-02 21:21:00 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-03-10 08:14:38 +00:00
|
|
|
qfglDisable (GL_CULL_FACE);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
2002-10-10 20:12:32 +00:00
|
|
|
MYgluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear,
|
|
|
|
GLdouble zFar)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-07-15 12:23:06 +00:00
|
|
|
GLdouble xmin, xmax, ymin, ymax;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ymax = zNear * tan (fovy * M_PI / 360.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
ymin = -ymax;
|
|
|
|
|
|
|
|
xmin = ymin * aspect;
|
2002-06-26 22:20:12 +00:00
|
|
|
xmax = -xmin;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
// printf ("glFrustum (%f, %f, %f, %f)\n", xmin, xmax, ymin, ymax);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglFrustum (xmin, xmax, ymin, ymax, zNear, zFar);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
2003-01-15 16:53:34 +00:00
|
|
|
R_SetupGL_Viewport_and_Perspective (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-05-20 22:02:44 +00:00
|
|
|
float screenaspect;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
|
|
|
qfglLoadIdentity ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-15 12:23:06 +00:00
|
|
|
screenaspect = r_refdef.vrect.width / (float) r_refdef.vrect.height;
|
2002-06-26 22:20:12 +00:00
|
|
|
MYgluPerspective (r_refdef.fov_y, screenaspect, r_nearclip->value,
|
|
|
|
r_farclip->value);
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_SetupGL (void)
|
|
|
|
{
|
|
|
|
R_SetupGL_Viewport_and_Perspective ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2022-03-14 15:09:37 +00:00
|
|
|
qfglFrontFace (GL_CW);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_MODELVIEW);
|
|
|
|
qfglLoadIdentity ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
static mat4f_t z_up = {
|
|
|
|
{ 0, 0, -1, 0},
|
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 0, 1},
|
|
|
|
};
|
|
|
|
mat4f_t view;
|
[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 (view, z_up, r_refdef.camera_inverse);
|
2021-03-19 11:18:45 +00:00
|
|
|
qfglLoadMatrixf (&view[0][0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
qfglGetFloatv (GL_MODELVIEW_MATRIX, gl_r_world_matrix);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// set drawing parms
|
2004-04-28 04:07:50 +00:00
|
|
|
// qfglEnable (GL_CULL_FACE);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDisable (GL_ALPHA_TEST);
|
|
|
|
qfglAlphaFunc (GL_GREATER, 0.5);
|
|
|
|
qfglEnable (GL_DEPTH_TEST);
|
2001-05-14 06:47:38 +00:00
|
|
|
if (gl_dlight_smooth->int_val)
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglShadeModel (GL_SMOOTH);
|
2001-05-14 06:47:38 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglShadeModel (GL_FLAT);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-05-14 20:49:18 +00:00
|
|
|
R_RenderScene (void)
|
|
|
|
{
|
|
|
|
R_SetupGL ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_EnableGFog ();
|
2022-03-02 07:29:40 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawWorld (); // adds static entities to the list
|
2001-05-14 20:49:18 +00:00
|
|
|
S_ExtraUpdate (); // don't let sound get messed up if going slow
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_RenderDlights ();
|
2022-03-02 07:29:40 +00:00
|
|
|
R_DrawViewModel ();
|
2010-12-10 12:40:36 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_DisableGFog ();
|
2001-05-14 20:49:18 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2003-01-15 16:53:34 +00:00
|
|
|
R_RenderView_
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
r_refdef must be set before the first call
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-15 16:53:34 +00:00
|
|
|
static void
|
|
|
|
R_RenderView_ (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-03-09 14:52:40 +00:00
|
|
|
if (r_norefresh->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2022-03-14 06:27:43 +00:00
|
|
|
if (!r_refdef.worldmodel) {
|
2021-12-02 09:30:57 +00:00
|
|
|
return;
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// render normal view
|
2001-05-14 20:49:18 +00:00
|
|
|
R_RenderScene ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-01-15 16:53:34 +00:00
|
|
|
|
2022-03-14 14:51:30 +00:00
|
|
|
static void R_RenderViewFishEye (void);
|
2021-03-19 11:18:45 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gl_R_RenderView (void)
|
|
|
|
{
|
2022-03-14 14:51:30 +00:00
|
|
|
if(!scr_fisheye->int_val)
|
2021-03-19 11:18:45 +00:00
|
|
|
R_RenderView_ ();
|
|
|
|
else
|
2022-03-14 14:51:30 +00:00
|
|
|
R_RenderViewFishEye ();
|
2021-03-19 11:18:45 +00:00
|
|
|
}
|
2022-03-14 14:51:30 +00:00
|
|
|
|
|
|
|
//FIXME
|
2003-01-15 16:53:34 +00:00
|
|
|
// Algorithm:
|
|
|
|
// Draw up to six views, one in each direction.
|
|
|
|
// Save the picture to cube map texture, use GL_ARB_texture_cube_map.
|
|
|
|
// Create FPOLYCNTxFPOLYCNT polygons sized flat grid.
|
|
|
|
// Baseing on field of view, tie cube map texture to grid using
|
|
|
|
// translation function to map texture coordinates to fixed/regular
|
|
|
|
// grid vertices coordinates.
|
|
|
|
// Render view. Fisheye is done.
|
2022-03-24 06:45:01 +00:00
|
|
|
#if 0
|
2003-01-15 16:53:34 +00:00
|
|
|
#define BOX_FRONT 0
|
|
|
|
#define BOX_RIGHT 1
|
|
|
|
#define BOX_BEHIND 2
|
|
|
|
#define BOX_LEFT 3
|
|
|
|
#define BOX_TOP 4
|
|
|
|
#define BOX_BOTTOM 5
|
2022-03-24 06:45:01 +00:00
|
|
|
#endif
|
2022-03-14 14:51:30 +00:00
|
|
|
static mat4f_t box_rotations[] = {
|
|
|
|
{ { 1, 0, 0, 0}, // front
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
{ { 0,-1, 0, 0}, // right
|
|
|
|
{ 1, 0, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
{ {-1, 0, 0, 0}, // back
|
|
|
|
{ 0,-1, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
{ { 0, 1, 0, 0}, // left
|
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
{ { 0, 0, 1, 0}, // top
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
{ { 0, 0,-1, 0}, // bottom
|
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 1, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 1} },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FPOLYCNT 128
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
struct xyz {
|
|
|
|
float x, y, z;
|
|
|
|
};
|
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
static struct xyz FisheyeLookupTbl[FPOLYCNT + 1][FPOLYCNT + 1];
|
2003-01-15 16:53:34 +00:00
|
|
|
static GLuint cube_map_tex;
|
|
|
|
static GLint gl_cube_map_size;
|
|
|
|
static GLint gl_cube_map_step;
|
|
|
|
|
|
|
|
static const GLenum box2cube_map[] = {
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_BuildFisheyeLookup (int width, int height, float fov)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
struct xyz *v;
|
|
|
|
|
|
|
|
for (y = 0; y <= height; y += gl_cube_map_step) {
|
|
|
|
for (x = 0; x <= width; x += gl_cube_map_step) {
|
2003-02-09 19:35:49 +00:00
|
|
|
float dx = x - width / 2;
|
|
|
|
float dy = y - height / 2;
|
|
|
|
float yaw = sqrt (dx * dx + dy * dy) * fov / width;
|
|
|
|
float roll = atan2 (dy, dx);
|
2003-01-15 16:53:34 +00:00
|
|
|
// X is a first index and Y is a second, because later
|
2004-03-15 21:32:19 +00:00
|
|
|
// when we draw QUAD_STRIPs we need next Y vertex coordinate.
|
2003-02-09 19:35:49 +00:00
|
|
|
v = &FisheyeLookupTbl[x / gl_cube_map_step][y / gl_cube_map_step];
|
|
|
|
v->x = sin (yaw) * cos (roll);
|
|
|
|
v->y = -sin (yaw) * sin (roll);
|
|
|
|
v->z = cos (yaw);
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHKGLERR(s) \
|
|
|
|
do { \
|
|
|
|
GLint err = qfglGetError(); \
|
2003-02-09 19:35:49 +00:00
|
|
|
if (err != GL_NO_ERROR) \
|
|
|
|
printf ("%s: gl error %d\n", s, (int) err); \
|
2003-01-15 16:53:34 +00:00
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_RenderCubeSide (int side)
|
|
|
|
{
|
2022-03-14 14:51:30 +00:00
|
|
|
mat4f_t camera;
|
|
|
|
mat4f_t camera_inverse;
|
|
|
|
mat4f_t rotinv;
|
|
|
|
|
|
|
|
memcpy (camera, r_refdef.camera, sizeof (camera));
|
|
|
|
memcpy (camera_inverse, r_refdef.camera_inverse, sizeof (camera_inverse));
|
|
|
|
mmulf (r_refdef.camera, camera, box_rotations[side]);
|
|
|
|
mat4ftranspose (rotinv, box_rotations[side]);
|
|
|
|
mmulf (r_refdef.camera_inverse, rotinv, camera_inverse);
|
|
|
|
|
|
|
|
//FIXME see fixme in r_screen.c
|
|
|
|
r_refdef.frame.mat[0] = -r_refdef.camera[1];
|
|
|
|
r_refdef.frame.mat[1] = r_refdef.camera[0];
|
|
|
|
r_refdef.frame.mat[2] = r_refdef.camera[2];
|
|
|
|
r_refdef.frame.mat[3] = r_refdef.camera[3];
|
|
|
|
#if 0
|
|
|
|
printf ("side: %d\n", side);
|
|
|
|
printf ("c: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 0));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 1));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 2));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 3));
|
|
|
|
printf ("i: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 0));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 1));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 2));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 3));
|
|
|
|
printf ("f: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 0));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 1));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 2));
|
|
|
|
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 3));
|
|
|
|
#endif
|
|
|
|
qfglClear (GL_DEPTH_BUFFER_BIT);
|
2003-01-15 16:53:34 +00:00
|
|
|
R_RenderView_ ();
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
2003-01-15 16:53:34 +00:00
|
|
|
qfglCopyTexSubImage2D (box2cube_map[side], 0, 0, 0, 0, 0,
|
2003-02-09 19:35:49 +00:00
|
|
|
gl_cube_map_size, gl_cube_map_size);
|
2022-03-14 14:51:30 +00:00
|
|
|
CHKGLERR ("qfglCopyTexSubImage2D");
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
2003-01-15 16:53:34 +00:00
|
|
|
|
2022-03-14 14:51:30 +00:00
|
|
|
memcpy (r_refdef.camera, camera, sizeof (camera));
|
|
|
|
memcpy (r_refdef.camera_inverse, camera_inverse, sizeof (camera_inverse));
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static qboolean gl_cube_map_capable = false;
|
|
|
|
static GLint gl_cube_map_maxtex;
|
|
|
|
static GLuint fisheye_grid;
|
|
|
|
|
|
|
|
static int
|
|
|
|
R_InitFishEyeOnce (void)
|
|
|
|
{
|
|
|
|
static qboolean fisheye_init_once_completed = false;
|
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
if (fisheye_init_once_completed)
|
|
|
|
return 1;
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "GL_ARB_texture_cube_map ");
|
2003-01-15 16:53:34 +00:00
|
|
|
if (QFGL_ExtensionPresent ("GL_ARB_texture_cube_map")) {
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB,
|
|
|
|
&gl_cube_map_maxtex);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "present, max texture size %d.\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
(int) gl_cube_map_maxtex);
|
2003-01-15 16:53:34 +00:00
|
|
|
gl_cube_map_capable = true;
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "not found.\n");
|
2003-02-09 19:35:49 +00:00
|
|
|
gl_cube_map_capable = false;
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
fisheye_init_once_completed = true;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
R_InitFishEye (void)
|
|
|
|
{
|
|
|
|
int width = vid.width;
|
|
|
|
int height = vid.height;
|
|
|
|
int fov = scr_ffov->int_val;
|
|
|
|
int views = scr_fviews->int_val;
|
|
|
|
|
|
|
|
static int pwidth = -1;
|
|
|
|
static int pheight = -1;
|
|
|
|
static int pfov = -1;
|
|
|
|
static int pviews = -1;
|
|
|
|
|
|
|
|
int i, x, y, min_wh, wh_changed = 0;
|
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
if (!R_InitFishEyeOnce())
|
|
|
|
return 0;
|
|
|
|
if (!gl_cube_map_capable)
|
|
|
|
return 0;
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
// There is a problem when max texture size is bigger than
|
|
|
|
// min(width, height), it shows up as black fat stripes at the edges
|
|
|
|
// of box polygons, probably due to missing texture fragment. Try
|
|
|
|
// to play in 640x480 with gl_cube_map_size == 512.
|
|
|
|
if (pwidth != width || pheight != height) {
|
|
|
|
wh_changed = 1;
|
|
|
|
min_wh = (height < width) ? height : width;
|
|
|
|
gl_cube_map_size = gl_cube_map_maxtex;
|
|
|
|
while (gl_cube_map_size > min_wh)
|
|
|
|
gl_cube_map_size /= 2;
|
2003-02-09 19:35:49 +00:00
|
|
|
gl_cube_map_step = gl_cube_map_size / FPOLYCNT;
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
if (pviews != views) {
|
|
|
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
if (pviews != -1)
|
|
|
|
qfglDeleteTextures (1, &cube_map_tex);
|
|
|
|
pviews = views;
|
|
|
|
qfglGenTextures (1, &cube_map_tex);
|
|
|
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
|
|
|
for (i = 0; i < 6; ++i) {
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size,
|
|
|
|
gl_cube_map_size, 0, GL_RGB, GL_UNSIGNED_SHORT,
|
|
|
|
NULL);
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR);
|
2003-01-15 16:53:34 +00:00
|
|
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
}
|
|
|
|
if (wh_changed || pfov != fov) {
|
|
|
|
if (pfov != -1)
|
|
|
|
qfglDeleteLists (fisheye_grid, 1);
|
|
|
|
pwidth = width;
|
|
|
|
pheight = height;
|
|
|
|
pfov = fov;
|
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size,
|
|
|
|
((float) fov) * M_PI / 180.0);
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
fisheye_grid = qfglGenLists (1);
|
|
|
|
qfglNewList (fisheye_grid, GL_COMPILE);
|
|
|
|
qfglLoadIdentity ();
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglTranslatef (-gl_cube_map_size / 2, -gl_cube_map_size / 2,
|
|
|
|
-gl_cube_map_size / 2);
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
qfglDisable (GL_DEPTH_TEST);
|
2012-01-03 09:06:26 +00:00
|
|
|
qfglFrontFace (GL_CCW);
|
2003-01-15 16:53:34 +00:00
|
|
|
qfglClear (GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
2003-01-15 16:53:34 +00:00
|
|
|
for (y = 0; y < gl_cube_map_size; y += gl_cube_map_step) {
|
2011-04-17 04:03:22 +00:00
|
|
|
qfglBegin (GL_QUAD_STRIP);
|
2003-01-15 16:53:34 +00:00
|
|
|
for (x = 0; x <= gl_cube_map_size; x += gl_cube_map_step) { // quad_strip, X should be inclusive
|
2003-02-09 19:35:49 +00:00
|
|
|
struct xyz *v = &FisheyeLookupTbl[x / gl_cube_map_step]
|
|
|
|
[y / gl_cube_map_step + 1];
|
|
|
|
qfglTexCoord3f (v->x, v->y, v->z);
|
|
|
|
qfglVertex2i (x, y + gl_cube_map_step);
|
2003-01-15 16:53:34 +00:00
|
|
|
--v;
|
2003-02-09 19:35:49 +00:00
|
|
|
qfglTexCoord3f (v->x, v->y, v->z);
|
|
|
|
qfglVertex2i (x, y);
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
2011-04-17 04:03:22 +00:00
|
|
|
qfglEnd ();
|
2003-01-15 16:53:34 +00:00
|
|
|
}
|
|
|
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
qfglEnable (GL_DEPTH_TEST);
|
|
|
|
qfglEndList ();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_RenderViewFishEye (void)
|
|
|
|
{
|
|
|
|
float s_fov_x, s_fov_y;
|
2009-12-23 08:20:29 +00:00
|
|
|
int s_vid_w, s_vid_h, s_rect_w, s_rect_h;
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
if (!R_InitFishEye()) return;
|
|
|
|
|
|
|
|
// save values
|
|
|
|
s_fov_x = r_refdef.fov_x;
|
|
|
|
s_fov_y = r_refdef.fov_y;
|
|
|
|
s_vid_w = vid.width;
|
|
|
|
s_vid_h = vid.height;
|
|
|
|
s_rect_w = r_refdef.vrect.width;
|
|
|
|
s_rect_h = r_refdef.vrect.height;
|
|
|
|
// the view should be square
|
|
|
|
r_refdef.fov_x = r_refdef.fov_y = 90;
|
|
|
|
vid.width = vid.height =
|
|
|
|
r_refdef.vrect.height = r_refdef.vrect.width =
|
2009-12-23 08:20:29 +00:00
|
|
|
gl_cube_map_size;
|
2003-01-15 16:53:34 +00:00
|
|
|
switch (scr_fviews->int_val) {
|
|
|
|
case 6: R_RenderCubeSide (BOX_BEHIND);
|
|
|
|
case 5: R_RenderCubeSide (BOX_BOTTOM);
|
|
|
|
case 4: R_RenderCubeSide (BOX_TOP);
|
|
|
|
case 3: R_RenderCubeSide (BOX_LEFT);
|
|
|
|
case 2: R_RenderCubeSide (BOX_RIGHT);
|
|
|
|
default: R_RenderCubeSide (BOX_FRONT);
|
|
|
|
}
|
|
|
|
// restore
|
|
|
|
r_refdef.fov_x = s_fov_x;
|
|
|
|
r_refdef.fov_y = s_fov_y;
|
|
|
|
vid.width = s_vid_w;
|
|
|
|
vid.height = s_vid_h;
|
|
|
|
r_refdef.vrect.width = s_rect_w;
|
|
|
|
r_refdef.vrect.height = s_rect_h;
|
|
|
|
R_SetupGL_Viewport_and_Perspective ();
|
|
|
|
qfglMatrixMode (GL_MODELVIEW);
|
|
|
|
qfglCallList (fisheye_grid);
|
2022-03-14 14:51:30 +00:00
|
|
|
}
|
2011-12-23 03:51:47 +00:00
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_ClearState (void)
|
2011-12-23 03:51:47 +00:00
|
|
|
{
|
2022-03-14 06:27:43 +00:00
|
|
|
r_refdef.worldmodel = 0;
|
2011-12-23 03:51:47 +00:00
|
|
|
R_ClearEfrags ();
|
|
|
|
R_ClearDlights ();
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2011-12-23 03:51:47 +00:00
|
|
|
}
|