mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-15 00:20:56 +00:00
Refactored gluPerspective-like function in GL1
It was being called repeteadly with the same parameters, so it was re-written with only one needed parameter, with the rest of the data being obtained inside the function, to avoid logic duplication.
This commit is contained in:
parent
6b8cd8fdf9
commit
6a3a081b4b
2 changed files with 19 additions and 22 deletions
|
@ -36,7 +36,7 @@ int cur_lm_copy; // which lightmap copy to use (when lightmapcopies=on)
|
|||
|
||||
static GLushort vtx_ptr, idx_ptr; // pointers for array positions in gl_buf
|
||||
|
||||
extern void R_MYgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
|
||||
extern void R_SetPerspective(GLdouble fovy);
|
||||
|
||||
void
|
||||
R_ResetGLBuffer(void)
|
||||
|
@ -50,7 +50,6 @@ R_ApplyGLBuffer(void)
|
|||
// Properties of batched draws here
|
||||
GLint vtx_size;
|
||||
qboolean texture, mtex, alpha, color, alias, texenv_set;
|
||||
float fovy, dist;
|
||||
|
||||
if (vtx_ptr == 0 || idx_ptr == 0)
|
||||
{
|
||||
|
@ -107,9 +106,7 @@ R_ApplyGLBuffer(void)
|
|||
glScalef(-1, 1, 1);
|
||||
}
|
||||
|
||||
fovy = (r_gunfov->value < 0) ? r_newrefdef.fov_y : r_gunfov->value;
|
||||
dist = (r_farsee->value == 0) ? 4096.0f : 8192.0f;
|
||||
R_MYgluPerspective(fovy, (float)r_newrefdef.width / r_newrefdef.height, 4, dist);
|
||||
R_SetPerspective( (r_gunfov->value < 0) ? r_newrefdef.fov_y : r_gunfov->value );
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
|
|
|
@ -727,19 +727,28 @@ R_SetupFrame(void)
|
|||
}
|
||||
|
||||
void
|
||||
R_MYgluPerspective(GLdouble fovy, GLdouble aspect,
|
||||
GLdouble zNear, GLdouble zFar)
|
||||
R_SetPerspective(GLdouble fovy)
|
||||
{
|
||||
// gluPerspective style parameters
|
||||
static const GLdouble zNear = 4;
|
||||
const GLdouble zFar = (r_farsee->value) ? 8192.0f : 4096.0f;
|
||||
const GLdouble aspectratio = (GLdouble)r_newrefdef.width / r_newrefdef.height;
|
||||
|
||||
GLdouble xmin, xmax, ymin, ymax;
|
||||
|
||||
// traditional gluPerspective calculations - https://youtu.be/YqSNGcF5nvM?t=644
|
||||
ymax = zNear * tan(fovy * M_PI / 360.0);
|
||||
xmax = ymax * aspectratio;
|
||||
|
||||
ymin = -ymax;
|
||||
xmin = -xmax;
|
||||
|
||||
xmin = ymin * aspect;
|
||||
xmax = ymax * aspect;
|
||||
|
||||
xmin += - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
||||
xmax += - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
||||
if (gl_state.camera_separation)
|
||||
{
|
||||
const GLdouble separation = - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
||||
xmin += separation;
|
||||
xmax += separation;
|
||||
}
|
||||
|
||||
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
||||
}
|
||||
|
@ -747,7 +756,6 @@ R_MYgluPerspective(GLdouble fovy, GLdouble aspect,
|
|||
void
|
||||
R_SetupGL(void)
|
||||
{
|
||||
float screenaspect;
|
||||
int x, x2, y2, y, w, h;
|
||||
|
||||
/* set up viewport */
|
||||
|
@ -777,18 +785,10 @@ R_SetupGL(void)
|
|||
glViewport(x, y2, w, h);
|
||||
|
||||
/* set up projection matrix */
|
||||
screenaspect = (float)r_newrefdef.width / r_newrefdef.height;
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
if (r_farsee->value == 0)
|
||||
{
|
||||
R_MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 4096);
|
||||
}
|
||||
else
|
||||
{
|
||||
R_MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 8192);
|
||||
}
|
||||
R_SetPerspective(r_newrefdef.fov_y);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
|
|
Loading…
Reference in a new issue