mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-16 00:51:46 +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
|
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
|
void
|
||||||
R_ResetGLBuffer(void)
|
R_ResetGLBuffer(void)
|
||||||
|
@ -50,7 +50,6 @@ R_ApplyGLBuffer(void)
|
||||||
// Properties of batched draws here
|
// Properties of batched draws here
|
||||||
GLint vtx_size;
|
GLint vtx_size;
|
||||||
qboolean texture, mtex, alpha, color, alias, texenv_set;
|
qboolean texture, mtex, alpha, color, alias, texenv_set;
|
||||||
float fovy, dist;
|
|
||||||
|
|
||||||
if (vtx_ptr == 0 || idx_ptr == 0)
|
if (vtx_ptr == 0 || idx_ptr == 0)
|
||||||
{
|
{
|
||||||
|
@ -107,9 +106,7 @@ R_ApplyGLBuffer(void)
|
||||||
glScalef(-1, 1, 1);
|
glScalef(-1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fovy = (r_gunfov->value < 0) ? r_newrefdef.fov_y : r_gunfov->value;
|
R_SetPerspective( (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);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
|
|
@ -727,19 +727,28 @@ R_SetupFrame(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
R_MYgluPerspective(GLdouble fovy, GLdouble aspect,
|
R_SetPerspective(GLdouble fovy)
|
||||||
GLdouble zNear, GLdouble zFar)
|
|
||||||
{
|
{
|
||||||
|
// 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;
|
GLdouble xmin, xmax, ymin, ymax;
|
||||||
|
|
||||||
|
// traditional gluPerspective calculations - https://youtu.be/YqSNGcF5nvM?t=644
|
||||||
ymax = zNear * tan(fovy * M_PI / 360.0);
|
ymax = zNear * tan(fovy * M_PI / 360.0);
|
||||||
|
xmax = ymax * aspectratio;
|
||||||
|
|
||||||
ymin = -ymax;
|
ymin = -ymax;
|
||||||
|
xmin = -xmax;
|
||||||
|
|
||||||
xmin = ymin * aspect;
|
if (gl_state.camera_separation)
|
||||||
xmax = ymax * aspect;
|
{
|
||||||
|
const GLdouble separation = - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
||||||
xmin += - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
xmin += separation;
|
||||||
xmax += - gl1_stereo_convergence->value * (2 * gl_state.camera_separation) / zNear;
|
xmax += separation;
|
||||||
|
}
|
||||||
|
|
||||||
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
||||||
}
|
}
|
||||||
|
@ -747,7 +756,6 @@ R_MYgluPerspective(GLdouble fovy, GLdouble aspect,
|
||||||
void
|
void
|
||||||
R_SetupGL(void)
|
R_SetupGL(void)
|
||||||
{
|
{
|
||||||
float screenaspect;
|
|
||||||
int x, x2, y2, y, w, h;
|
int x, x2, y2, y, w, h;
|
||||||
|
|
||||||
/* set up viewport */
|
/* set up viewport */
|
||||||
|
@ -777,18 +785,10 @@ R_SetupGL(void)
|
||||||
glViewport(x, y2, w, h);
|
glViewport(x, y2, w, h);
|
||||||
|
|
||||||
/* set up projection matrix */
|
/* set up projection matrix */
|
||||||
screenaspect = (float)r_newrefdef.width / r_newrefdef.height;
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
if (r_farsee->value == 0)
|
R_SetPerspective(r_newrefdef.fov_y);
|
||||||
{
|
|
||||||
R_MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 4096);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
R_MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 8192);
|
|
||||||
}
|
|
||||||
|
|
||||||
glCullFace(GL_FRONT);
|
glCullFace(GL_FRONT);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue