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
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
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 06:47:38 +00:00
|
|
|
#include "QF/locs.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"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.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"
|
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"
|
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"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
int gl_c_brush_polys, gl_c_alias_polys;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
qboolean gl_envmap; // true during envmap command capture
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
int gl_mirrortexturenum; // quake texturenum, not gltexturenum
|
|
|
|
qboolean gl_mirror;
|
|
|
|
plane_t *gl_mirror_plane;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
float gl_r_world_matrix[16];
|
2012-02-17 09:33:07 +00:00
|
|
|
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
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
/* Unknown renamed to GLErr_Unknown to solve conflict with winioctl.h */
|
2012-02-22 07:32:34 +00:00
|
|
|
static unsigned int GLErr_InvalidEnum;
|
|
|
|
static unsigned int GLErr_InvalidValue;
|
|
|
|
static unsigned int GLErr_InvalidOperation;
|
|
|
|
static unsigned int GLErr_OutOfMemory;
|
|
|
|
static unsigned int GLErr_StackOverflow;
|
|
|
|
static unsigned int GLErr_StackUnderflow;
|
|
|
|
static unsigned int GLErr_Unknown;
|
2003-05-08 22:16:30 +00:00
|
|
|
|
2003-03-20 19:58:18 +00:00
|
|
|
extern void (*R_DrawSpriteModel) (struct entity_s *ent);
|
|
|
|
|
2001-10-30 19:58:01 +00:00
|
|
|
|
2003-05-09 05:22:30 +00:00
|
|
|
static unsigned int
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (unsigned int numerous)
|
2003-03-21 21:28:09 +00:00
|
|
|
{
|
|
|
|
switch (qfglGetError ()) {
|
2004-02-09 04:13:44 +00:00
|
|
|
case GL_NO_ERROR:
|
|
|
|
return numerous;
|
|
|
|
break;
|
2003-03-21 21:28:09 +00:00
|
|
|
case GL_INVALID_ENUM:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_InvalidEnum++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
case GL_INVALID_VALUE:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_InvalidValue++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
case GL_INVALID_OPERATION:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_InvalidOperation++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
case GL_STACK_OVERFLOW:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_StackOverflow++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
case GL_STACK_UNDERFLOW:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_StackUnderflow++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
case GL_OUT_OF_MEMORY:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_OutOfMemory++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_Unknown++;
|
2003-05-08 22:16:30 +00:00
|
|
|
R_TestErrors (numerous++);
|
2003-03-21 21:28:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-05-08 22:16:30 +00:00
|
|
|
|
|
|
|
return numerous;
|
|
|
|
}
|
|
|
|
|
2003-05-09 05:22:30 +00:00
|
|
|
static void
|
2003-05-08 22:16:30 +00:00
|
|
|
R_DisplayErrors (void)
|
|
|
|
{
|
2007-03-22 23:20:57 +00:00
|
|
|
if (GLErr_InvalidEnum)
|
|
|
|
printf ("%d OpenGL errors: Invalid Enum!\n", GLErr_InvalidEnum);
|
|
|
|
if (GLErr_InvalidValue)
|
|
|
|
printf ("%d OpenGL errors: Invalid Value!\n", GLErr_InvalidValue);
|
|
|
|
if (GLErr_InvalidOperation)
|
|
|
|
printf ("%d OpenGL errors: Invalid Operation!\n", GLErr_InvalidOperation);
|
|
|
|
if (GLErr_StackOverflow)
|
|
|
|
printf ("%d OpenGL errors: Stack Overflow!\n", GLErr_StackOverflow);
|
|
|
|
if (GLErr_StackUnderflow)
|
|
|
|
printf ("%d OpenGL errors: Stack Underflow\n!", GLErr_StackUnderflow);
|
|
|
|
if (GLErr_OutOfMemory)
|
|
|
|
printf ("%d OpenGL errors: Out Of Memory!\n", GLErr_OutOfMemory);
|
|
|
|
if (GLErr_Unknown)
|
|
|
|
printf ("%d Unknown OpenGL errors!\n", GLErr_Unknown);
|
2003-05-08 22:16:30 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 05:22:30 +00:00
|
|
|
static void
|
2003-05-08 22:16:30 +00:00
|
|
|
R_ClearErrors (void)
|
|
|
|
{
|
2007-03-22 23:20:57 +00:00
|
|
|
GLErr_InvalidEnum = 0;
|
|
|
|
GLErr_InvalidValue = 0;
|
|
|
|
GLErr_InvalidOperation = 0;
|
|
|
|
GLErr_OutOfMemory = 0;
|
|
|
|
GLErr_StackOverflow = 0;
|
|
|
|
GLErr_StackUnderflow = 0;
|
|
|
|
GLErr_Unknown = 0;
|
2003-03-21 21:28:09 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-12-15 03:06:03 +00:00
|
|
|
qfglMultMatrixf (e->transform);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-05-08 22:16:30 +00:00
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
/*
|
|
|
|
R_DrawEntitiesOnList
|
|
|
|
|
|
|
|
Draw all the entities we have information on.
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_DrawEntitiesOnList (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2010-12-03 05:54:39 +00:00
|
|
|
entity_t *ent;
|
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
|
|
|
|
2010-12-03 05:54:39 +00:00
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) {
|
|
|
|
if (ent->model->type != mod_alias)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2010-12-03 05:54:39 +00:00
|
|
|
currententity = ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawAliasModel (currententity);
|
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
|
|
|
|
2012-05-17 06:58:29 +00:00
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) {
|
|
|
|
if (ent->model->type != mod_iqm)
|
|
|
|
continue;
|
|
|
|
currententity = ent;
|
|
|
|
|
|
|
|
gl_R_DrawIQMModel (currententity);
|
|
|
|
}
|
|
|
|
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);
|
2010-12-03 05:54:39 +00:00
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) {
|
|
|
|
if (ent->model->type != mod_sprite)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2010-12-03 05:54:39 +00:00
|
|
|
currententity = ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_DrawSpriteModel (currententity);
|
|
|
|
}
|
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
|
|
|
{
|
2012-02-14 08:28:09 +00:00
|
|
|
currententity = vr_data.view_model;
|
|
|
|
if (vr_data.inhibit_viewmodel
|
2001-05-21 00:22:35 +00:00
|
|
|
|| !r_drawviewmodel->int_val
|
2012-02-17 09:33:07 +00:00
|
|
|
|| gl_envmap
|
2001-05-15 03:27:55 +00:00
|
|
|
|| !r_drawentities->int_val
|
2001-05-21 00:22:35 +00:00
|
|
|
|| !currententity->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
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawAliasModel (currententity);
|
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-11-20 09:41:15 +00:00
|
|
|
static inline int
|
2011-11-14 02:18:22 +00:00
|
|
|
SignbitsForPlane (plane_t *out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
int bits, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// for fast box on planeside test
|
|
|
|
|
|
|
|
bits = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (out->normal[j] < 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
bits |= 1 << j;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_SetFrustum (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-26 22:20:12 +00:00
|
|
|
// rotate VPN right by FOV_X/2 degrees
|
|
|
|
RotatePointAroundVector (frustum[0].normal, vup, vpn,
|
|
|
|
-(90 - r_refdef.fov_x / 2));
|
|
|
|
// rotate VPN left by FOV_X/2 degrees
|
|
|
|
RotatePointAroundVector (frustum[1].normal, vup, vpn,
|
|
|
|
90 - r_refdef.fov_x / 2);
|
|
|
|
// rotate VPN up by FOV_Y/2 degrees
|
|
|
|
RotatePointAroundVector (frustum[2].normal, vright, vpn,
|
|
|
|
90 - r_refdef.fov_y / 2);
|
|
|
|
// rotate VPN down by FOV_Y/2 degrees
|
|
|
|
RotatePointAroundVector (frustum[3].normal, vright, vpn,
|
|
|
|
-(90 - r_refdef.fov_y / 2));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
frustum[i].type = PLANE_ANYZ;
|
|
|
|
frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
|
|
|
|
frustum[i].signbits = SignbitsForPlane (&frustum[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-10 06:01:11 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_SetupFrame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
R_AnimateLight ();
|
2010-12-25 10:47:31 +00:00
|
|
|
R_ClearEnts ();
|
2001-02-19 21:15:25 +00:00
|
|
|
r_framecount++;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_SetupFrame ();
|
2010-12-10 12:40:36 +00:00
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
// build the transformation matrix for the given view angles
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (r_refdef.vieworg, r_origin);
|
|
|
|
|
|
|
|
AngleVectors (r_refdef.viewangles, vpn, vright, vup);
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
// current viewleaf
|
2001-05-20 04:25:36 +00:00
|
|
|
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.model);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_cache_thrash = false;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_c_brush_polys = 0;
|
|
|
|
gl_c_alias_polys = 0;
|
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
|
|
|
{
|
2001-09-09 19:37:07 +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;
|
2009-12-23 08:05:03 +00:00
|
|
|
int x, y2, w, h;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// set up viewpoint
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
|
|
|
qfglLoadIdentity ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_envmap) {
|
2001-02-19 21:15:25 +00:00
|
|
|
x = y2 = 0;
|
|
|
|
w = h = 256;
|
2002-06-26 22:20:12 +00:00
|
|
|
} else {
|
2009-12-23 08:05:03 +00:00
|
|
|
x = r_refdef.vrect.x;
|
|
|
|
y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height));
|
|
|
|
|
2009-12-23 07:53:05 +00:00
|
|
|
w = r_refdef.vrect.width;
|
|
|
|
h = r_refdef.vrect.height;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-03-21 21:28:09 +00:00
|
|
|
// printf ("glViewport(%d, %d, %d, %d)\n", glx + x, gly + y2, w, h);
|
2009-12-23 08:20:29 +00:00
|
|
|
qfglViewport (x, y2, w, h);
|
2009-12-24 05:33:41 +00:00
|
|
|
screenaspect = r_refdef.vrect.width * vid.aspect / 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_SetFrustum ();
|
|
|
|
|
|
|
|
R_SetupGL_Viewport_and_Perspective ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_mirror) {
|
|
|
|
if (gl_mirror_plane->normal[2])
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (1, -1, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (-1, 1, 1);
|
2012-01-03 09:06:26 +00:00
|
|
|
qfglFrontFace (GL_CCW);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2012-01-03 09:06:26 +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
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglRotatef (-90, 1, 0, 0); // put Z going up
|
|
|
|
qfglRotatef (90, 0, 0, 1); // put Z going up
|
2011-12-30 12:07:35 +00:00
|
|
|
qfglRotatef (-r_refdef.viewangles[ROLL], 1, 0, 0);
|
|
|
|
qfglRotatef (-r_refdef.viewangles[PITCH], 0, 1, 0);
|
|
|
|
qfglRotatef (-r_refdef.viewangles[YAW], 0, 0, 1);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1],
|
2001-02-26 06:48:02 +00:00
|
|
|
-r_refdef.vieworg[2]);
|
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-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_Clear (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (gl_clear->int_val)
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglClear (GL_DEPTH_BUFFER_BIT);
|
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)
|
|
|
|
{
|
2001-05-22 06:00:38 +00:00
|
|
|
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
|
|
|
|
r_time1 = Sys_DoubleTime ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_SetupFrame ();
|
2001-05-14 20:49:18 +00:00
|
|
|
R_SetupGL ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_EnableGFog ();
|
2001-05-14 20:49:18 +00:00
|
|
|
R_MarkLeaves (); // done here so we know if we're in water
|
2001-08-05 04:01:45 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
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
|
|
|
|
R_DrawEntitiesOnList ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_RenderDlights ();
|
2003-05-08 22:16:30 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawWaterSurfaces ();
|
|
|
|
gl_R_DrawParticles ();
|
2010-12-10 12:40:36 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_Fog_DisableGFog ();
|
2010-12-10 12:40:36 +00:00
|
|
|
|
|
|
|
R_DrawViewModel ();
|
|
|
|
|
2003-05-08 22:16:30 +00:00
|
|
|
if (R_TestErrors (0))
|
|
|
|
R_DisplayErrors ();
|
2004-03-15 21:32:19 +00:00
|
|
|
R_ClearErrors ();
|
2001-05-14 20:49:18 +00:00
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-11-20 09:41:15 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_Mirror (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
float d;
|
2011-12-17 10:14:14 +00:00
|
|
|
// msurface_t *s;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
// if (!gl_mirror) // FIXME: Broken
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
memcpy (r_base_world_matrix, gl_r_world_matrix,
|
|
|
|
sizeof (r_base_world_matrix));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
d = 2 * DotProduct (r_refdef.vieworg, gl_mirror_plane->normal) -
|
|
|
|
gl_mirror_plane->dist;
|
|
|
|
VectorMultSub (r_refdef.vieworg, d, gl_mirror_plane->normal,
|
2003-08-08 15:25:53 +00:00
|
|
|
r_refdef.vieworg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
d = 2 * DotProduct (vpn, gl_mirror_plane->normal);
|
|
|
|
VectorMultSub (vpn, d, gl_mirror_plane->normal, vpn);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r_refdef.viewangles[0] = -asin (vpn[2]) / M_PI * 180;
|
|
|
|
r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0]) / M_PI * 180;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.viewangles[2] = -r_refdef.viewangles[2];
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
R_EnqueueEntity (vr_data.player_entity);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
gldepthmin = 0.5;
|
|
|
|
gldepthmax = 1;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_RenderScene ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_DrawWaterSurfaces ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
gldepthmin = 0;
|
2001-10-02 00:01:05 +00:00
|
|
|
gldepthmax = 1;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// blend on top
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
2012-02-17 09:33:07 +00:00
|
|
|
if (gl_mirror_plane->normal[2])
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (1, -1, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (-1, 1, 1);
|
2012-01-03 09:06:26 +00:00
|
|
|
qfglFrontFace (GL_CW);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_MODELVIEW);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglLoadMatrixf (r_base_world_matrix);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-03-15 21:32:19 +00:00
|
|
|
color_white[3] = r_mirroralpha->value * 255;
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor4ubv (color_white);
|
2011-12-17 10:14:14 +00:00
|
|
|
#if 0//FIXME
|
2012-02-17 09:33:07 +00:00
|
|
|
s = r_worldentity.model->textures[gl_mirrortexturenum]->texturechain;
|
2002-03-16 09:25:06 +00:00
|
|
|
for (; s; s = s->texturechain) {
|
2002-04-15 03:26:08 +00:00
|
|
|
texture_t *tex;
|
2004-02-21 05:36:19 +00:00
|
|
|
|
2002-04-15 03:26:08 +00:00
|
|
|
if (!s->texinfo->texture->anim_total)
|
|
|
|
tex = s->texinfo->texture;
|
|
|
|
else
|
|
|
|
tex = R_TextureAnimation (s);
|
|
|
|
|
2004-02-21 05:36:19 +00:00
|
|
|
// FIXME: Needs to set the texture, the tmu, and include the header, and then
|
|
|
|
// clean up afterwards.
|
|
|
|
// if (tex->gl_fb_texturenum && gl_mtex_fullbright
|
|
|
|
// && gl_fb_models->int_val) {
|
2002-04-15 03:26:08 +00:00
|
|
|
// s->polys->fb_chain = fullbright_polys[tex->gl_fb_texturenum];
|
|
|
|
// fullbright_polys[tex->gl_fb_texturenum] = s->polys;
|
|
|
|
// }
|
|
|
|
|
2002-03-16 09:25:06 +00:00
|
|
|
qfglBindTexture (GL_TEXTURE_2D, tex->gl_texturenum);
|
2004-02-22 06:00:15 +00:00
|
|
|
// R_RenderBrushPoly (s, tex); // FIXME: Need to move R_Mirror to gl_rsurf.c, and uncommment this line!
|
2002-03-16 09:25:06 +00:00
|
|
|
}
|
2012-02-17 09:33:07 +00:00
|
|
|
r_worldentity.model->textures[gl_mirrortexturenum]->texturechain = NULL;
|
2011-12-17 10:14:14 +00:00
|
|
|
#endif
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
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
|
|
|
{
|
|
|
|
if (r_norefresh->int_val)
|
|
|
|
return;
|
2001-05-20 04:25:36 +00:00
|
|
|
if (!r_worldentity.model)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("R_RenderView: NULL worldmodel");
|
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
gl_mirror = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_Clear ();
|
|
|
|
|
|
|
|
// render normal view
|
2001-05-14 20:49:18 +00:00
|
|
|
R_RenderScene ();
|
2004-04-28 04:07:50 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// render mirror view
|
2001-05-14 20:49:18 +00:00
|
|
|
R_Mirror ();
|
2001-08-30 18:24:19 +00:00
|
|
|
|
|
|
|
if (r_timegraph->int_val)
|
|
|
|
R_TimeGraph ();
|
|
|
|
if (r_zgraph->int_val)
|
|
|
|
R_ZGraph ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
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.
|
|
|
|
|
|
|
|
static void R_RenderViewFishEye (void);
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_RenderView (void)
|
2003-01-15 16:53:34 +00:00
|
|
|
{
|
|
|
|
if(!scr_fisheye->int_val)
|
|
|
|
R_RenderView_ ();
|
|
|
|
else
|
|
|
|
R_RenderViewFishEye ();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOX_FRONT 0
|
|
|
|
#define BOX_RIGHT 1
|
|
|
|
#define BOX_BEHIND 2
|
|
|
|
#define BOX_LEFT 3
|
|
|
|
#define BOX_TOP 4
|
|
|
|
#define BOX_BOTTOM 5
|
|
|
|
|
|
|
|
#define FPOLYCNT 16
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
#define NO(x) \
|
|
|
|
do { \
|
2003-02-09 19:35:49 +00:00
|
|
|
if (x < 0) \
|
|
|
|
x += 360; \
|
|
|
|
else if (x >= 360) \
|
|
|
|
x -= 360; \
|
2003-01-15 16:53:34 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_RenderCubeSide (int side)
|
|
|
|
{
|
|
|
|
float pitch, n_pitch;
|
|
|
|
float yaw, n_yaw;
|
|
|
|
float roll, n_roll;
|
|
|
|
float s_roll;
|
|
|
|
|
|
|
|
pitch = n_pitch = r_refdef.viewangles[PITCH];
|
|
|
|
yaw = n_yaw = r_refdef.viewangles[YAW];
|
|
|
|
// setting ROLL for now to 0, correct roll handling
|
|
|
|
// requre more exhaustive changes in rotation
|
|
|
|
// TODO: implement via matrix
|
2003-02-09 19:35:49 +00:00
|
|
|
// roll = n_roll = r_refdef.viewangles[ROLL];
|
2003-01-15 16:53:34 +00:00
|
|
|
s_roll = r_refdef.viewangles[ROLL];
|
|
|
|
roll = n_roll = 0;
|
2003-02-09 19:35:49 +00:00
|
|
|
// roll -= scr_fviews->int_val * 10;
|
|
|
|
// n_roll = roll;
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
switch (side) {
|
2003-02-09 19:35:49 +00:00
|
|
|
case BOX_FRONT:
|
|
|
|
break;
|
2003-01-15 16:53:34 +00:00
|
|
|
case BOX_RIGHT:
|
|
|
|
n_pitch = roll;
|
|
|
|
n_yaw -= 90;
|
|
|
|
n_roll = -pitch;
|
|
|
|
break;
|
|
|
|
case BOX_LEFT:
|
|
|
|
n_pitch = -roll;
|
|
|
|
n_yaw += 90;
|
|
|
|
n_roll = pitch;
|
2003-02-09 19:35:49 +00:00
|
|
|
// static int f = 0;
|
|
|
|
// if (!(f++ % 100))
|
|
|
|
// printf ("%4d %4d %4d | %4d %4d %4d\n", (int) pitch, (int) yaw,
|
|
|
|
// (int) roll, (int) n_pitch, (int) n_yaw, (int) n_roll);
|
2003-01-15 16:53:34 +00:00
|
|
|
break;
|
|
|
|
case BOX_TOP:
|
|
|
|
n_pitch -= 90;
|
|
|
|
break;
|
|
|
|
case BOX_BOTTOM:
|
|
|
|
n_pitch += 90;
|
|
|
|
break;
|
|
|
|
case BOX_BEHIND:
|
|
|
|
n_pitch = -pitch;
|
|
|
|
n_yaw += 180;
|
|
|
|
break;
|
|
|
|
}
|
2003-02-09 19:35:49 +00:00
|
|
|
NO (n_pitch);
|
|
|
|
NO (n_yaw);
|
|
|
|
NO (n_roll);
|
2003-01-15 16:53:34 +00:00
|
|
|
r_refdef.viewangles[PITCH] = n_pitch;
|
|
|
|
r_refdef.viewangles[YAW] = n_yaw;
|
|
|
|
r_refdef.viewangles[ROLL] = n_roll;
|
|
|
|
|
|
|
|
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);
|
|
|
|
// CHKGLERR ("qfglCopyTexSubImage2D");
|
|
|
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
2003-01-15 16:53:34 +00:00
|
|
|
|
|
|
|
r_refdef.viewangles[PITCH] = pitch;
|
|
|
|
r_refdef.viewangles[YAW] = yaw;
|
|
|
|
r_refdef.viewangles[ROLL] = s_roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-11-23 05:09:30 +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);
|
2010-11-23 05:09:30 +00:00
|
|
|
Sys_MaskPrintf (SYS_DEV, "present, max texture size %d.\n",
|
|
|
|
(int) gl_cube_map_maxtex);
|
2003-01-15 16:53:34 +00:00
|
|
|
gl_cube_map_capable = true;
|
|
|
|
} else {
|
2010-11-23 05:09:30 +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);
|
|
|
|
}
|
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
|
|
|
{
|
2012-01-28 11:45:14 +00:00
|
|
|
r_worldentity.model = 0;
|
2011-12-23 03:51:47 +00:00
|
|
|
R_ClearEfrags ();
|
|
|
|
R_ClearDlights ();
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_ClearParticles ();
|
2011-12-23 03:51:47 +00:00
|
|
|
}
|