mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +00:00
Cleaned up fisheye code which totally ignored QF coding style.
Also attempt to fix an init bug in R_InitFishEyeOnce (add gl_cube_map_capable = false to else).
This commit is contained in:
parent
76eb7917a7
commit
83f0901c17
1 changed files with 66 additions and 46 deletions
|
@ -305,7 +305,7 @@ MYgluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear,
|
||||||
xmin = ymin * aspect;
|
xmin = ymin * aspect;
|
||||||
xmax = -xmin;
|
xmax = -xmin;
|
||||||
|
|
||||||
//printf ("glFrustum (%f, %f, %f, %f)\n", xmin, xmax, ymin, ymax);
|
// printf ("glFrustum (%f, %f, %f, %f)\n", xmin, xmax, ymin, ymax);
|
||||||
qfglFrustum (xmin, xmax, ymin, ymax, zNear, zFar);
|
qfglFrustum (xmin, xmax, ymin, ymax, zNear, zFar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ R_SetupGL_Viewport_and_Perspective (void)
|
||||||
w = x2 - x;
|
w = x2 - x;
|
||||||
h = y - y2;
|
h = y - y2;
|
||||||
}
|
}
|
||||||
//printf("glViewport(%d, %d, %d, %d)\n", glx + x, gly + y2, w, h);
|
// printf("glViewport(%d, %d, %d, %d)\n", glx + x, gly + y2, w, h);
|
||||||
qfglViewport (glx + x, gly + y2, w, h);
|
qfglViewport (glx + x, gly + y2, w, h);
|
||||||
screenaspect = (float) r_refdef.vrect.width / r_refdef.vrect.height;
|
screenaspect = (float) r_refdef.vrect.width / r_refdef.vrect.height;
|
||||||
MYgluPerspective (r_refdef.fov_y, screenaspect, r_nearclip->value,
|
MYgluPerspective (r_refdef.fov_y, screenaspect, r_nearclip->value,
|
||||||
|
@ -552,7 +552,7 @@ struct xyz {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct xyz FisheyeLookupTbl[FPOLYCNT+1][FPOLYCNT+1];
|
static struct xyz FisheyeLookupTbl[FPOLYCNT + 1][FPOLYCNT + 1];
|
||||||
static GLuint cube_map_tex;
|
static GLuint cube_map_tex;
|
||||||
static GLint gl_cube_map_size;
|
static GLint gl_cube_map_size;
|
||||||
static GLint gl_cube_map_step;
|
static GLint gl_cube_map_step;
|
||||||
|
@ -574,16 +574,16 @@ R_BuildFisheyeLookup (int width, int height, float fov)
|
||||||
|
|
||||||
for (y = 0; y <= height; y += gl_cube_map_step) {
|
for (y = 0; y <= height; y += gl_cube_map_step) {
|
||||||
for (x = 0; x <= width; x += gl_cube_map_step) {
|
for (x = 0; x <= width; x += gl_cube_map_step) {
|
||||||
float dx = x - width/2;
|
float dx = x - width / 2;
|
||||||
float dy = y - height/2;
|
float dy = y - height / 2;
|
||||||
float yaw = sqrt(dx*dx+dy*dy)*fov/width;
|
float yaw = sqrt (dx * dx + dy * dy) * fov / width;
|
||||||
float roll = atan2(dy, dx);
|
float roll = atan2 (dy, dx);
|
||||||
// X is a first index and Y is a second, because later
|
// X is a first index and Y is a second, because later
|
||||||
// when we draw QUAD_STRIPes we need next Y vertix coordinate.
|
// when we draw QUAD_STRIPes we need next Y vertix coordinate.
|
||||||
v = &FisheyeLookupTbl[x/gl_cube_map_step][y/gl_cube_map_step];
|
v = &FisheyeLookupTbl[x / gl_cube_map_step][y / gl_cube_map_step];
|
||||||
v->x = sin(yaw) * cos(roll);
|
v->x = sin (yaw) * cos (roll);
|
||||||
v->y = -sin(yaw) * sin(roll);
|
v->y = -sin (yaw) * sin (roll);
|
||||||
v->z = cos(yaw);
|
v->z = cos (yaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,13 +591,16 @@ R_BuildFisheyeLookup (int width, int height, float fov)
|
||||||
#define CHKGLERR(s) \
|
#define CHKGLERR(s) \
|
||||||
do { \
|
do { \
|
||||||
GLint err = qfglGetError(); \
|
GLint err = qfglGetError(); \
|
||||||
if (err != GL_NO_ERROR) printf ("%s: gl error %d\n", s, (int)err); \
|
if (err != GL_NO_ERROR) \
|
||||||
|
printf ("%s: gl error %d\n", s, (int) err); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define NO(x) \
|
#define NO(x) \
|
||||||
do { \
|
do { \
|
||||||
if (x < 0) x += 360; \
|
if (x < 0) \
|
||||||
else if (x >= 360) x -= 360; \
|
x += 360; \
|
||||||
|
else if (x >= 360) \
|
||||||
|
x -= 360; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -613,14 +616,15 @@ R_RenderCubeSide (int side)
|
||||||
// setting ROLL for now to 0, correct roll handling
|
// setting ROLL for now to 0, correct roll handling
|
||||||
// requre more exhaustive changes in rotation
|
// requre more exhaustive changes in rotation
|
||||||
// TODO: implement via matrix
|
// TODO: implement via matrix
|
||||||
//roll = n_roll = r_refdef.viewangles[ROLL];
|
// roll = n_roll = r_refdef.viewangles[ROLL];
|
||||||
s_roll = r_refdef.viewangles[ROLL];
|
s_roll = r_refdef.viewangles[ROLL];
|
||||||
roll = n_roll = 0;
|
roll = n_roll = 0;
|
||||||
//roll -= scr_fviews->int_val*10;
|
// roll -= scr_fviews->int_val * 10;
|
||||||
//n_roll = roll;
|
// n_roll = roll;
|
||||||
|
|
||||||
switch (side) {
|
switch (side) {
|
||||||
case BOX_FRONT: break;
|
case BOX_FRONT:
|
||||||
|
break;
|
||||||
case BOX_RIGHT:
|
case BOX_RIGHT:
|
||||||
n_pitch = roll;
|
n_pitch = roll;
|
||||||
n_yaw -= 90;
|
n_yaw -= 90;
|
||||||
|
@ -630,10 +634,10 @@ R_RenderCubeSide (int side)
|
||||||
n_pitch = -roll;
|
n_pitch = -roll;
|
||||||
n_yaw += 90;
|
n_yaw += 90;
|
||||||
n_roll = pitch;
|
n_roll = pitch;
|
||||||
//static int f = 0;
|
// static int f = 0;
|
||||||
//if (!(f++%100)) printf("%4d %4d %4d | %4d %4d %4d\n",
|
// if (!(f++ % 100))
|
||||||
//(int)pitch, (int)yaw, (int)roll,
|
// printf ("%4d %4d %4d | %4d %4d %4d\n", (int) pitch, (int) yaw,
|
||||||
//(int)n_pitch, (int)n_yaw, (int)n_roll);
|
// (int) roll, (int) n_pitch, (int) n_yaw, (int) n_roll);
|
||||||
break;
|
break;
|
||||||
case BOX_TOP:
|
case BOX_TOP:
|
||||||
n_pitch -= 90;
|
n_pitch -= 90;
|
||||||
|
@ -646,18 +650,20 @@ R_RenderCubeSide (int side)
|
||||||
n_yaw += 180;
|
n_yaw += 180;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
NO(n_pitch); NO(n_yaw); NO(n_roll);
|
NO (n_pitch);
|
||||||
|
NO (n_yaw);
|
||||||
|
NO (n_roll);
|
||||||
r_refdef.viewangles[PITCH] = n_pitch;
|
r_refdef.viewangles[PITCH] = n_pitch;
|
||||||
r_refdef.viewangles[YAW] = n_yaw;
|
r_refdef.viewangles[YAW] = n_yaw;
|
||||||
r_refdef.viewangles[ROLL] = n_roll;
|
r_refdef.viewangles[ROLL] = n_roll;
|
||||||
|
|
||||||
R_RenderView_ ();
|
R_RenderView_ ();
|
||||||
qfglEnable(GL_TEXTURE_CUBE_MAP_ARB);
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||||
qfglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
||||||
qfglCopyTexSubImage2D (box2cube_map[side], 0, 0, 0, 0, 0,
|
qfglCopyTexSubImage2D (box2cube_map[side], 0, 0, 0, 0, 0,
|
||||||
gl_cube_map_size, gl_cube_map_size);
|
gl_cube_map_size, gl_cube_map_size);
|
||||||
//CHKGLERR ("qfglCopyTexSubImage2D");
|
// CHKGLERR ("qfglCopyTexSubImage2D");
|
||||||
qfglDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||||
|
|
||||||
r_refdef.viewangles[PITCH] = pitch;
|
r_refdef.viewangles[PITCH] = pitch;
|
||||||
r_refdef.viewangles[YAW] = yaw;
|
r_refdef.viewangles[YAW] = yaw;
|
||||||
|
@ -673,14 +679,18 @@ R_InitFishEyeOnce (void)
|
||||||
{
|
{
|
||||||
static qboolean fisheye_init_once_completed = false;
|
static qboolean fisheye_init_once_completed = false;
|
||||||
|
|
||||||
if (fisheye_init_once_completed) return 1;
|
if (fisheye_init_once_completed)
|
||||||
|
return 1;
|
||||||
Con_Printf ("GL_ARB_texture_cube_map ");
|
Con_Printf ("GL_ARB_texture_cube_map ");
|
||||||
if (QFGL_ExtensionPresent ("GL_ARB_texture_cube_map")) {
|
if (QFGL_ExtensionPresent ("GL_ARB_texture_cube_map")) {
|
||||||
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &gl_cube_map_maxtex);
|
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB,
|
||||||
Con_Printf ("present, max texture size %d.\n", (int)gl_cube_map_maxtex);
|
&gl_cube_map_maxtex);
|
||||||
|
Con_Printf ("present, max texture size %d.\n",
|
||||||
|
(int) gl_cube_map_maxtex);
|
||||||
gl_cube_map_capable = true;
|
gl_cube_map_capable = true;
|
||||||
} else {
|
} else {
|
||||||
Con_Printf ("not found.\n");
|
Con_Printf ("not found.\n");
|
||||||
|
gl_cube_map_capable = false;
|
||||||
}
|
}
|
||||||
fisheye_init_once_completed = true;
|
fisheye_init_once_completed = true;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -701,8 +711,10 @@ R_InitFishEye (void)
|
||||||
|
|
||||||
int i, x, y, min_wh, wh_changed = 0;
|
int i, x, y, min_wh, wh_changed = 0;
|
||||||
|
|
||||||
if (!R_InitFishEyeOnce()) return 0;
|
if (!R_InitFishEyeOnce())
|
||||||
if (!gl_cube_map_capable) return 0;
|
return 0;
|
||||||
|
if (!gl_cube_map_capable)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// There is a problem when max texture size is bigger than
|
// There is a problem when max texture size is bigger than
|
||||||
// min(width, height), it shows up as black fat stripes at the edges
|
// min(width, height), it shows up as black fat stripes at the edges
|
||||||
|
@ -714,7 +726,7 @@ R_InitFishEye (void)
|
||||||
gl_cube_map_size = gl_cube_map_maxtex;
|
gl_cube_map_size = gl_cube_map_maxtex;
|
||||||
while (gl_cube_map_size > min_wh)
|
while (gl_cube_map_size > min_wh)
|
||||||
gl_cube_map_size /= 2;
|
gl_cube_map_size /= 2;
|
||||||
gl_cube_map_step = gl_cube_map_size/FPOLYCNT;
|
gl_cube_map_step = gl_cube_map_size / FPOLYCNT;
|
||||||
}
|
}
|
||||||
if (pviews != views) {
|
if (pviews != views) {
|
||||||
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||||
|
@ -724,11 +736,14 @@ R_InitFishEye (void)
|
||||||
qfglGenTextures (1, &cube_map_tex);
|
qfglGenTextures (1, &cube_map_tex);
|
||||||
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
||||||
for (i = 0; i < 6; ++i) {
|
for (i = 0; i < 6; ++i) {
|
||||||
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size, gl_cube_map_size,
|
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size,
|
||||||
0, GL_RGB, GL_UNSIGNED_SHORT, NULL);
|
gl_cube_map_size, 0, GL_RGB, GL_UNSIGNED_SHORT,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
|
||||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GL_LINEAR);
|
||||||
|
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
|
||||||
|
GL_LINEAR);
|
||||||
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||||
}
|
}
|
||||||
if (wh_changed || pfov != fov) {
|
if (wh_changed || pfov != fov) {
|
||||||
|
@ -738,27 +753,32 @@ R_InitFishEye (void)
|
||||||
pheight = height;
|
pheight = height;
|
||||||
pfov = fov;
|
pfov = fov;
|
||||||
|
|
||||||
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size, ((float)fov)*M_PI/180.0);
|
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size,
|
||||||
|
((float) fov) * M_PI / 180.0);
|
||||||
|
|
||||||
fisheye_grid = qfglGenLists (1);
|
fisheye_grid = qfglGenLists (1);
|
||||||
qfglNewList (fisheye_grid, GL_COMPILE);
|
qfglNewList (fisheye_grid, GL_COMPILE);
|
||||||
qfglLoadIdentity ();
|
qfglLoadIdentity ();
|
||||||
qfglTranslatef (-gl_cube_map_size/2, -gl_cube_map_size/2, -gl_cube_map_size/2);
|
qfglTranslatef (-gl_cube_map_size / 2, -gl_cube_map_size / 2,
|
||||||
|
-gl_cube_map_size / 2);
|
||||||
|
|
||||||
qfglDisable (GL_DEPTH_TEST);
|
qfglDisable (GL_DEPTH_TEST);
|
||||||
qfglCullFace (GL_BACK);
|
qfglCullFace (GL_BACK);
|
||||||
qfglClear (GL_COLOR_BUFFER_BIT);
|
qfglClear (GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
qfglEnable(GL_TEXTURE_CUBE_MAP_ARB);
|
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||||
qfglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
||||||
qfglBegin(GL_QUAD_STRIP);
|
qfglBegin (GL_QUAD_STRIP);
|
||||||
|
|
||||||
for (y = 0; y < gl_cube_map_size; y += gl_cube_map_step) {
|
for (y = 0; y < gl_cube_map_size; y += gl_cube_map_step) {
|
||||||
for (x = 0; x <= gl_cube_map_size; x += gl_cube_map_step) { // quad_strip, X should be inclusive
|
for (x = 0; x <= gl_cube_map_size; x += gl_cube_map_step) { // quad_strip, X should be inclusive
|
||||||
struct xyz *v = &FisheyeLookupTbl[x/gl_cube_map_step][y/gl_cube_map_step+1];
|
struct xyz *v = &FisheyeLookupTbl[x / gl_cube_map_step]
|
||||||
qfglTexCoord3f (v->x, v->y, v->z); qfglVertex2i (x, y+gl_cube_map_step);
|
[y / gl_cube_map_step + 1];
|
||||||
|
qfglTexCoord3f (v->x, v->y, v->z);
|
||||||
|
qfglVertex2i (x, y + gl_cube_map_step);
|
||||||
--v;
|
--v;
|
||||||
qfglTexCoord3f (v->x, v->y, v->z); qfglVertex2i (x, y);
|
qfglTexCoord3f (v->x, v->y, v->z);
|
||||||
|
qfglVertex2i (x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qfglEnd ();
|
qfglEnd ();
|
||||||
|
|
Loading…
Reference in a new issue