From 5cc57bf8797906d5cd7782347061399c66bb5ea6 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 3 Apr 2008 22:00:13 +0000 Subject: [PATCH] eliminate two calls to qglGetDoublev that possibly slow down rendering by doing a round trip to the GPU to request the matrices. However, on the tested system, this change does absolutely nothing (233fps vs 233fps), and Xnest, forcing indirect rendering and a ssh -Y localhost did not change that. On an actual network connection however, this new way is SURE faster, as it avoids a round trip over the network. Infinite far clip already used this method, as there is no GL helper for using the infinite far clip matrix. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8242 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_backend.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/gl_backend.c b/gl_backend.c index 6b7f9998..b6425f70 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -303,6 +303,29 @@ void GL_SetupView_Orientation_FromEntity(const matrix4x4_t *matrix) R_Mesh_Matrix(&tempmatrix); } +static void GL_BuildFrustum(double m[16], double left, double right, double bottom, double top, double nearVal, double farVal) +{ + m[0] = 2 * nearVal / (right - left); + m[1] = 0; + m[2] = 0; + m[3] = 0; + + m[4] = 0; + m[5] = 2 * nearVal / (top - bottom); + m[6] = 0; + m[7] = 0; + + m[8] = (right + left) / (right - left); + m[9] = (top + bottom) / (top - bottom); + m[10] = - (farVal + nearVal) / (farVal - nearVal); + m[11] = -1; + + m[12] = 0; + m[13] = 0; + m[14] = - 2 * farVal * nearVal / (farVal - nearVal); + m[15] = 0; +} + void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar) { double m[16]; @@ -310,10 +333,18 @@ void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNe // set up viewpoint CHECKGLERROR qglMatrixMode(GL_PROJECTION);CHECKGLERROR - qglLoadIdentity();CHECKGLERROR // set view pyramid +#if 1 + // avoid glGetDoublev whenever possible, it may stall the render pipeline + // in the tested cases (nvidia) no measurable fps difference, but it sure + // makes a difference over a network line with GLX + GL_BuildFrustum(m, -frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar); + qglLoadMatrixd(m);CHECKGLERROR +#else + qglLoadIdentity();CHECKGLERROR qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR +#endif Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m); qglMatrixMode(GL_MODELVIEW);CHECKGLERROR GL_SetupView_Orientation_Identity(); @@ -353,6 +384,29 @@ void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double frustumx, double frust Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m); } +static void GL_BuildOrtho(double m[16], double left, double right, double bottom, double top, double near, double far) +{ + m[0] = 2/(right - left); + m[1] = 0; + m[2] = 0; + m[3] = 0; + + m[4] = 0; + m[5] = 2/(top - bottom); + m[6] = 0; + m[7] = 0; + + m[8] = 0; + m[9] = 0; + m[10] = -2/(far - near); + m[11] = 0; + + m[12] = - (right + left)/(right - left); + m[13] = - (top + bottom)/(top - bottom); + m[14] = - (far + near)/(far - near); + m[15] = 1; +} + void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar) { double m[16]; @@ -360,9 +414,17 @@ void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double // set up viewpoint CHECKGLERROR qglMatrixMode(GL_PROJECTION);CHECKGLERROR +#if 1 + // avoid glGetDoublev whenever possible, it may stall the render pipeline + // in the tested cases (nvidia) no measurable fps difference, but it sure + // makes a difference over a network line with GLX + GL_BuildOrtho(m, x1, x2, y2, y1, zNear, zFar); + qglLoadMatrixd(m);CHECKGLERROR +#else qglLoadIdentity();CHECKGLERROR qglOrtho(x1, x2, y2, y1, zNear, zFar);CHECKGLERROR qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR +#endif Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m); qglMatrixMode(GL_MODELVIEW);CHECKGLERROR GL_SetupView_Orientation_Identity(); -- 2.39.2