+/**
+ * Computes the scaling and the translation part of the
+ * viewport transform matrix of the \param i-th viewport
+ * and writes that into \param scale and \param translate.
+ */
+void
+_mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
+ float scale[3], float translate[3])
+{
+ float x = ctx->ViewportArray[i].X;
+ float y = ctx->ViewportArray[i].Y;
+ float half_width = 0.5f * ctx->ViewportArray[i].Width;
+ float half_height = 0.5f * ctx->ViewportArray[i].Height;
+ double n = ctx->ViewportArray[i].Near;
+ double f = ctx->ViewportArray[i].Far;
+
+ scale[0] = half_width;
+ translate[0] = half_width + x;
+ if (ctx->Transform.ClipOrigin == GL_UPPER_LEFT) {
+ scale[1] = -half_height;
+ } else {
+ scale[1] = half_height;
+ }
+ translate[1] = half_height + y;
+
+ if (ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE) {
+ scale[2] = 0.5 * (f - n);
+ translate[2] = 0.5 * (n + f);
+ } else {
+ scale[2] = f - n;
+ translate[2] = n;
+ }
+}