/** * Apply a perspective projection matrix. * * \param left left clipping plane coordinate. * \param right right clipping plane coordinate. * \param bottom bottom clipping plane coordinate. * \param top top clipping plane coordinate. * \param nearval distance to the near clipping plane. * \param farval distance to the far clipping plane. * * \sa glFrustum(). * * Flushes vertices and validates parameters. Calls _math_matrix_frustum() with * the top matrix of the current matrix stack and sets * __struct gl_contextRec::NewState. */ void GLAPIENTRY _mesa_Frustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval ) { GET_CURRENT_CONTEXT(ctx); FLUSH_VERTICES(ctx, 0); if (nearval <= 0.0 || farval <= 0.0 || nearval == farval || left == right || top == bottom) { _mesa_error( ctx, GL_INVALID_VALUE, "glFrustum" ); return; } _math_matrix_frustum( ctx->CurrentStack->Top, (GLfloat) left, (GLfloat) right, (GLfloat) bottom, (GLfloat) top, (GLfloat) nearval, (GLfloat) farval ); ctx->NewState |= ctx->CurrentStack->DirtyFlag; }
void cogl_matrix_frustum (CoglMatrix *matrix, float left, float right, float bottom, float top, float z_near, float z_far) { #ifndef USE_MESA_MATRIX_API float x, y, a, b, c, d; CoglMatrix frustum; x = (2.0f * z_near) / (right - left); y = (2.0f * z_near) / (top - bottom); a = (right + left) / (right - left); b = (top + bottom) / (top - bottom); c = -(z_far + z_near) / ( z_far - z_near); d = -(2.0f * z_far* z_near) / (z_far - z_near); frustum.xx = x; frustum.yx = 0.0f; frustum.zx = 0.0f; frustum.wx = 0.0f; frustum.xy = 0.0f; frustum.yy = y; frustum.zy = 0.0f; frustum.wy = 0.0f; frustum.xz = a; frustum.yz = b; frustum.zz = c; frustum.wz = -1.0f; frustum.xw = 0.0f; frustum.yw = 0.0f; frustum.zw = d; frustum.ww = 0.0f; cogl_matrix_multiply (matrix, matrix, &frustum); #else _math_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); }